@octane-xplat/calendar 0.19.0 → 0.20.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,40 +1,5 @@
1
1
  # @octane-xplat/calendar
2
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.
3
+ [Documentation](https://octane-xplat.goddardai.org/package-calendar).
5
4
 
6
- ## Read upcoming events
7
-
8
- Install in an existing Xplat app:
9
-
10
- ```sh
11
- bun add @octane-xplat/calendar
12
- ```
13
-
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:
17
-
18
- ```ts
19
- import { calendar } from '@octane-xplat/calendar'
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)
26
- }
27
- ```
28
-
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.
5
+ [API reference](https://octane-xplat.goddardai.org/api-calendar).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octane-xplat/calendar",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Device calendar for Octane xplat — event store reads and writes via EventKit/CalendarContract",
5
5
  "keywords": [
6
6
  "android",
@@ -57,10 +57,10 @@
57
57
  "@nativescript-community/octane": "0.2.5",
58
58
  "@nativescript/core": "9.1.3",
59
59
  "@nativescript/types": "9.1.4",
60
- "@tsrx/typescript-plugin": "0.4.11",
61
60
  "octane": "0.16.3",
62
- "tsrx-typegen": "0.5.0",
63
- "typescript": "5.9.3"
61
+ "tsrx-typegen": "0.6.1",
62
+ "typescript": "7.1.0-beta",
63
+ "@tsrx/content-mapper": "0.1.2"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@nativescript-community/octane": ">=0.2.1 <1",
@@ -82,6 +82,6 @@
82
82
  }
83
83
  },
84
84
  "dependencies": {
85
- "@octane-xplat/platform": "0.19.0"
85
+ "@octane-xplat/platform": "0.20.0"
86
86
  }
87
87
  }
@@ -3,242 +3,257 @@
3
3
  // same entity type). Metadata targets macOS 11, so the deprecated
4
4
  // requestAccessToEntityTypeCompletion is the bound request entry point —
5
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'
6
+ import { EKEntityType, EKEvent, EKEventStore, EKSpan, NSDate } from '@octane-xplat/platform/macos'
13
7
  import type { Calendar, CalendarEvent, CalendarInfo, NewEvent, PermissionResult } from './types'
14
8
 
15
9
  let store: any = null
16
10
  const eventStore = () => {
17
- if (store) {
18
- return store
19
- }
20
-
21
- try {
22
- if (typeof EKEventStore?.authorizationStatusForEntityType !== 'function') {
23
- return null
24
- }
25
- return (store = EKEventStore.new())
26
- } catch {
27
- return null
28
- }
11
+ if (store) {
12
+ return store
13
+ }
14
+
15
+ try {
16
+ if (typeof EKEventStore?.authorizationStatusForEntityType !== 'function') {
17
+ return null
18
+ }
19
+
20
+ return (store = EKEventStore.new())
21
+ } catch {
22
+ return null
23
+ }
29
24
  }
30
25
 
31
26
  // EKAuthorizationStatus: 0 notDetermined 1 restricted 2 denied
32
27
  // 3 fullAccess/authorized 4 writeOnly
33
28
  const rawStatus = () =>
34
- Number(EKEventStore.authorizationStatusForEntityType(EKEntityType.Event ?? 0))
29
+ Number(EKEventStore.authorizationStatusForEntityType(EKEntityType.Event ?? 0))
35
30
 
36
31
  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
- })
32
+ const s = eventStore()
33
+
34
+ if (!s) {
35
+ return Promise.resolve('unsupported')
36
+ }
37
+
38
+ const status = rawStatus()
39
+
40
+ if (status === 3 || status === 4) {
41
+ return Promise.resolve('granted')
42
+ }
43
+
44
+ if (status === 1 || status === 2) {
45
+ return Promise.resolve('denied')
46
+ }
47
+
48
+ return new Promise((resolve) => {
49
+ s.requestAccessToEntityTypeCompletion(EKEntityType.Event ?? 0, (granted: boolean) =>
50
+ resolve(granted ? 'granted' : 'denied'),
51
+ )
52
+ })
56
53
  }
