@octane-xplat/calendar 0.18.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 +3 -23
- package/package.json +86 -93
- package/src/calendar.macos.ts +255 -11
- package/src/calendar.ts +389 -258
- package/src/calendar.web.ts +11 -9
- package/src/calendar.windows.ts +12 -10
- package/src/types.ts +69 -31
- package/types/generated/.tsrx-typegen-manifest.json +0 -6
- package/types/generated/calendar.d.ts +1 -0
- package/types/generated/types.d.ts +38 -0
- package/LICENSE +0 -21
- package/types/generated/calendar.linux.d.ts +0 -1
- package/types/generated/calendar.macos.d.ts +0 -2
- package/types/generated/calendar.web.d.ts +0 -2
- package/types/generated/calendar.windows.d.ts +0 -2
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @octane-xplat/calendar
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
pnpm add @octane-xplat/calendar
|
|
5
|
-
```
|
|
3
|
+
[Documentation](https://octane-xplat.goddardai.org/package-calendar).
|
|
6
4
|
|
|
7
|
-
|
|
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.
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
import { calendar } from '@octane-xplat/calendar'
|
|
14
|
-
|
|
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
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Reminders, attendees, and recurring-edit modes are out of scope (Expo models
|
|
25
|
-
reminders as a separate entity).
|
|
5
|
+
[API reference](https://octane-xplat.goddardai.org/api-calendar).
|
package/package.json
CHANGED
|
@@ -1,94 +1,87 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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.20.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
|
+
"octane": "0.16.3",
|
|
61
|
+
"tsrx-typegen": "0.6.1",
|
|
62
|
+
"typescript": "7.1.0-beta",
|
|
63
|
+
"@tsrx/content-mapper": "0.1.2"
|
|
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.20.0"
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/calendar.macos.ts
CHANGED
|
@@ -1,15 +1,259 @@
|
|
|
1
|
-
|
|
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 { EKEntityType, EKEvent, EKEventStore, EKSpan, NSDate } from '@octane-xplat/platform/macos'
|
|
7
|
+
import type { Calendar, CalendarEvent, CalendarInfo, NewEvent, PermissionResult } from './types'
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
let store: any = null
|
|
10
|
+
const eventStore = () => {
|
|
11
|
+
if (store) {
|
|
12
|
+
return store
|
|
13
|
+
}
|
|
4
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
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// EKAuthorizationStatus: 0 notDetermined 1 restricted 2 denied
|
|
27
|
+
// 3 fullAccess/authorized 4 writeOnly
|
|
28
|
+
const rawStatus = () =>
|
|
29
|
+
Number(EKEventStore.authorizationStatusForEntityType(EKEntityType.Event ?? 0))
|
|
30
|
+
|
|
31
|
+
function ensureAccess(): Promise<PermissionResult> {
|
|
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
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const permissionResponse = () => {
|
|
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
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function calendars(): CalendarInfo[] {
|
|
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
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function asEvent(e: any): CalendarEvent {
|
|
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
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const toNSDate = (date: Date) => NSDate.dateWithTimeIntervalSince1970(date.getTime() / 1000)
|
|
112
|
+
|
|
113
|
+
/** Calendar service — EventKit/CalendarContract. */
|
|
5
114
|
export const calendar: Calendar = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
},
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
|
|
251
|
+
|
|
252
|
+
permissionOwners.calendar = {
|
|
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
|
+
},
|
|
15
259
|
}
|