@octane-xplat/calendar 0.18.0 → 0.19.0

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/README.md CHANGED
@@ -1,25 +1,40 @@
1
- # `@octane-xplat/calendar`
1
+ # @octane-xplat/calendar
2
+
3
+ Read and edit the device calendar on iOS and Android. Web and desktop report
4
+ `supported: false`; this package does not generate calendar invitation files.
5
+
6
+ ## Read upcoming events
7
+
8
+ Install in an existing Xplat app:
2
9
 
3
10
  ```sh
4
- pnpm add @octane-xplat/calendar
11
+ bun add @octane-xplat/calendar
5
12
  ```
6
13
 
7
- Device calendar — list calendars, query events by range, create/update/
8
- delete. Custom bridge: EventKit `EKEventStore` on iOS, CalendarContract on
9
- Android (the `nativescript-calendar` plugin is stale). Web and desktop
10
- report `supported: false` — `.ics` file generation is userland.
14
+ Configure the app's calendar privacy declarations before requesting access.
15
+ Call the following from an action such as **Show my upcoming events**. The
16
+ example uses actual dates and performs no writes:
11
17
 
12
18
  ```ts
13
19
  import { calendar } from '@octane-xplat/calendar'
14
20
 
15
- if ((await calendar.ensure()) === 'granted') {
16
- const cals = await calendar.getCalendars()
17
- const thisWeek = await calendar.getEvents(start, end)
18
- const id = await calendar.createEvent(undefined, {
19
- title: 'Flight', startDate, endDate, location: 'SFO',
20
- })
21
+ export async function upcomingEvents() {
22
+ if (!calendar.supported || (await calendar.ensure()) !== 'granted') return []
23
+ const start = new Date()
24
+ const end = new Date(start.getTime() + 7 * 24 * 60 * 60 * 1000)
25
+ return calendar.getEvents(start, end)
21
26
  }
22
27
  ```
23
28
 
