@ebarooni/capacitor-calendar 8.8.0 → 8.10.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 +27 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +70 -25
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +45 -22
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +1 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/CalendarInfo.kt +1 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CreateEventInput.kt +4 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventInput.kt +4 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventWithPromptInput.kt +4 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ModifyEvent.kt +8 -2
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ModifyEventWithPromptInput.kt +1 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/GetDefaultCalendarResult.kt +1 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/ListCalendarsResult.kt +1 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/DeclarationCheck.kt +59 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +27 -2
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/PluginCallRejecter.kt +69 -0
- package/dist/docs.json +2 -2
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.d.ts +44 -0
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js +46 -0
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js.map +1 -0
- package/dist/esm/schemas/interfaces/calendar.d.ts +3 -1
- package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
- package/dist/plugin.cjs.js +46 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +46 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +66 -22
- package/ios/Plugin/PluginError.swift +47 -0
- package/ios/Plugin/Utils/DeclarationCheck.swift +63 -0
- package/ios/Plugin/Utils/PluginCallRejecter.swift +36 -0
- package/package.json +1 -1
|
@@ -17,10 +17,12 @@ enum PluginError: LocalizedError {
|
|
|
17
17
|
case invalidFrequency
|
|
18
18
|
case invalidScope
|
|
19
19
|
case invalidUrl
|
|
20
|
+
case ioError(String)
|
|
20
21
|
case listIdsMissing
|
|
21
22
|
case listNotFound
|
|
22
23
|
case listNotModifiable
|
|
23
24
|
case messageMissing
|
|
25
|
+
case missingDeclaration(String)
|
|
24
26
|
case missingFrequency
|
|
25
27
|
case missingInterval
|
|
26
28
|
case noFieldsToModify
|
|
@@ -68,6 +70,8 @@ enum PluginError: LocalizedError {
|
|
|
68
70
|
return NSLocalizedString("Invalid scope.", comment: "Invalid scope error")
|
|
69
71
|
case .invalidUrl:
|
|
70
72
|
return NSLocalizedString("Invalid URL.", comment: "Invalid URL error")
|
|
73
|
+
case .ioError(let message):
|
|
74
|
+
return message
|
|
71
75
|
case .listIdsMissing:
|
|
72
76
|
return NSLocalizedString("List IDs must be provided.", comment: "List IDs missing error")
|
|
73
77
|
case .listNotFound:
|
|
@@ -76,6 +80,8 @@ enum PluginError: LocalizedError {
|
|
|
76
80
|
return NSLocalizedString("List is not modifiable.", comment: "List not modifiable error")
|
|
77
81
|
case .messageMissing:
|
|
78
82
|
return NSLocalizedString("Message must be provided.", comment: "Message missing error")
|
|
83
|
+
case .missingDeclaration(let key):
|
|
84
|
+
return "Missing Info.plist usage description: \(key)."
|
|
79
85
|
case .missingFrequency:
|
|
80
86
|
return NSLocalizedString("Frequency must be provided.", comment: "Frequency missing error")
|
|
81
87
|
case .missingInterval:
|
|
@@ -102,4 +108,45 @@ enum PluginError: LocalizedError {
|
|
|
102
108
|
return NSLocalizedString("Missing view controller.", comment: "View controller missing error")
|
|
103
109
|
}
|
|
104
110
|
}
|
|
111
|
+
|
|
112
|
+
/// Cap-style reject code when this error provides one; nil for message-only cases.
|
|
113
|
+
var code: String? {
|
|
114
|
+
switch self {
|
|
115
|
+
case .calendarIdMissing,
|
|
116
|
+
.fromDateMissing,
|
|
117
|
+
.idMissing,
|
|
118
|
+
.invalidColor,
|
|
119
|
+
.invalidFrequency,
|
|
120
|
+
.invalidScope,
|
|
121
|
+
.invalidUrl,
|
|
122
|
+
.listIdsMissing,
|
|
123
|
+
.messageMissing,
|
|
124
|
+
.missingFrequency,
|
|
125
|
+
.missingInterval,
|
|
126
|
+
.noFieldsToModify,
|
|
127
|
+
.scopeMissing,
|
|
128
|
+
.titleMissing,
|
|
129
|
+
.toDateMissing:
|
|
130
|
+
return "EB-CLDR-0001"
|
|
131
|
+
case .calendarNotFound,
|
|
132
|
+
.calendarSourceNotFound,
|
|
133
|
+
.eventNotFound,
|
|
134
|
+
.listNotFound,
|
|
135
|
+
.reminderNotFound:
|
|
136
|
+
return "EB-CLDR-0002"
|
|
137
|
+
case .failedToRetrieveCalendarId,
|
|
138
|
+
.failedToRetrieveEventId,
|
|
139
|
+
.ioError,
|
|
140
|
+
.processFailed:
|
|
141
|
+
return "EB-CLDR-0004"
|
|
142
|
+
case .failedToLaunchCalendar,
|
|
143
|
+
.failedToLaunchReminders,
|
|
144
|
+
.unableToOpenUrl:
|
|
145
|
+
return "EB-CLDR-0005"
|
|
146
|
+
case .missingDeclaration:
|
|
147
|
+
return "EB-CLDR-0100"
|
|
148
|
+
default:
|
|
149
|
+
return nil
|
|
150
|
+
}
|
|
151
|
+
}
|
|
105
152
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Early Info.plist usage-description checks for EB-CLDR-0100 MissingDeclaration.
|
|
4
|
+
/// Callers pass only the access level the method actually uses.
|
|
5
|
+
enum DeclarationCheck {
|
|
6
|
+
/// Throws `PluginError.missingDeclaration` when the Info.plist key for the scope is missing.
|
|
7
|
+
static func ensureUsageDescription(for scope: CalendarPermissionScope) throws {
|
|
8
|
+
switch scope {
|
|
9
|
+
case .writeCalendar:
|
|
10
|
+
try ensureWriteOnlyCalendarUsageDescription()
|
|
11
|
+
case .readCalendar:
|
|
12
|
+
try ensureFullCalendarUsageDescription()
|
|
13
|
+
case .writeReminders, .readReminders:
|
|
14
|
+
try ensureRemindersUsageDescription()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static func ensureWriteOnlyCalendarUsageDescription() throws {
|
|
19
|
+
try ensureUsageDescriptionKey(requiredWriteOnlyCalendarUsageDescriptionKey())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static func ensureFullCalendarUsageDescription() throws {
|
|
23
|
+
try ensureUsageDescriptionKey(requiredFullCalendarUsageDescriptionKey())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static func ensureRemindersUsageDescription() throws {
|
|
27
|
+
try ensureUsageDescriptionKey(requiredRemindersUsageDescriptionKey())
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private static func ensureUsageDescriptionKey(_ key: String) throws {
|
|
31
|
+
guard hasUsageDescription(forKey: key) else {
|
|
32
|
+
throw PluginError.missingDeclaration(key)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private static func hasUsageDescription(forKey key: String) -> Bool {
|
|
37
|
+
guard let value = Bundle.main.object(forInfoDictionaryKey: key) as? String else {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
return !value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private static func requiredWriteOnlyCalendarUsageDescriptionKey() -> String {
|
|
44
|
+
if #available(iOS 17.0, *) {
|
|
45
|
+
return "NSCalendarsWriteOnlyAccessUsageDescription"
|
|
46
|
+
}
|
|
47
|
+
return "NSCalendarsUsageDescription"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private static func requiredFullCalendarUsageDescriptionKey() -> String {
|
|
51
|
+
if #available(iOS 17.0, *) {
|
|
52
|
+
return "NSCalendarsFullAccessUsageDescription"
|
|
53
|
+
}
|
|
54
|
+
return "NSCalendarsUsageDescription"
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private static func requiredRemindersUsageDescriptionKey() -> String {
|
|
58
|
+
if #available(iOS 17.0, *) {
|
|
59
|
+
return "NSRemindersFullAccessUsageDescription"
|
|
60
|
+
}
|
|
61
|
+
return "NSRemindersUsageDescription"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
/// Maps thrown errors to `PluginError` and rejects the Capacitor call.
|
|
5
|
+
enum PluginCallRejecter {
|
|
6
|
+
static func reject(_ call: CAPPluginCall, _ error: Error?) {
|
|
7
|
+
let pluginError = toPluginError(error)
|
|
8
|
+
let message = pluginError?.localizedDescription
|
|
9
|
+
?? PluginError.customError("An unknown error has occurred.").localizedDescription
|
|
10
|
+
call.reject(message, pluginError?.code)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static func toPluginError(_ error: Error?) -> PluginError? {
|
|
14
|
+
if let error = error as? PluginError {
|
|
15
|
+
return error
|
|
16
|
+
} else if let error = error {
|
|
17
|
+
return .ioError(
|
|
18
|
+
wrapSystemError(
|
|
19
|
+
"An I/O error occurred while accessing the calendar.",
|
|
20
|
+
error.localizedDescription
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
} else {
|
|
24
|
+
return nil
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Lead with the stable plugin sentence; append a different non-blank OS message in parentheses.
|
|
29
|
+
static func wrapSystemError(_ canonicalMessage: String, _ systemMessage: String?) -> String {
|
|
30
|
+
let detail = systemMessage?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
|
31
|
+
if detail.isEmpty || detail == canonicalMessage {
|
|
32
|
+
return canonicalMessage
|
|
33
|
+
}
|
|
34
|
+
return "\(canonicalMessage) (\(detail))"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebarooni/capacitor-calendar",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.10.0",
|
|
4
4
|
"description": "A Capacitor plugin for native calendar events on iOS and Android (with reminders on iOS), and .ics event creation on the web.",
|
|
5
5
|
"author": "Ehsan Barooni",
|
|
6
6
|
"license": "MIT",
|