capacitor-gleap-plugin 7.0.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.
@@ -0,0 +1,28 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <Capacitor/Capacitor.h>
3
+
4
+ // Define the plugin using the CAP_PLUGIN Macro, and
5
+ // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
+ CAP_PLUGIN(GleapPlugin, "Gleap",
7
+ CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise);
8
+ CAP_PLUGIN_METHOD(identify, CAPPluginReturnPromise);
9
+ CAP_PLUGIN_METHOD(clearIdentity, CAPPluginReturnPromise);
10
+ CAP_PLUGIN_METHOD(attachCustomData, CAPPluginReturnPromise);
11
+ CAP_PLUGIN_METHOD(setCustomData, CAPPluginReturnPromise);
12
+ CAP_PLUGIN_METHOD(removeCustomData, CAPPluginReturnPromise);
13
+ CAP_PLUGIN_METHOD(clearCustomData, CAPPluginReturnPromise);
14
+ CAP_PLUGIN_METHOD(logEvent, CAPPluginReturnPromise);
15
+ CAP_PLUGIN_METHOD(sendSilentCrashReport, CAPPluginReturnPromise);
16
+ CAP_PLUGIN_METHOD(open, CAPPluginReturnPromise);
17
+ CAP_PLUGIN_METHOD(close, CAPPluginReturnPromise);
18
+ CAP_PLUGIN_METHOD(isOpened, CAPPluginReturnPromise);
19
+ CAP_PLUGIN_METHOD(enableDebugConsoleLog, CAPPluginReturnPromise);
20
+ CAP_PLUGIN_METHOD(log, CAPPluginReturnPromise);
21
+ CAP_PLUGIN_METHOD(disableConsoleLogOverwrite, CAPPluginReturnPromise);
22
+ CAP_PLUGIN_METHOD(startFeedbackFlow, CAPPluginReturnPromise);
23
+ CAP_PLUGIN_METHOD(setLanguage, CAPPluginReturnPromise);
24
+ CAP_PLUGIN_METHOD(setEventCallback, CAPPluginReturnCallback);
25
+ CAP_PLUGIN_METHOD(preFillForm, CAPPluginReturnCallback);
26
+ CAP_PLUGIN_METHOD(addAttachment, CAPPluginReturnCallback);
27
+ CAP_PLUGIN_METHOD(removeAllAttachments, CAPPluginReturnCallback);
28
+ )
@@ -0,0 +1,380 @@
1
+ import Foundation
2
+ import Capacitor
3
+ import Gleap
4
+
5
+ /**
6
+ * Please read the Capacitor iOS Plugin Development Guide
7
+ * here: https://capacitorjs.com/docs/plugins/ios
8
+ */
9
+ @objc(GleapPlugin)
10
+ public class GleapPlugin: CAPPlugin, GleapDelegate {
11
+ enum CallType {
12
+ case event
13
+ }
14
+
15
+ private var callQueue: [String: CallType] = [:]
16
+
17
+ @objc func initialize(_ call: CAPPluginCall) {
18
+ // Check if key is present
19
+ guard let api_key = call.options["API_KEY"] as? String else {
20
+ call.reject("Missing API Key")
21
+ return;
22
+ }
23
+
24
+ // Initialize Gleap with API key
25
+ Gleap.initialize(withToken: api_key)
26
+
27
+ // Provide feedback that it has been success
28
+ call.resolve([
29
+ "initialized": true
30
+ ])
31
+ }
32
+
33
+ @objc func identify(_ call: CAPPluginCall) {
34
+ // If userId is empty, then pass back error
35
+ guard let userId = call.options["userId"] as? String else {
36
+ call.reject("Must provide an user ID")
37
+ return;
38
+ }
39
+
40
+ // Map all values
41
+ let userProperty = GleapUserProperty()
42
+ if (call.getString("name") != nil) {
43
+ userProperty.name = call.getString("name") ?? ""
44
+ }
45
+ if (call.getString("email") != nil) {
46
+ userProperty.email = call.getString("email") ?? ""
47
+ }
48
+ if (call.getDouble("value") != nil) {
49
+ userProperty.value = (call.getDouble("value") ?? 0.0) as NSNumber
50
+ }
51
+ if (call.getString("phone") != nil) {
52
+ userProperty.phone = call.getString("phone") ?? ""
53
+ }
54
+
55
+ if let userHash = call.getString("userHash") {
56
+ Gleap.identifyUser(with: userId, andData: userProperty, andUserHash: userHash)
57
+ } else {
58
+ Gleap.identifyUser(with: userId, andData: userProperty)
59
+ }
60
+
61
+ // Provide feedback that it has been success
62
+ call.resolve([
63
+ "identify": true
64
+ ])
65
+ }
66
+
67
+ @objc func clearIdentity(_ call: CAPPluginCall) {
68
+ // Clear User Identity in Gleap
69
+ Gleap.clearIdentity()
70
+
71
+ // Provide feedback that it has been success
72
+ call.resolve([
73
+ "clearIdentity": true
74
+ ])
75
+ }
76
+
77
+ @objc func disableConsoleLogOverwrite(_ call: CAPPluginCall) {
78
+ call.resolve([
79
+ "consoleLogDisabled": true
80
+ ])
81
+ }
82
+
83
+ @objc func enableDebugConsoleLog(_ call: CAPPluginCall) {
84
+ Gleap.enableDebugConsoleLog()
85
+
86
+ call.resolve([
87
+ "debugConsoleLogEnabled": true
88
+ ])
89
+ }
90
+
91
+ @objc func log(_ call: CAPPluginCall) {
92
+ guard let message = call.options["message"] as? String else {
93
+ call.reject("Must provide a log message")
94
+ return;
95
+ }
96
+
97
+ var logLevel = INFO
98
+ switch call.getString("logLevel") ?? "INFO" {
99
+ case "INFO":
100
+ logLevel = INFO
101
+
102
+ case "WARNING":
103
+ logLevel = WARNING
104
+
105
+ case "ERROR":
106
+ logLevel = INFO
107
+
108
+ default:
109
+ logLevel = INFO
110
+ }
111
+
112
+ Gleap.log(message, with: logLevel)
113
+
114
+ call.resolve([
115
+ "logged": true
116
+ ])
117
+ }
118
+
119
+ @objc func attachCustomData(_ call: CAPPluginCall) {
120
+ // If key is empty, then pass back error
121
+ guard let data = call.getObject("data") else {
122
+ call.reject("Must provide data")
123
+ return;
124
+ }
125
+
126
+ // Set custom data
127
+ Gleap.attachCustomData(data)
128
+
129
+ // Provide feedback that it has been success
130
+ call.resolve([
131
+ "addedCustomData": true
132
+ ])
133
+ }
134
+
135
+ @objc func setCustomData(_ call: CAPPluginCall) {
136
+ // If key is empty, then pass back error
137
+ guard let key = call.options["key"] as? String else {
138
+ call.reject("Must provide a data key")
139
+ return;
140
+ }
141
+
142
+ // If value is empty, then pass back error
143
+ guard let value = call.options["value"] as? String else {
144
+ call.reject("Must provide a data value")
145
+ return;
146
+ }
147
+
148
+ // Append custom data
149
+ Gleap.setCustomData(value, forKey: key)
150
+
151
+
152
+ // Provide feedback that it has been success
153
+ call.resolve([
154
+ "setCustomData": true
155
+ ])
156
+ }
157
+
158
+ @objc func removeCustomData(_ call: CAPPluginCall) {
159
+ // If key is empty, then pass back error
160
+ guard let key = call.options["key"] as? String else {
161
+ call.reject("Must provide a data key")
162
+ return;
163
+ }
164
+
165
+ // Remove custom data
166
+ Gleap.removeCustomData(forKey: key)
167
+
168
+
169
+ // Provide feedback that it has been success
170
+ call.resolve([
171
+ "removedCustomData": true
172
+ ])
173
+ }
174
+
175
+ @objc func clearCustomData(_ call: CAPPluginCall) {
176
+ // Clear custom data
177
+ Gleap.clearCustomData()
178
+
179
+ // Provide feedback that it has been success
180
+ call.resolve([
181
+ "clearedCustomData": true
182
+ ])
183
+ }
184
+
185
+ @objc func preFillForm(_ call: CAPPluginCall) {
186
+ // If key is empty, then pass back error
187
+ guard let data = call.getObject("data") else {
188
+ call.reject("Must provide data")
189
+ return;
190
+ }
191
+
192
+ // Prefill the form
193
+ Gleap.preFillForm(data)
194
+
195
+ // Provide feedback that it has been success
196
+ call.resolve([
197
+ "preFilledForm": true
198
+ ])
199
+ }
200
+
201
+ @objc func logEvent(_ call: CAPPluginCall) {
202
+ guard let eventName = call.options["name"] as? String else {
203
+ call.reject("No event log subject provided")
204
+ return;
205
+ }
206
+
207
+ if let eventData = call.getObject("data") {
208
+ Gleap.logEvent(eventName, withData: eventData)
209
+ } else {
210
+ Gleap.logEvent(eventName)
211
+ }
212
+
213
+ // Provide feedback that it has been success
214
+ call.resolve([
215
+ "loggedEvent": true
216
+ ])
217
+ }
218
+
219
+ @objc func addAttachment(_ call: CAPPluginCall) {
220
+ guard let base64data = call.options["base64data"] as? String else {
221
+ call.reject("No base64 file data provided")
222
+ return;
223
+ }
224
+
225
+ guard let name = call.options["name"] as? String else {
226
+ call.reject("No file name provided")
227
+ return;
228
+ }
229
+
230
+ guard let fileData = Data(base64Encoded: base64data, options: .ignoreUnknownCharacters) else {
231
+ call.reject("Invalid file data")
232
+ return;
233
+ }
234
+
235
+ Gleap.addAttachment(with: fileData, andName: name)
236
+
237
+ // Provide feedback that it has been success
238
+ call.resolve([
239
+ "attachmentAdded": true
240
+ ])
241
+ }
242
+
243
+ @objc func removeAllAttachments(_ call: CAPPluginCall) {
244
+ Gleap.removeAllAttachments()
245
+
246
+ // Provide feedback that it has been success
247
+ call.resolve([
248
+ "allAttachmentsRemoved": true
249
+ ])
250
+ }
251
+
252
+ @objc func sendSilentCrashReport(_ call: CAPPluginCall) {
253
+ let dataExclusion = call.getObject("dataExclusion") ?? [:]
254
+ let severity = call.getString("severity") ?? "low"
255
+
256
+ // If logEventSubject is empty, then pass back error
257
+ guard let description = call.options["description"] as? String else {
258
+ call.reject("No silent bug report description provided")
259
+ return;
260
+ }
261
+
262
+ var severityType = MEDIUM
263
+ if (severity == "HIGH") {
264
+ severityType = HIGH
265
+ } else if (severity == "MEDIUM") {
266
+ severityType = MEDIUM
267
+ } else {
268
+ severityType = LOW
269
+ }
270
+
271
+ Gleap.sendSilentCrashReport(with: description, andSeverity: severityType, andDataExclusion: dataExclusion) { success in
272
+ call.resolve([
273
+ "sentSilentBugReport": success
274
+ ])
275
+ }
276
+ }
277
+
278
+ @objc func setEventCallback(_ call: CAPPluginCall) {
279
+ call.keepAlive = true
280
+ callQueue[call.callbackId] = .event
281
+
282
+ DispatchQueue.main.async {
283
+ Gleap.sharedInstance().delegate = self
284
+ }
285
+ }
286
+
287
+ @objc func open(_ call: CAPPluginCall) {
288
+ // Open widget
289
+ Gleap.open()
290
+
291
+ // Provide feedback that it has been success
292
+ call.resolve([
293
+ "openedWidget": true
294
+ ])
295
+ }
296
+
297
+ @objc func close(_ call: CAPPluginCall) {
298
+ // Open widget
299
+ Gleap.close()
300
+
301
+ // Provide feedback that it has been success
302
+ call.resolve([
303
+ "closedWidget": true
304
+ ])
305
+ }
306
+
307
+ @objc func isOpened(_ call: CAPPluginCall) {
308
+ // Provide feedback that it has been success
309
+ call.resolve([
310
+ "isOpened": Gleap.isOpened()
311
+ ])
312
+ }
313
+
314
+ @objc func startFeedbackFlow(_ call: CAPPluginCall) {
315
+ let feedbackFlow = call.getString("feedbackFlow") ?? "bugreporting"
316
+ let showBackButton = call.getBool("showBackButton") ?? false
317
+
318
+ Gleap.startFeedbackFlow(feedbackFlow, showBackButton: showBackButton)
319
+
320
+ // Provide feedback that it has been success
321
+ call.resolve([
322
+ "startedFeedbackFlow": true
323
+ ])
324
+ }
325
+
326
+ @objc func setLanguage(_ call: CAPPluginCall) {
327
+
328
+ // If languageCode is empty, then pass back error
329
+ guard let languageCode = call.options["languageCode"] as? String else {
330
+ call.reject("No language provided")
331
+ return;
332
+ }
333
+
334
+ // set language in Gleap
335
+ Gleap.setLanguage(languageCode)
336
+
337
+ // Provide feedback that it has been success
338
+ call.resolve([
339
+ "setLanguage": languageCode
340
+ ])
341
+ }
342
+
343
+ func notifyEventUpdate(name: String, data: Any?) {
344
+ var eventData: PluginCallResultData = [
345
+ "name": name
346
+ ];
347
+ if let data = data {
348
+ eventData["data"] = data
349
+ }
350
+ for (id, callType) in callQueue {
351
+ if let call = bridge?.savedCall(withID: id), callType == .event {
352
+ call.resolve(eventData)
353
+ }
354
+ }
355
+ }
356
+
357
+ public func customActionCalled(_ customAction: String) {
358
+ notifyEventUpdate(name: "custom-action-called", data: nil)
359
+ }
360
+
361
+ public func widgetClosed() {
362
+ notifyEventUpdate(name: "widget-closed", data: nil)
363
+ }
364
+
365
+ public func widgetOpened() {
366
+ notifyEventUpdate(name: "widget-opened", data: nil)
367
+ }
368
+
369
+ public func feedbackFlowStarted(_ feedbackAction: [AnyHashable : Any]) {
370
+ notifyEventUpdate(name: "flow-started", data: feedbackAction)
371
+ }
372
+
373
+ public func feedbackSent(_ data: [AnyHashable : Any]) {
374
+ notifyEventUpdate(name: "feedback-sent", data: data)
375
+ }
376
+
377
+ public func feedbackSendingFailed() {
378
+ notifyEventUpdate(name: "error-while-sending", data: nil)
379
+ }
380
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>$(CURRENT_PROJECT_VERSION)</string>
21
+ <key>NSPrincipalClass</key>
22
+ <string></string>
23
+ </dict>
24
+ </plist>
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "capacitor-gleap-plugin",
3
+ "version": "7.0.0",
4
+ "description": "Gleap SDK for Capacitor is the easiest way to integrate Gleap into your Ionic apps! Achieve better app quality with comprehensive in-app bug reporting & customer feedback for your web-apps and websites. Many thanks to Stephan Nagel (congrapp) for his work on the Gleap capacitor plugin.",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "ios/Plugin/",
14
+ "CapacitorGleapPlugin.podspec"
15
+ ],
16
+ "author": "Gleap GmbH",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/GleapSDK/Capacitor.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/GleapSDK/Capacitor/issues"
24
+ },
25
+ "keywords": [
26
+ "capacitor",
27
+ "plugin",
28
+ "native",
29
+ "gleap",
30
+ "bugreporting",
31
+ "customerfeedback",
32
+ "inappbugreporting"
33
+ ],
34
+ "scripts": {
35
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
36
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
37
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
38
+ "verify:web": "npm run build",
39
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
40
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
41
+ "eslint": "eslint . --ext ts",
42
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
43
+ "swiftlint": "node-swiftlint",
44
+ "docgen": "docgen --api GleapPlugin --output-readme README.md --output-json dist/docs.json",
45
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
46
+ "clean": "rimraf ./dist",
47
+ "watch": "tsc --watch",
48
+ "prepublishOnly": "npm run build",
49
+ "prepare": "npm run build"
50
+ },
51
+ "dependencies": {
52
+ "gleap": "7.0.25"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "devDependencies": {
58
+ "@capacitor/android": "^3.0.0",
59
+ "@capacitor/core": "^3.0.0",
60
+ "@capacitor/docgen": "^0.0.10",
61
+ "@capacitor/ios": "^3.0.0",
62
+ "@ionic/eslint-config": "^0.3.0",
63
+ "@ionic/prettier-config": "^1.0.1",
64
+ "@ionic/swiftlint-config": "^1.1.2",
65
+ "eslint": "^7.11.0",
66
+ "prettier": "~2.2.0",
67
+ "prettier-plugin-java": "~1.0.0",
68
+ "rimraf": "^3.0.2",
69
+ "rollup": "^2.32.0",
70
+ "swiftlint": "^1.0.1",
71
+ "typescript": "~4.0.3"
72
+ },
73
+ "peerDependencies": {
74
+ "@capacitor/core": "^3.0.0"
75
+ },
76
+ "prettier": "@ionic/prettier-config",
77
+ "swiftlint": "@ionic/swiftlint-config",
78
+ "eslintConfig": {
79
+ "extends": "@ionic/eslint-config/recommended"
80
+ },
81
+ "capacitor": {
82
+ "ios": {
83
+ "src": "ios"
84
+ },
85
+ "android": {
86
+ "src": "android"
87
+ }
88
+ }
89
+ }