24
- Reminders, attendees, and recurring-edit modes are out of scope (Expo models
25
- reminders as a separate entity).
29
+ With access granted, the result contains events in the requested range.
30
+ An empty result may mean no events or, in this example, no access; use a
31
+ separate permission message in your screen when that distinction matters.
32
+ Event dates are JavaScript `Date` values. Catch and display operation failures
33
+ at the action boundary.
34
+
35
+ The package uses EventKit on iOS and CalendarContract on Android. Reminders,
36
+ attendees, and recurring-event edit modes are outside this API. Review the
37
+ [public calendar contract](https://github.com/octane-xplat/octane-xplat/blob/main/packages/calendar/src/types.ts)
38
+ before adding writes, and [permission handling](https://octane-xplat.goddardai.org/platform-services#the-shared-service-shape)
39
+ for the app's unavailable and denied states. Calendar privacy configuration
40
+ and device behavior still need verification in the app you ship.
package/package.json CHANGED
@@ -1,94 +1,87 @@
1
1
  {
2
- "name": "@octane-xplat/calendar",
3
- "version": "0.18.0",
4
- "description": "Device calendar for Octane xplat — event store reads and writes via EventKit/CalendarContract",
5
- "keywords": [
6
- "android",
7
- "cross-platform",
8
- "nativescript",
9
- "octane",
10
- "xplat",
11
- "calendar",
12
- "events"
13
- ],
14
- "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/calendar",
15
- "license": "MIT",
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/octane-xplat/octane-xplat",
19
- "directory": "packages/calendar"
20
- },
21
- "files": [
22
- "src",
23
- "platforms",
24
- "types",
25
- "!src/**/*.test.*",
26
- "!src/**/*.spec.*"
27
- ],
28
- "type": "module",
29
- "exports": {
30
- ".": {
31
- "macos": {
32
- "types": "./types/generated/index.macos.d.ts",
33
- "default": "./src/index.macos.ts"
34
- },
35
- "web": {
36
- "types": "./types/generated/index.web.d.ts",
37
- "default": "./src/index.web.ts"
38
- },
39
- "native": {
40
- "types": "./types/generated/index.d.ts",
41
- "default": "./src/index.ts"
42
- },
43
- "types": "./types/generated/index.d.ts",
44
- "default": "./src/index.ts"
45
- },
46
- "./*": {
47
- "types": "./types/generated/*.d.ts",
48
- "default": "./src/*"
49
- },
50
- "./*.ts": {
51
- "types": "./types/generated/*.d.ts",
52
- "default": "./src/*.ts"
53
- }
54
- },
55
- "publishConfig": {
56
- "access": "public"
57
- },
58
- "devDependencies": {
59
- "@nativescript-community/octane": "0.2.5",
60
- "@nativescript/core": "9.1.3",
61
- "@nativescript/types": "9.1.4",
62
- "@tsrx/typescript-plugin": "0.4.11",
63
- "octane": "0.14.0",
64
- "tsrx-typegen": "0.4.0",
65
- "typescript": "5.9.3"
66
- },
67
- "peerDependencies": {
68
- "@nativescript-community/octane": ">=0.2.1 <1",
69
- "@nativescript/core": ">=9.1.0 <10",
70
- "octane": ">=0.6.3 <1"
71
- },
72
- "peerDependenciesMeta": {
73
- "@nativescript-community/octane": {
74
- "optional": true
75
- },
76
- "@nativescript/core": {
77
- "optional": true
78
- }
79
- },
80
- "nativescript": {
81
- "platforms": {
82
- "android": "9.1.0",
83
- "ios": "9.1.0"
84
- }
85
- },
86
- "dependencies": {
87
- "@octane-xplat/platform": "0.18.0"
88
- },
89
- "scripts": {
90
- "typegen": "tsrx-typegen --target octane",
91
- "pack:check": "tsrx-typegen --pack-check",
92
- "typecheck": "node ../../scripts/typecheck.ts"
93
- }
94
- }
2
+ "name": "@octane-xplat/calendar",
3
+ "version": "0.19.0",
4
+ "description": "Device calendar for Octane xplat — event store reads and writes via EventKit/CalendarContract",
5
+ "keywords": [
6
+ "android",
7
+ "cross-platform",
8
+ "nativescript",
9
+ "octane",
10
+ "xplat",
11
+ "calendar",
12
+ "events"
13
+ ],
14
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/calendar",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/octane-xplat/octane-xplat",
19
+ "directory": "packages/calendar"
20
+ },
21
+ "files": [
22
+ "src",
23
+ "platforms",
24
+ "types",
25
+ "!src/**/*.test.*",
26
+ "!src/**/*.spec.*"
27
+ ],
28
+ "type": "module",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./types/generated/index.d.ts",
32
+ "macos": "./src/index.macos.ts",
33
+ "web": "./src/index.web.ts",
34
+ "native": "./src/index.ts",
35
+ "default": "./src/index.ts"
36
+ },
37
+ "./*": {
38
+ "types": "./types/generated/*.d.ts",
39
+ "default": "./src/*"
40
+ },
41
+ "./*.ts": {
42
+ "types": "./types/generated/*.d.ts",
43
+ "default": "./src/*.ts"
44
+ }
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "typegen": "tsrx-typegen --target octane",
51
+ "prepack": "bun run typegen && tsrx-typegen --pack-check",
52
+ "pack:check": "tsrx-typegen --pack-check",
53
+ "typecheck": "node ../../scripts/typecheck.ts",
54
+ "test": "node --test tests/*.test.ts"
55
+ },
56
+ "devDependencies": {
57
+ "@nativescript-community/octane": "0.2.5",
58
+ "@nativescript/core": "9.1.3",
59
+ "@nativescript/types": "9.1.4",
60
+ "@tsrx/typescript-plugin": "0.4.11",
61
+ "octane": "0.16.3",
62
+ "tsrx-typegen": "0.5.0",
63
+ "typescript": "5.9.3"
64
+ },
65
+ "peerDependencies": {
66
+ "@nativescript-community/octane": ">=0.2.1 <1",
67
+ "@nativescript/core": ">=9.1.0 <10",
68
+ "octane": ">=0.6.3 <1"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "@nativescript-community/octane": {
72
+ "optional": true
73
+ },
74
+ "@nativescript/core": {
75
+ "optional": true
76
+ }
77
+ },
78
+ "nativescript": {
79
+ "platforms": {
80
+ "android": "9.1.0",
81
+ "ios": "9.1.0"
82
+ }
83
+ },
84
+ "dependencies": {
85
+ "@octane-xplat/platform": "0.19.0"
86
+ }
87
+ }
@@ -1,15 +1,244 @@
1
- import type { Calendar, PermissionResult } from './types'
1
+ // Calendar — AppKit leaf over EventKit. EKEventStore is bridgeable through
2
+ // the JSC host; the API mirrors the iOS leaf's surface (same store class,
3
+ // same entity type). Metadata targets macOS 11, so the deprecated
4
+ // requestAccessToEntityTypeCompletion is the bound request entry point —
5
+ // on macOS 14+ it still performs the full-access events prompt.
6
+ import {
7
+ EKEntityType,
8
+ EKEvent,
9
+ EKEventStore,
10
+ EKSpan,
11
+ NSDate,
12
+ } from '@octane-xplat/platform/macos'
13
+ import type { Calendar, CalendarEvent, CalendarInfo, NewEvent, PermissionResult } from './types'
2
14
 