57
54
 
58
55
  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
- }
56
+ const s = eventStore()
57
+
58
+ if (!s) {
59
+ return { status: 'unsupported' as const, granted: false, canAskAgain: false }
60
+ }
61
+
62
+ const status = rawStatus()
63
+
64
+ return {
65
+ status:
66
+ status === 3 || status === 4
67
+ ? ('granted' as const)
68
+ : status === 0
69
+ ? ('undetermined' as const)
70
+ : ('denied' as const),
71
+ granted: status === 3 || status === 4,
72
+ canAskAgain: status === 0 || status === 3 || status === 4,
73
+ }
70
74
  }
71
75
 
72
76
  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
77
+ const s = eventStore()
78
+ const out: CalendarInfo[] = []
79
+ const list = s?.calendarsForEntityType?.(EKEntityType.Event ?? 0)
80
+
81
+ for (let i = 0; i < (list?.count ?? 0); i++) {
82
+ const c = list.objectAtIndex(i)
83
+
84
+ out.push({
85
+ id: String(c.calendarIdentifier ?? ''),
86
+ title: String(c.title ?? ''),
87
+ color: c.CGColor ? String(c.CGColor) : undefined,
88
+ source: c.source?.title ? String(c.source.title) : undefined,
89
+ allowsModifications: !!c.allowsContentModifications,
90
+ isPrimary: false,
91
+ })
92
+ }
93
+
94
+ return out
89
95
  }
90
96
 
91
97
  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
- }
98
+ return {
99
+ id: String(e.eventIdentifier ?? ''),
100
+ calendarId: e.calendar?.calendarIdentifier ? String(e.calendar.calendarIdentifier) : undefined,
101
+ title: String(e.title ?? ''),
102
+ startDate: new Date((e.startDate?.timeIntervalSince1970 ?? 0) * 1000),
103
+ endDate: new Date((e.endDate?.timeIntervalSince1970 ?? 0) * 1000),
104
+ allDay: !!e.allDay,
105
+ location: e.location ? String(e.location) : undefined,
106
+ notes: e.notes ? String(e.notes) : undefined,
107
+ timeZone: e.timeZone?.name ? String(e.timeZone.name) : undefined,
108
+ }
103
109
  }
104
110
 
105
111
  const toNSDate = (date: Date) => NSDate.dateWithTimeIntervalSince1970(date.getTime() / 1000)
106
112
 
107
113
  /** Calendar service — EventKit/CalendarContract. */
