@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 +2 -37
- package/package.json +5 -5
- package/src/calendar.macos.ts +223 -208
- package/src/calendar.ts +386 -341
- package/src/calendar.web.ts +10 -9
- package/src/calendar.windows.ts +10 -10
- package/src/types.ts +63 -63
- package/types/generated/.tsrx-typegen-manifest.json +0 -6
- package/types/generated/calendar.linux.d.ts +0 -1
- package/types/generated/calendar.macos.d.ts +0 -3
- package/types/generated/calendar.web.d.ts +0 -3
- package/types/generated/calendar.windows.d.ts +0 -3
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,40 +1,5 @@
|
|
|
1
1
|
# @octane-xplat/calendar
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
`supported: false`; this package does not generate calendar invitation files.
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-calendar).
|
|
5
4
|
|
|
6
|
-
|
|
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.
|
|
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.
|
|
63
|
-
"typescript": "
|
|
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.
|
|
85
|
+
"@octane-xplat/platform": "0.20.0"
|
|
86
86
|
}
|
|
87
87
|
}
|
package/src/calendar.macos.ts
CHANGED
|
@@ -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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
29
|
+
Number(EKEventStore.authorizationStatusForEntityType(EKEntityType.Event ?? 0))
|
|
35
30
|
|
|
36
31
|
function ensureAccess(): Promise<PermissionResult> {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
}
|