3
- const unsupported = () => Promise.reject(new Error('unsupported: calendar is not wired on this platform'))
15
+ let store: any = null
16
+ const eventStore = () => {
17
+ if (store) {
18
+ return store
19
+ }
4
20
 
21
+ try {
22
+ if (typeof EKEventStore?.authorizationStatusForEntityType !== 'function') {
23
+ return null
24
+ }
25
+ return (store = EKEventStore.new())
26
+ } catch {
27
+ return null
28
+ }
29
+ }
30
+
31
+ // EKAuthorizationStatus: 0 notDetermined 1 restricted 2 denied
32
+ // 3 fullAccess/authorized 4 writeOnly
33
+ const rawStatus = () =>
34
+ Number(EKEventStore.authorizationStatusForEntityType(EKEntityType.Event ?? 0))
35
+
36
+ function ensureAccess(): Promise<PermissionResult> {
37
+ const s = eventStore()
38
+ if (!s) {
39
+ return Promise.resolve('unsupported')
40
+ }
41
+
42
+ const status = rawStatus()
43
+ if (status === 3 || status === 4) {
44
+ return Promise.resolve('granted')
45
+ }
46
+
47
+ if (status === 1 || status === 2) {
48
+ return Promise.resolve('denied')
49
+ }
50
+
51
+ return new Promise((resolve) => {
52
+ s.requestAccessToEntityTypeCompletion(EKEntityType.Event ?? 0, (granted: boolean) =>
53
+ resolve(granted ? 'granted' : 'denied'),
54
+ )
55
+ })
56
+ }
57
+
58
+ const permissionResponse = () => {
59
+ const s = eventStore()
60
+ if (!s) {
61
+ return { status: 'unsupported' as const, granted: false, canAskAgain: false }
62
+ }
63
+
64
+ const status = rawStatus()
65
+ return {
66
+ status: status === 3 || status === 4 ? ('granted' as const) : status === 0 ? ('undetermined' as const) : ('denied' as const),
67
+ granted: status === 3 || status === 4,
68
+ canAskAgain: status === 0 || status === 3 || status === 4,
69
+ }
70
+ }
71
+
72
+ function calendars(): CalendarInfo[] {
73
+ const s = eventStore()
74
+ const out: CalendarInfo[] = []
75
+ const list = s?.calendarsForEntityType?.(EKEntityType.Event ?? 0)
76
+ for (let i = 0; i < (list?.count ?? 0); i++) {
77
+ const c = list.objectAtIndex(i)
78
+ out.push({
79
+ id: String(c.calendarIdentifier ?? ''),
80
+ title: String(c.title ?? ''),
81
+ color: c.CGColor ? String(c.CGColor) : undefined,
82
+ source: c.source?.title ? String(c.source.title) : undefined,
83
+ allowsModifications: !!c.allowsContentModifications,
84
+ isPrimary: false,
85
+ })
86
+ }
87
+
88
+ return out
89
+ }
90
+
91
+ function asEvent(e: any): CalendarEvent {
92
+ return {
93
+ id: String(e.eventIdentifier ?? ''),
94
+ calendarId: e.calendar?.calendarIdentifier ? String(e.calendar.calendarIdentifier) : undefined,
95
+ title: String(e.title ?? ''),
96
+ startDate: new Date((e.startDate?.timeIntervalSince1970 ?? 0) * 1000),
97
+ endDate: new Date((e.endDate?.timeIntervalSince1970 ?? 0) * 1000),
98
+ allDay: !!e.allDay,
99
+ location: e.location ? String(e.location) : undefined,
100
+ notes: e.notes ? String(e.notes) : undefined,
101
+ timeZone: e.timeZone?.name ? String(e.timeZone.name) : undefined,
102
+ }
103
+ }
104
+
105
+ const toNSDate = (date: Date) => NSDate.dateWithTimeIntervalSince1970(date.getTime() / 1000)
106
+
107
+ /** Calendar service — EventKit/CalendarContract. */
5
108
  export const calendar: Calendar = {
6
- supported: false,
7
- ensure: async (): Promise<PermissionResult> => 'unsupported',
8
- getCalendars: unsupported,
9
- getDefaultCalendar: unsupported,
10
- getEvents: unsupported,
11
- getEvent: unsupported,
12
- createEvent: unsupported,
13
- updateEvent: unsupported,
14
- deleteEvent: unsupported,
109
+ get supported() {
110
+ return eventStore() !== null
111
+ },
112
+
113
+ ensure(): Promise<PermissionResult> {
114
+ return ensureAccess()
115
+ },
116
+
117
+ async getCalendars(): Promise<CalendarInfo[]> {
118
+ return calendars()
119
+ },
120
+
121
+ async getDefaultCalendar(): Promise<CalendarInfo | null> {
122
+ const def = eventStore()?.defaultCalendarForNewEvents
123
+ return def
124
+ ? {
125
+ id: String(def.calendarIdentifier),
126
+ title: String(def.title ?? ''),
127
+ allowsModifications: !!def.allowsContentModifications,
128
+ }
129
+ : null
130
+ },
131
+
132
+ async getEvents(
133
+ startDate: Date,
134
+ endDate: Date,
135
+ calendarIds?: string[],
136
+ ): Promise<CalendarEvent[]> {
137
+ const s = eventStore()
138
+ const wanted =
139
+ calendarIds?.length
140
+ ? calendarIds
141
+ .map((id) => s?.calendarWithIdentifier?.(id))
142
+ .filter((c: any) => c != null)
143
+ : null
144
+ const predicate = s?.predicateForEventsWithStartDateEndDateCalendars(
145
+ toNSDate(startDate),
146
+ toNSDate(endDate),
147
+ wanted?.length ? wanted : null,
148
+ )
149
+ const list = s?.eventsMatchingPredicate?.(predicate)
150
+ const out: CalendarEvent[] = []
151
+ for (let i = 0; i < (list?.count ?? 0); i++) {
152
+ const e = asEvent(list.objectAtIndex(i))
153
+ if (!calendarIds?.length || calendarIds.includes(e.calendarId ?? '')) {
154
+ out.push(e)
155
+ }
156
+ }
157
+
158
+ return out
159
+ },
160
+
161
+ async getEvent(id: string): Promise<CalendarEvent | null> {
162
+ const e = eventStore()?.eventWithIdentifier?.(id)
163
+ return e ? asEvent(e) : null
164
+ },
165
+
166
+ async createEvent(calendarId: string | undefined, event: NewEvent): Promise<string> {
167
+ const s = eventStore()
168
+ if (!s) {
169
+ throw new Error('calendar.createEvent: EventKit is unavailable on this host')
170
+ }
171
+
172
+ const e = EKEvent.eventWithEventStore(s)
173
+ e.title = event.title
174
+ e.startDate = toNSDate(event.startDate)
175
+ e.endDate = toNSDate(event.endDate)
176
+ e.allDay = !!event.allDay
177
+ e.location = (event.location ?? null) as string
178
+ e.notes = (event.notes ?? null) as string
179
+ e.calendar = calendarId
180
+ ? (s.calendarWithIdentifier?.(calendarId) ?? s.defaultCalendarForNewEvents)
181
+ : s.defaultCalendarForNewEvents
182
+
183
+ if (!s.saveEventSpanError(e, EKSpan.ThisEvent ?? 0, null)) {
184
+ throw new Error('calendar.createEvent: EKEventStore.saveEvent failed')
185
+ }
186
+
187
+ return String(e.eventIdentifier ?? '')
188
+ },
189
+
190
+ async updateEvent(id: string, patch: Partial<NewEvent>): Promise<string> {
191
+ const s = eventStore()
192
+ const e = s?.eventWithIdentifier?.(id)
193
+ if (!e) {
194
+ throw new Error(`calendar.updateEvent: no event ${id}`)
195
+ }
196
+
197
+ if (patch.title !== undefined) {
198
+ e.title = patch.title
199
+ }
200
+
201
+ if (patch.startDate) {
202
+ e.startDate = toNSDate(patch.startDate)
203
+ }
204
+
205
+ if (patch.endDate) {
206
+ e.endDate = toNSDate(patch.endDate)
207
+ }
208
+
209
+ if (patch.allDay !== undefined) {
210
+ e.allDay = patch.allDay
211
+ }
212
+
213
+ if (patch.location !== undefined) {
214
+ e.location = patch.location
215
+ }
216
+
217
+ if (patch.notes !== undefined) {
218
+ e.notes = patch.notes
219
+ }
220
+
221
+ if (!s.saveEventSpanError(e, EKSpan.ThisEvent ?? 0, null)) {
222
+ throw new Error('calendar.updateEvent: EKEventStore.saveEvent failed')
223
+ }
224
+
225
+ return id
226
+ },
227
+
228
+ async deleteEvent(id: string): Promise<void> {
229
+ const s = eventStore()
230
+ const e = s?.eventWithIdentifier?.(id)
231
+ if (e && !s.removeEventSpanError(e, EKSpan.ThisEvent ?? 0, null)) {
232
+ throw new Error('calendar.deleteEvent: EKEventStore.removeEvent failed')
233
+ }
234
+ },
235
+ }
236
+
237
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
238
+ permissionOwners.calendar = {
239
+ getPermissions: async () => permissionResponse(),
240
+ requestPermissions: async () => {
241
+ const result = await calendar.ensure()
242
+ return { status: result, granted: result === 'granted', canAskAgain: result === 'granted' }
243
+ },
15
244
  }