108
114
  export const calendar: Calendar = {
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
- },
115
+ get supported() {
116
+ return eventStore() !== null
117
+ },
118
+
119
+ ensure(): Promise<PermissionResult> {
120
+ return ensureAccess()
121
+ },
122
+
123
+ async getCalendars(): Promise<CalendarInfo[]> {
124
+ return calendars()
125
+ },
126
+
127
+ async getDefaultCalendar(): Promise<CalendarInfo | null> {
128
+ const def = eventStore()?.defaultCalendarForNewEvents
129
+
130
+ return def
131
+ ? {
132
+ id: String(def.calendarIdentifier),
133
+ title: String(def.title ?? ''),
134
+ allowsModifications: !!def.allowsContentModifications,
135
+ }
136
+ : null
137
+ },
138
+
139
+ async getEvents(
140
+ startDate: Date,
141
+ endDate: Date,
142
+ calendarIds?: string[],
143
+ ): Promise<CalendarEvent[]> {
144
+ const s = eventStore()
145
+ const wanted = calendarIds?.length
146
+ ? calendarIds.map((id) => s?.calendarWithIdentifier?.(id)).filter((c: any) => c != null)
147
+ : null
148
+
149
+ const predicate = s?.predicateForEventsWithStartDateEndDateCalendars(
150
+ toNSDate(startDate),
151
+ toNSDate(endDate),
152
+ wanted?.length ? wanted : null,
153
+ )
154
+
155
+ const list = s?.eventsMatchingPredicate?.(predicate)
156
+ const out: CalendarEvent[] = []
157
+
158
+ for (let i = 0; i < (list?.count ?? 0); i++) {
159
+ const e = asEvent(list.objectAtIndex(i))
160
+
161
+ if (!calendarIds?.length || calendarIds.includes(e.calendarId ?? '')) {
162
+ out.push(e)
163
+ }
164
+ }
165
+
166
+ return out
167
+ },
168
+
169
+ async getEvent(id: string): Promise<CalendarEvent | null> {
170
+ const e = eventStore()?.eventWithIdentifier?.(id)
171
+
172
+ return e ? asEvent(e) : null
173
+ },
174
+
175
+ async createEvent(calendarId: string | undefined, event: NewEvent): Promise<string> {
176
+ const s = eventStore()
177
+
178
+ if (!s) {
179
+ throw new Error('calendar.createEvent: EventKit is unavailable on this host')
180
+ }
181
+
182
+ const e = EKEvent.eventWithEventStore(s)
183
+
184
+ e.title = event.title
185
+ e.startDate = toNSDate(event.startDate)
186
+ e.endDate = toNSDate(event.endDate)
187
+ e.allDay = !!event.allDay
188
+ e.location = (event.location ?? null) as string
189
+ e.notes = (event.notes ?? null) as string
190
+ e.calendar = calendarId
191
+ ? (s.calendarWithIdentifier?.(calendarId) ?? s.defaultCalendarForNewEvents)
192
+ : s.defaultCalendarForNewEvents
193
+
194
+ if (!s.saveEventSpanError(e, EKSpan.ThisEvent ?? 0, null)) {
195
+ throw new Error('calendar.createEvent: EKEventStore.saveEvent failed')
196
+ }
197
+
198
+ return String(e.eventIdentifier ?? '')
199
+ },
200
+
201
+ async updateEvent(id: string, patch: Partial<NewEvent>): Promise<string> {
202
+ const s = eventStore()
203
+ const e = s?.eventWithIdentifier?.(id)
204
+
205
+ if (!e) {
206
+ throw new Error(`calendar.updateEvent: no event ${id}`)
207
+ }
208
+
209
+ if (patch.title !== undefined) {
210
+ e.title = patch.title
211
+ }
212
+
213
+ if (patch.startDate) {
214
+ e.startDate = toNSDate(patch.startDate)
215
+ }
216
+
217
+ if (patch.endDate) {
218
+ e.endDate = toNSDate(patch.endDate)
219
+ }
220
+
221
+ if (patch.allDay !== undefined) {
222
+ e.allDay = patch.allDay
223
+ }
224
+
225
+ if (patch.location !== undefined) {
226
+ e.location = patch.location
227
+ }
228
+
229
+ if (patch.notes !== undefined) {
230
+ e.notes = patch.notes
231
+ }
232
+
233
+ if (!s.saveEventSpanError(e, EKSpan.ThisEvent ?? 0, null)) {
234
+ throw new Error('calendar.updateEvent: EKEventStore.saveEvent failed')
235
+ }
236
+
237
+ return id
238
+ },
239
+
240
+ async deleteEvent(id: string): Promise<void> {
241
+ const s = eventStore()
242
+ const e = s?.eventWithIdentifier?.(id)
243
+
244
+ if (e && !s.removeEventSpanError(e, EKSpan.ThisEvent ?? 0, null)) {
245
+ throw new Error('calendar.deleteEvent: EKEventStore.removeEvent failed')
246
+ }
247
+ },
235
248
  }
236
249
 
237
250
  const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
251
+
238
252
  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
- },
253
+ getPermissions: async () => permissionResponse(),
254
+ requestPermissions: async () => {
255
+ const result = await calendar.ensure()
256
+
257
+ return { status: result, granted: result === 'granted', canAskAgain: result === 'granted' }
258
+ },
244
259
  }