package/src/calendar.ts CHANGED
@@ -57,9 +57,11 @@ function androidEnsure(): Promise<PermissionResult> {
57
57
  ) {
58
58
  return Promise.resolve('granted')
59
59
  }
60
+
60
61
  if (!activity) {
61
62
  return Promise.resolve('denied')
62
63
  }
64
+
63
65
  return new Promise<PermissionResult>((resolve) => {
64
66
  const requestCode = calRequestCode++
65
67
  const event = Application.android.activityRequestPermissionsEvent
@@ -122,7 +124,13 @@ function iosEvent(e: any): CalendarEvent {
122
124
  const androidUtils = Utils.android as any
123
125
  const resolver = () => androidUtils?.getApplicationContext?.()?.getContentResolver()
124
126
 
125
- function androidQuery(uri: any, projection: string[], selection: string, args: string[], sort: string): any[] {
127
+ function androidQuery(
128
+ uri: any,
129
+ projection: string[],
130
+ selection: string,
131
+ args: string[],
132
+ sort: string,
133
+ ): any[] {
126
134
  const cursor = resolver()?.query(uri, projection, selection, args, sort)
127
135
  const out: any[] = []
128
136
  if (!cursor) {
@@ -133,6 +141,7 @@ function androidQuery(uri: any, projection: string[], selection: string, args: s
133
141
  for (let i = 0; i < cursor.getColumnCount(); i++) {
134
142
  row[cursor.getColumnName(i)] = cursor.getString(i)
135
143
  }
144
+
136
145
  out.push(row)
137
146
  }
138
147
  cursor.close()
@@ -144,7 +153,20 @@ const EVENTS_URI = () => android.provider.CalendarContract.Events.CONTENT_URI
144
153
  const INSTANCES_URI = () => android.provider.CalendarContract.Instances.CONTENT_URI
145
154
 
146
155
  function androidCalendars(): CalendarInfo[] {
147
- return androidQuery(CAL_URI(), ['_id', 'calendar_displayName', 'calendar_color', 'account_name', 'calendar_access_level', 'isPrimary'], '', [], 'calendar_displayName ASC').map((row) => ({
156
+ return androidQuery(
157
+ CAL_URI(),
158
+ [
159
+ '_id',
160
+ 'calendar_displayName',
161
+ 'calendar_color',
162
+ 'account_name',
163
+ 'calendar_access_level',
164
+ 'isPrimary',
165
+ ],
166
+ '',
167
+ [],
168
+ 'calendar_displayName ASC',
169
+ ).map((row) => ({
148
170
  id: String(row._id),
149
171
  title: String(row.calendar_displayName ?? ''),
150
172
  color: row.calendar_color,
@@ -167,6 +189,7 @@ function androidEvent(row: any): CalendarEvent {
167
189
  }
168
190
  }
169
191
 
192
+ /** Calendar service — EventKit/CalendarContract. */
170
193
  export const calendar: Calendar = {
171
194
  supported: isIOS ? typeof EKEventStore !== 'undefined' : true,
172
195
 
@@ -182,12 +205,22 @@ export const calendar: Calendar = {
182
205
  if (isIOS) {
183
206
  const s = eventStore()
184
207
  const def = s?.defaultCalendarForNewEvents
185
- return def ? { id: String(def.calendarIdentifier), title: String(def.title ?? ''), allowsModifications: !!def.allowsContentModifications } : null
208
+ return def
209
+ ? {
210
+ id: String(def.calendarIdentifier),
211
+ title: String(def.title ?? ''),
212
+ allowsModifications: !!def.allowsContentModifications,
213
+ }
214
+ : null
186
215
  }
187
216
  return androidCalendars().find((c) => c.isPrimary) ?? androidCalendars()[0] ?? null
188
217
  },
189
218
 
190
- async getEvents(startDate: Date, endDate: Date, calendarIds?: string[]): Promise<CalendarEvent[]> {
219
+ async getEvents(
220
+ startDate: Date,
221
+ endDate: Date,
222
+ calendarIds?: string[],
223
+ ): Promise<CalendarEvent[]> {
191
224
  if (isIOS) {
192
225
  const s = eventStore()
193
226
  const begin = NSDate.dateWithTimeIntervalSince1970(startDate.getTime() / 1000)
@@ -201,6 +234,7 @@ export const calendar: Calendar = {
201
234
  out.push(e)
202
235
  }
203
236
  }
237
+
204
238
  return out
205
239
  }
206
240
  const selection = calendarIds?.length
@@ -209,7 +243,16 @@ export const calendar: Calendar = {
209
243
  const args = calendarIds ?? []
210
244
  return androidQuery(
211
245
  INSTANCES_URI(),
212
- ['event_id', 'calendar_id', 'title', 'begin', 'end', 'allDay', 'eventLocation', 'description'],
246
+ [
247
+ 'event_id',
248
+ 'calendar_id',
249
+ 'title',
250
+ 'begin',
251
+ 'end',
252
+ 'allDay',
253
+ 'eventLocation',
254
+ 'description',
255
+ ],
213
256
  selection,
214
257
  args,
215
258
  'begin ASC',
@@ -226,7 +269,9 @@ export const calendar: Calendar = {
226
269
  const rows = androidQuery(
227
270
  (android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)),
228
271
  ['_id', 'calendar_id', 'title', 'dtstart', 'dtend', 'allDay', 'eventLocation', 'description'],
229
- '', [], '',
272
+ '',
273
+ [],
274
+ '',
230
275
  )
231
276
  return rows.length ? androidEvent(rows[0]) : null
232
277
  },
@@ -242,11 +287,13 @@ export const calendar: Calendar = {
242
287
  e.location = event.location
243
288
  e.notes = event.notes
244
289
  e.calendar = calendarId
245
- ? s.calendarWithIdentifier?.(calendarId) ?? s.defaultCalendarForNewEvents
290
+ ? (s.calendarWithIdentifier?.(calendarId) ?? s.defaultCalendarForNewEvents)
246
291
  : s.defaultCalendarForNewEvents
292
+
247
293
  if (!s.saveEventSpanError(e, 0, null)) {
248
294
  throw new Error('calendar.createEvent: EKEventStore.saveEvent failed')
249
295
  }
296
+
250
297
  return String(e.eventIdentifier ?? '')
251
298
  }
252
299
  const values = new android.content.ContentValues()
@@ -274,22 +321,56 @@ export const calendar: Calendar = {
274
321
  if (!e) {
275
322
  throw new Error(`calendar.updateEvent: no event ${id}`)
276
323
  }
277
- if (patch.title !== undefined) {e.title = patch.title}
278
- if (patch.startDate) {e.startDate = NSDate.dateWithTimeIntervalSince1970(patch.startDate.getTime() / 1000)}
279
- if (patch.endDate) {e.endDate = NSDate.dateWithTimeIntervalSince1970(patch.endDate.getTime() / 1000)}
280
- if (patch.allDay !== undefined) {e.allDay = patch.allDay}
281
- if (patch.location !== undefined) {e.location = patch.location}
282
- if (patch.notes !== undefined) {e.notes = patch.notes}
324
+
325
+ if (patch.title !== undefined) {
326
+ e.title = patch.title
327
+ }
328
+
329
+ if (patch.startDate) {
330
+ e.startDate = NSDate.dateWithTimeIntervalSince1970(patch.startDate.getTime() / 1000)
331
+ }
332
+
333
+ if (patch.endDate) {
334
+ e.endDate = NSDate.dateWithTimeIntervalSince1970(patch.endDate.getTime() / 1000)
335
+ }
336
+
337
+ if (patch.allDay !== undefined) {
338
+ e.allDay = patch.allDay
339
+ }
340
+
341
+ if (patch.location !== undefined) {
342
+ e.location = patch.location
343
+ }
344
+
345
+ if (patch.notes !== undefined) {
346
+ e.notes = patch.notes
347
+ }
348
+
283
349
  s.saveEventSpanError(e, 0, null)
284
350
  return id
285
351
  }
286
352
  const values = new android.content.ContentValues()
287
- if (patch.title !== undefined) {values.put('title', patch.title)}
288
- if (patch.startDate) {values.put('dtstart', java.lang.Long.valueOf(patch.startDate.getTime()))}
289
- if (patch.endDate) {values.put('dtend', java.lang.Long.valueOf(patch.endDate.getTime()))}
290
- if (patch.location !== undefined) {values.put('eventLocation', patch.location)}
291
- if (patch.notes !== undefined) {values.put('description', patch.notes)}
292
- resolver()?.update((android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)), values, null, null)
353
+ if (patch.title !== undefined) {
354
+ values.put('title', patch.title)
355
+ }
356
+ if (patch.startDate) {
357
+ values.put('dtstart', java.lang.Long.valueOf(patch.startDate.getTime()))
358
+ }
359
+ if (patch.endDate) {
360
+ values.put('dtend', java.lang.Long.valueOf(patch.endDate.getTime()))
361
+ }
362
+ if (patch.location !== undefined) {
363
+ values.put('eventLocation', patch.location)
364
+ }
365
+ if (patch.notes !== undefined) {
366
+ values.put('description', patch.notes)
367
+ }
368
+ resolver()?.update(
369
+ (android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)),
370
+ values,
371
+ null,
372
+ null,
373
+ )
293
374
  return id
294
375
  },
295
376
 
@@ -300,9 +381,14 @@ export const calendar: Calendar = {
300
381
  if (e) {
301
382
  s.removeEventSpanError(e, 0, null)
302
383
  }
384
+
303
385
  return
304
386
  }
305
- resolver()?.delete((android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)), null, null)
387
+ resolver()?.delete(
388
+ (android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)),
389
+ null,
390
+ null,
391
+ )
306
392
  },
307
393
  }
308
394
 
@@ -4,6 +4,7 @@ import type { Calendar, PermissionResult } from './types'
4
4
 
5
5
  const unsupported = () => Promise.reject(new Error('unsupported: no calendar API on web'))
6
6
 
7
+ /** Calendar service — EventKit/CalendarContract. */
7
8
  export const calendar: Calendar = {
8
9
  supported: false,
9
10
  ensure: async (): Promise<PermissionResult> => 'unsupported',
@@ -1,7 +1,9 @@
1
1
  import type { Calendar, PermissionResult } from './types'
2
2
 
3
- const unsupported = () => Promise.reject(new Error('unsupported: calendar is not wired on this platform'))
3
+ const unsupported = () =>
4
+ Promise.reject(new Error('unsupported: calendar is not wired on this platform'))
4
5
 
6
+ /** Calendar service — EventKit/CalendarContract. */
5
7
  export const calendar: Calendar = {
6
8
  supported: false,
7
9
  ensure: async (): Promise<PermissionResult> => 'unsupported',
package/src/types.ts CHANGED
@@ -1,45 +1,83 @@
1
+ /** Coarse permission answer; 'unsupported' means the platform has no
2
+ * calendar/permission path. */
1
3
  export type PermissionResult = 'granted' | 'denied' | 'unsupported'
2
4
 
5
+ /** One calendar account-local store. */
3
6
  export interface CalendarInfo {
7
+ /** Store-assigned id — pass to getEvents/createEvent. */
4
8
  id: string
9
+ /** Display name. */
5
10
  title: string
11
+ /** Display color (CSS color where the store exposes one). */
6
12
  color?: string
13
+ /** Originating account/source name (iCloud, local, Exchange, …). */
7
14
  source?: string
15
+ /** False for read-only stores (subscribed/Birthdays calendars). */
8
16
  allowsModifications?: boolean
17
+ /** The store's default calendar. */
9
18
  isPrimary?: boolean
10
19
  }
11
20
 
21
+ /** A stored calendar event. */
12
22
  export interface CalendarEvent {
23
+ /** Store-assigned id — pass to getEvent/updateEvent/deleteEvent. */
13
24
  id: string
25
+ /** The owning CalendarInfo.id; absent where the store doesn't report it. */
14
26
  calendarId?: string
27
+ /** Display title. */
15
28
  title: string
29
+ /** Start instant. */
16
30
  startDate: Date
31
+ /** End instant. */
17
32
  endDate: Date
33
+ /** All-day flag; all-day dates are date-only values. */
18
34
  allDay?: boolean
35
+ /** Free-text location. */
19
36
  location?: string
37
+ /** Free-text notes. */
20
38
  notes?: string
39
+ /** IANA time-zone name when the store records one. */
21
40
  timeZone?: string
22
41
  }
23
42
 
43
+ /** Event fields for createEvent/updateEvent — no store ids. */
24
44
  export interface NewEvent {
45
+ /** Display title. */
25
46
  title: string
47
+ /** Start instant. */
26
48
  startDate: Date
49
+ /** End instant. */
27
50
  endDate: Date
51
+ /** All-day flag. */
28
52
  allDay?: boolean
53
+ /** Free-text location. */
29
54
  location?: string
55
+ /** Free-text notes. */
30
56
  notes?: string
57
+ /** IANA time-zone name. */
31
58
  timeZone?: string
32
59
  }
33
60
 
61
+ /** EventCalendar/EventKit calendar façade; false `supported` off mobile. */
34
62
  export interface Calendar {
63
+ /** Synchronous fast check — a calendar backend exists. */
35
64
  readonly supported: boolean
65
+ /** Ensure calendar permission, prompting if needed. */
36
66
  ensure(): Promise<PermissionResult>
67
+ /** Every calendar store visible to the app. */
37
68
  getCalendars(): Promise<CalendarInfo[]>
69
+ /** The store's default calendar, or null when none is writable. */
38
70
  getDefaultCalendar(): Promise<CalendarInfo | null>
71
+ /** Events overlapping the range, optionally limited to calendar ids. */
39
72
  getEvents(startDate: Date, endDate: Date, calendarIds?: string[]): Promise<CalendarEvent[]>
73
+ /** One event by id, or null. */
40
74
  getEvent(id: string): Promise<CalendarEvent | null>
75
+ /** Insert an event; resolves the store-assigned event id. Pass
76
+ * undefined calendarId for the default calendar. */
41
77
  createEvent(calendarId: string | undefined, event: NewEvent): Promise<string>
78
+ /** Patch fields of an existing event; resolves the event id. */
42
79
  updateEvent(id: string, patch: Partial<NewEvent>): Promise<string>
80
+ /** Remove an event by id. */
43
81
  deleteEvent(id: string): Promise<void>
44
82
  }
45
83
 
@@ -1,2 +1,3 @@
1
1
  import type { Calendar } from './types.js';
2
+ /** Calendar service — EventKit/CalendarContract. */
2
3
  export declare const calendar: Calendar;
@@ -1,2 +1,3 @@
1
1
  import type { Calendar } from './types.js';
2
+ /** Calendar service — EventKit/CalendarContract. */
2
3
  export declare const calendar: Calendar;
@@ -1,2 +1,3 @@
1
1
  import type { Calendar } from './types.js';
2
+ /** Calendar service — EventKit/CalendarContract. */
2
3
  export declare const calendar: Calendar;
@@ -1,2 +1,3 @@
1
1
  import type { Calendar } from './types.js';
2
+ /** Calendar service — EventKit/CalendarContract. */
2
3
  export declare const calendar: Calendar;
@@ -1,41 +1,79 @@
1
+ /** Coarse permission answer; 'unsupported' means the platform has no
2
+ * calendar/permission path. */
1
3
  export type PermissionResult = 'granted' | 'denied' | 'unsupported';
4
+ /** One calendar account-local store. */
2
5
  export interface CalendarInfo {
6
+ /** Store-assigned id — pass to getEvents/createEvent. */
3
7
  id: string;
8
+ /** Display name. */
4
9
  title: string;
10
+ /** Display color (CSS color where the store exposes one). */
5
11
  color?: string;
12
+ /** Originating account/source name (iCloud, local, Exchange, …). */
6
13
  source?: string;
14
+ /** False for read-only stores (subscribed/Birthdays calendars). */
7
15
  allowsModifications?: boolean;
16
+ /** The store's default calendar. */
8
17
  isPrimary?: boolean;
9
18
  }
19
+ /** A stored calendar event. */
10
20
  export interface CalendarEvent {
21
+ /** Store-assigned id — pass to getEvent/updateEvent/deleteEvent. */
11
22
  id: string;
23
+ /** The owning CalendarInfo.id; absent where the store doesn't report it. */
12
24
  calendarId?: string;
25
+ /** Display title. */
13
26
  title: string;
27
+ /** Start instant. */
14
28
  startDate: Date;
29
+ /** End instant. */
15
30
  endDate: Date;
31
+ /** All-day flag; all-day dates are date-only values. */
16
32
  allDay?: boolean;
33
+ /** Free-text location. */
17
34
  location?: string;
35
+ /** Free-text notes. */
18
36
  notes?: string;
37
+ /** IANA time-zone name when the store records one. */
19
38
  timeZone?: string;
20
39
  }
40
+ /** Event fields for createEvent/updateEvent — no store ids. */
21
41
  export interface NewEvent {
42
+ /** Display title. */
22
43
  title: string;
44
+ /** Start instant. */
23
45
  startDate: Date;
46
+ /** End instant. */
24
47
  endDate: Date;
48
+ /** All-day flag. */
25
49
  allDay?: boolean;
50
+ /** Free-text location. */
26
51
  location?: string;
52
+ /** Free-text notes. */
27
53
  notes?: string;
54
+ /** IANA time-zone name. */
28
55
  timeZone?: string;
29
56
  }
57
+ /** EventCalendar/EventKit calendar façade; false `supported` off mobile. */
30
58
  export interface Calendar {
59
+ /** Synchronous fast check — a calendar backend exists. */
31
60
  readonly supported: boolean;
61
+ /** Ensure calendar permission, prompting if needed. */
32
62
  ensure(): Promise<PermissionResult>;
63
+ /** Every calendar store visible to the app. */
33
64
  getCalendars(): Promise<CalendarInfo[]>;
65
+ /** The store's default calendar, or null when none is writable. */
34
66
  getDefaultCalendar(): Promise<CalendarInfo | null>;
67
+ /** Events overlapping the range, optionally limited to calendar ids. */
35
68
  getEvents(startDate: Date, endDate: Date, calendarIds?: string[]): Promise<CalendarEvent[]>;
69
+ /** One event by id, or null. */
36
70
  getEvent(id: string): Promise<CalendarEvent | null>;
71
+ /** Insert an event; resolves the store-assigned event id. Pass
72
+ * undefined calendarId for the default calendar. */
37
73
  createEvent(calendarId: string | undefined, event: NewEvent): Promise<string>;
74
+ /** Patch fields of an existing event; resolves the event id. */
38
75
  updateEvent(id: string, patch: Partial<NewEvent>): Promise<string>;
76
+ /** Remove an event by id. */
39
77
  deleteEvent(id: string): Promise<void>;
40
78
  }
41
79
  export declare const calendar: Calendar;
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2026 Alec Larson
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.