@ua/capacitor-airship 1.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.
Files changed (84) hide show
  1. package/README.md +12 -0
  2. package/UaCapacitorAirship.podspec +18 -0
  3. package/android/build.gradle +72 -0
  4. package/android/src/main/AndroidManifest.xml +33 -0
  5. package/android/src/main/java/com/airship/capacitor/AirshipCapacitorVersion.kt +7 -0
  6. package/android/src/main/java/com/airship/capacitor/AirshipPlugin.kt +331 -0
  7. package/android/src/main/java/com/airship/capacitor/CapacitorAutopilot.kt +39 -0
  8. package/android/src/main/res/.gitkeep +0 -0
  9. package/dist/esm/AirshipActions.d.ts +18 -0
  10. package/dist/esm/AirshipActions.js +20 -0
  11. package/dist/esm/AirshipActions.js.map +1 -0
  12. package/dist/esm/AirshipAnalytics.d.ts +30 -0
  13. package/dist/esm/AirshipAnalytics.js +39 -0
  14. package/dist/esm/AirshipAnalytics.js.map +1 -0
  15. package/dist/esm/AirshipChannel.d.ts +61 -0
  16. package/dist/esm/AirshipChannel.js +87 -0
  17. package/dist/esm/AirshipChannel.js.map +1 -0
  18. package/dist/esm/AirshipContact.d.ts +48 -0
  19. package/dist/esm/AirshipContact.js +68 -0
  20. package/dist/esm/AirshipContact.js.map +1 -0
  21. package/dist/esm/AirshipFeatureFlagManager.d.ts +24 -0
  22. package/dist/esm/AirshipFeatureFlagManager.js +28 -0
  23. package/dist/esm/AirshipFeatureFlagManager.js.map +1 -0
  24. package/dist/esm/AirshipInApp.d.ts +30 -0
  25. package/dist/esm/AirshipInApp.js +39 -0
  26. package/dist/esm/AirshipInApp.js.map +1 -0
  27. package/dist/esm/AirshipLocale.d.ts +24 -0
  28. package/dist/esm/AirshipLocale.js +31 -0
  29. package/dist/esm/AirshipLocale.js.map +1 -0
  30. package/dist/esm/AirshipMessageCenter.d.ts +77 -0
  31. package/dist/esm/AirshipMessageCenter.js +99 -0
  32. package/dist/esm/AirshipMessageCenter.js.map +1 -0
  33. package/dist/esm/AirshipPlugin.d.ts +31 -0
  34. package/dist/esm/AirshipPlugin.js +15 -0
  35. package/dist/esm/AirshipPlugin.js.map +1 -0
  36. package/dist/esm/AirshipPreferenceCenter.d.ts +38 -0
  37. package/dist/esm/AirshipPreferenceCenter.js +49 -0
  38. package/dist/esm/AirshipPreferenceCenter.js.map +1 -0
  39. package/dist/esm/AirshipPrivacyManager.d.ts +38 -0
  40. package/dist/esm/AirshipPrivacyManager.js +48 -0
  41. package/dist/esm/AirshipPrivacyManager.js.map +1 -0
  42. package/dist/esm/AirshipPush.d.ts +184 -0
  43. package/dist/esm/AirshipPush.js +232 -0
  44. package/dist/esm/AirshipPush.js.map +1 -0
  45. package/dist/esm/AirshipRoot.d.ts +49 -0
  46. package/dist/esm/AirshipRoot.js +55 -0
  47. package/dist/esm/AirshipRoot.js.map +1 -0
  48. package/dist/esm/AttributeEditor.d.ts +54 -0
  49. package/dist/esm/AttributeEditor.js +76 -0
  50. package/dist/esm/AttributeEditor.js.map +1 -0
  51. package/dist/esm/EventType.d.ts +25 -0
  52. package/dist/esm/EventType.js +14 -0
  53. package/dist/esm/EventType.js.map +1 -0
  54. package/dist/esm/ScopedSubscriptionListEditor.d.ts +59 -0
  55. package/dist/esm/ScopedSubscriptionListEditor.js +62 -0
  56. package/dist/esm/ScopedSubscriptionListEditor.js.map +1 -0
  57. package/dist/esm/SubscriptionListEditor.d.ts +50 -0
  58. package/dist/esm/SubscriptionListEditor.js +56 -0
  59. package/dist/esm/SubscriptionListEditor.js.map +1 -0
  60. package/dist/esm/TagEditor.d.ts +46 -0
  61. package/dist/esm/TagEditor.js +46 -0
  62. package/dist/esm/TagEditor.js.map +1 -0
  63. package/dist/esm/TagGroupEditor.d.ts +60 -0
  64. package/dist/esm/TagGroupEditor.js +60 -0
  65. package/dist/esm/TagGroupEditor.js.map +1 -0
  66. package/dist/esm/index.d.ts +20 -0
  67. package/dist/esm/index.js +25 -0
  68. package/dist/esm/index.js.map +1 -0
  69. package/dist/esm/types.d.ts +651 -0
  70. package/dist/esm/types.js +167 -0
  71. package/dist/esm/types.js.map +1 -0
  72. package/dist/plugin.cjs.js +1278 -0
  73. package/dist/plugin.cjs.js.map +1 -0
  74. package/dist/plugin.js +1281 -0
  75. package/dist/plugin.js.map +1 -0
  76. package/ios/Plugin/AirshipCapacitorAutopilot.swift +94 -0
  77. package/ios/Plugin/AirshipCapacitorBootstrap.h +8 -0
  78. package/ios/Plugin/AirshipCapacitorBootstrap.m +24 -0
  79. package/ios/Plugin/AirshipCapacitorVersion.swift +7 -0
  80. package/ios/Plugin/AirshipPlugin.h +7 -0
  81. package/ios/Plugin/AirshipPlugin.m +9 -0
  82. package/ios/Plugin/AirshipPlugin.swift +557 -0
  83. package/ios/Plugin/Info.plist +24 -0
  84. package/package.json +75 -0
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Capacitor Airship Plugin
2
+
3
+ A Capacitor plugin for Airship's iOS and Android SDK.
4
+
5
+ ### Resources
6
+
7
+ * [Getting started guide](https://docs.airship.com/platform/mobile/setup/sdk/capacitor/)
8
+ * [API docs](https://docs.airship.com/reference/libraries/capacitor-airship/latest/)
9
+
10
+ ### Issues
11
+
12
+ Please visit https://support.airship.com/ for any issues integrating or using this plugin.
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'UaCapacitorAirship'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '14.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ s.dependency "AirshipFrameworkProxy", "5.4.1"
18
+ end
@@ -0,0 +1,72 @@
1
+ buildscript {
2
+ def kotlinVersion = project.hasProperty('kotlinVersion') ? rootProject.ext.kotlinVersion : '1.8.20'
3
+
4
+ repositories {
5
+ google()
6
+ mavenCentral()
7
+ }
8
+ dependencies {
9
+ classpath 'com.android.tools.build:gradle:8.0.2'
10
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
11
+ }
12
+ }
13
+
14
+ def isHmsEnabled() {
15
+ return (rootProject.hasProperty("airshipHmsEnabled") && rootProject.getProperty("airshipHmsEnabled") == "true") || (rootProject.ext.has("airshipHmsEnabled") && rootProject.ext.get("airshipHmsEnabled") == "true")
16
+ }
17
+
18
+ def getExtOrDefault(name) {
19
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Airship_" + name]
20
+ }
21
+
22
+ apply plugin: 'com.android.library'
23
+ apply plugin: 'org.jetbrains.kotlin.android'
24
+
25
+ android {
26
+ namespace "com.airship.capacitor"
27
+ compileSdk 34
28
+ defaultConfig {
29
+ minSdkVersion 22
30
+ targetSdkVersion 34
31
+ versionCode 1
32
+ versionName "1.0"
33
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
34
+ }
35
+ buildTypes {
36
+ release {
37
+ minifyEnabled false
38
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39
+ }
40
+ }
41
+ lintOptions {
42
+ abortOnError false
43
+ }
44
+ compileOptions {
45
+ sourceCompatibility JavaVersion.VERSION_17
46
+ targetCompatibility JavaVersion.VERSION_17
47
+ }
48
+ kotlinOptions {
49
+ jvmTarget = '17'
50
+ }
51
+ }
52
+
53
+ repositories {
54
+ google()
55
+ mavenCentral()
56
+ }
57
+
58
+ dependencies {
59
+ def proxyVersion = '5.4.1'
60
+ def airshipVersion = '17.7.3'
61
+ def kotlinVersion = project.hasProperty('kotlinVersion') ? rootProject.ext.kotlinVersion : '1.8.20'
62
+
63
+
64
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
65
+ implementation project(':capacitor-android')
66
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
67
+ api "com.urbanairship.android:airship-framework-proxy:$proxyVersion"
68
+
69
+ if (isHmsEnabled()) {
70
+ implementation "com.urbanairship.android:urbanairship-hms:$airshipVersion"
71
+ }
72
+ }
@@ -0,0 +1,33 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+
3
+ <application>
4
+ <meta-data
5
+ android:name="com.urbanairship.autopilot"
6
+ android:value="com.airship.capacitor.CapacitorAutopilot"/>
7
+
8
+ <meta-data
9
+ android:name="com.urbanairship.webview.ENABLE_LOCAL_STORAGE"
10
+ android:value="true" />
11
+
12
+ <activity
13
+ android:name="com.urbanairship.android.framework.proxy.CustomMessageCenterActivity"
14
+ android:label="@string/ua_message_center_title"
15
+ android:launchMode="singleTask"
16
+ android:exported="false">
17
+ <intent-filter>
18
+ <action android:name="com.urbanairship.VIEW_RICH_PUSH_INBOX" />
19
+ <category android:name="android.intent.category.DEFAULT" />
20
+ </intent-filter>
21
+ </activity>
22
+
23
+ <activity
24
+ android:name="com.urbanairship.android.framework.proxy.CustomMessageActivity"
25
+ android:exported="false">
26
+ <intent-filter>
27
+ <action android:name="com.urbanairship.VIEW_RICH_PUSH_MESSAGE" />
28
+ <data android:scheme="message" />
29
+ <category android:name="android.intent.category.DEFAULT" />
30
+ </intent-filter>
31
+ </activity>
32
+ </application>
33
+ </manifest>
@@ -0,0 +1,7 @@
1
+ /* Copyright Urban Airship and Contributors */
2
+
3
+ package com.airship.capacitor
4
+
5
+ object AirshipCapacitorVersion {
6
+ var version = "1.0.0"
7
+ }
@@ -0,0 +1,331 @@
1
+ package com.airship.capacitor
2
+
3
+ import android.os.Build
4
+ import com.getcapacitor.JSArray
5
+ import com.getcapacitor.JSObject
6
+ import com.getcapacitor.Plugin
7
+ import com.getcapacitor.PluginCall
8
+ import com.getcapacitor.PluginMethod
9
+ import com.getcapacitor.annotation.CapacitorPlugin
10
+ import com.urbanairship.Autopilot
11
+ import com.urbanairship.PendingResult
12
+ import com.urbanairship.UALog
13
+ import com.urbanairship.actions.ActionResult
14
+ import com.urbanairship.android.framework.proxy.EventType
15
+ import com.urbanairship.android.framework.proxy.events.EventEmitter
16
+ import com.urbanairship.android.framework.proxy.proxies.AirshipProxy
17
+ import com.urbanairship.android.framework.proxy.proxies.FeatureFlagProxy
18
+ import com.urbanairship.json.JsonList
19
+ import com.urbanairship.json.JsonMap
20
+ import com.urbanairship.json.JsonSerializable
21
+ import com.urbanairship.json.JsonValue
22
+ import com.urbanairship.json.jsonMapOf
23
+ import kotlinx.coroutines.CoroutineScope
24
+ import kotlinx.coroutines.Dispatchers
25
+ import kotlinx.coroutines.SupervisorJob
26
+ import kotlinx.coroutines.launch
27
+ import kotlinx.coroutines.plus
28
+ import org.json.JSONArray
29
+ import org.json.JSONObject
30
+
31
+ @CapacitorPlugin(name = "Airship")
32
+ class AirshipPlugin : Plugin() {
33
+ private val scope: CoroutineScope = CoroutineScope(Dispatchers.Main) + SupervisorJob()
34
+
35
+ companion object {
36
+ private val EVENT_NAME_MAP = mapOf(
37
+ EventType.BACKGROUND_NOTIFICATION_RESPONSE_RECEIVED to "notification_response",
38
+ EventType.FOREGROUND_NOTIFICATION_RESPONSE_RECEIVED to "notification_response",
39
+ EventType.CHANNEL_CREATED to "channel_created",
40
+ EventType.DEEP_LINK_RECEIVED to "deep_link_received",
41
+ EventType.DISPLAY_MESSAGE_CENTER to "display_message_center",
42
+ EventType.DISPLAY_PREFERENCE_CENTER to "display_preference_center",
43
+ EventType.MESSAGE_CENTER_UPDATED to "message_center_updated",
44
+ EventType.PUSH_TOKEN_RECEIVED to "push_token_received",
45
+ EventType.FOREGROUND_PUSH_RECEIVED to "push_received",
46
+ EventType.BACKGROUND_PUSH_RECEIVED to "background_push_received",
47
+ EventType.NOTIFICATION_STATUS_CHANGED to "notification_status_changed"
48
+ )
49
+ }
50
+ override fun load() {
51
+ super.load()
52
+ Autopilot.automaticTakeOff(context.applicationContext)
53
+
54
+ scope.launch {
55
+ EventEmitter.shared().pendingEventListener.collect {
56
+ notifyPendingEvents()
57
+ }
58
+ }
59
+ UALog.i { "Airship capacitor plugin loaded." }
60
+ }
61
+
62
+ @SuppressWarnings("unused")
63
+ @PluginMethod(returnType = PluginMethod.RETURN_NONE)
64
+ override fun addListener(call: PluginCall) {
65
+ super.addListener(call)
66
+ notifyPendingEvents()
67
+ }
68
+
69
+ private fun notifyPendingEvents() {
70
+ EventType.values().forEach { eventType ->
71
+ EventEmitter.shared().processPending(listOf(eventType)) { event ->
72
+ val name = EVENT_NAME_MAP[event.type]
73
+ if (hasListeners(name)) {
74
+ notifyListeners(name, event.body.toJSObject())
75
+ true
76
+ } else {
77
+ false
78
+ }
79
+ }
80
+ }
81
+ }
82
+
83
+ @PluginMethod
84
+ @SuppressWarnings("unused")
85
+ fun perform(call: PluginCall) {
86
+ val data = JsonValue.wrap(call.data).optMap()
87
+ val method = data.opt("method").optString()
88
+ val arg = data.opt("value")
89
+
90
+ val proxy = AirshipProxy.shared(context)
91
+
92
+ when (method) {
93
+ // Airship
94
+ "takeOff" -> call.resolveResult(method) { proxy.takeOff(arg) }
95
+ "isFlying" -> call.resolveResult(method) { proxy.isFlying() }
96
+
97
+ // Channel
98
+ "channel#getChannelId" -> call.resolveResult(method) { proxy.channel.getChannelId() }
99
+
100
+ "channel#editTags" -> call.resolveResult(method) { proxy.channel.editTags(arg) }
101
+ "channel#getTags" -> call.resolveResult(method) { proxy.channel.getTags().toList() }
102
+ "channel#editTagGroups" -> call.resolveResult(method) { proxy.channel.editTagGroups(arg) }
103
+ "channel#editSubscriptionLists" -> call.resolveResult(method) { proxy.channel.editSubscriptionLists(arg) }
104
+ "channel#editAttributes" -> call.resolveResult(method) { proxy.channel.editAttributes(arg) }
105
+ "channel#getSubscriptionLists" -> call.resolvePending(method) { proxy.channel.getSubscriptionLists() }
106
+ "channel#enableChannelCreation" -> call.resolveResult(method) { proxy.channel.enableChannelCreation() }
107
+
108
+ // Contact
109
+ "contact#reset" -> call.resolveResult(method) { proxy.contact.reset() }
110
+ "contact#notifyRemoteLogin" -> call.resolveResult(method) { proxy.contact.notifyRemoteLogin() }
111
+ "contact#identify" -> call.resolveResult(method) { proxy.contact.identify(arg.requireString()) }
112
+ "contact#getNamedUserId" -> call.resolveResult(method) { proxy.contact.getNamedUserId() }
113
+ "contact#editTagGroups" -> call.resolveResult(method) { proxy.contact.editTagGroups(arg) }
114
+ "contact#editSubscriptionLists" -> call.resolveResult(method) { proxy.contact.editSubscriptionLists(arg) }
115
+ "contact#editAttributes" -> call.resolveResult(method) { proxy.contact.editAttributes(arg) }
116
+ "contact#getSubscriptionLists" -> call.resolvePending(method) { proxy.contact.getSubscriptionLists() }
117
+
118
+ // Push
119
+ "push#setUserNotificationsEnabled" -> call.resolveResult(method) { proxy.push.setUserNotificationsEnabled(arg.requireBoolean()) }
120
+ "push#enableUserNotifications" -> call.resolvePending(method) { proxy.push.enableUserPushNotifications() }
121
+ "push#isUserNotificationsEnabled" -> call.resolveResult(method) { proxy.push.isUserNotificationsEnabled() }
122
+ "push#getNotificationStatus" -> call.resolveResult(method) { proxy.push.getNotificationStatus() }
123
+ "push#getActiveNotifications" -> call.resolveResult(method) {
124
+ if (Build.VERSION.SDK_INT >= 23) {
125
+ proxy.push.getActiveNotifications()
126
+ } else {
127
+ emptyList()
128
+ }
129
+ }
130
+ "push#clearNotification" -> call.resolveResult(method) { proxy.push.clearNotification(arg.requireString()) }
131
+ "push#clearNotifications" -> call.resolveResult(method) { proxy.push.clearNotifications() }
132
+ "push#getPushToken" -> call.resolveResult(method) { proxy.push.getRegistrationToken() }
133
+ "push#android#isNotificationChannelEnabled" -> call.resolveResult(method) {
134
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
135
+ proxy.push.isNotificationChannelEnabled(arg.requireString())
136
+ } else {
137
+ true
138
+ }
139
+ }
140
+ "push#android#setNotificationConfig" -> call.resolveResult(method) { proxy.push.setNotificationConfig(arg) }
141
+ "push#android#setForegroundNotificationsEnabled" -> call.resolveResult(method) {
142
+ proxy.push.isForegroundNotificationsEnabled = arg.requireBoolean()
143
+ return@resolveResult Unit
144
+ }
145
+ "push#android#isForegroundNotificationsEnabled" -> call.resolveResult(method) {
146
+ proxy.push.isForegroundNotificationsEnabled
147
+ }
148
+
149
+ // In-App
150
+ "inApp#setPaused" -> call.resolveResult(method) { proxy.inApp.setPaused(arg.getBoolean(false)) }
151
+ "inApp#isPaused" -> call.resolveResult(method) { proxy.inApp.isPaused() }
152
+ "inApp#setDisplayInterval" -> call.resolveResult(method) { proxy.inApp.setDisplayInterval(arg.getLong(0)) }
153
+ "inApp#getDisplayInterval" -> call.resolveResult(method) { proxy.inApp.getDisplayInterval() }
154
+
155
+ // Analytics
156
+ "analytics#trackScreen" -> call.resolveResult(method) { proxy.analytics.trackScreen(arg.optString()) }
157
+ "analytics#addCustomEvent" -> call.resolveResult(method) { proxy.analytics.addEvent(arg) }
158
+ "analytics#associateIdentifier" -> {
159
+ val associatedIdentifierArgs = arg.requireStringList()
160
+ proxy.analytics.associateIdentifier(
161
+ associatedIdentifierArgs[0],
162
+ associatedIdentifierArgs.getOrNull(1)
163
+ )
164
+ }
165
+
166
+ // Message Center
167
+ "messageCenter#getMessages" -> call.resolveResult(method) {
168
+ JsonValue.wrapOpt(proxy.messageCenter.getMessages())
169
+ }
170
+ "messageCenter#dismiss" -> call.resolveResult(method) { proxy.messageCenter.dismiss() }
171
+ "messageCenter#display" -> call.resolveResult(method) { proxy.messageCenter.display(arg.optString()) }
172
+ "messageCenter#showMessageView" -> call.resolveResult(method) { proxy.messageCenter.showMessageView(arg.requireString()) }
173
+ "messageCenter#markMessageRead" -> call.resolveResult(method) { proxy.messageCenter.markMessageRead(arg.requireString()) }
174
+ "messageCenter#deleteMessage" -> call.resolveResult(method) { proxy.messageCenter.deleteMessage(arg.requireString()) }
175
+ "messageCenter#getUnreadMessageCount" -> call.resolveResult(method) { proxy.messageCenter.getUnreadMessagesCount() }
176
+ "messageCenter#setAutoLaunchDefaultMessageCenter" -> call.resolveResult(method) { proxy.messageCenter.setAutoLaunchDefaultMessageCenter(arg.requireBoolean()) }
177
+ "messageCenter#refreshMessages" -> call.resolveDeferred(method) { resolveCallback ->
178
+ proxy.messageCenter.refreshInbox().addResultCallback {
179
+ if (it == true) {
180
+ resolveCallback(null, null)
181
+ } else {
182
+ resolveCallback(null, Exception("Failed to refresh"))
183
+ }
184
+ }
185
+ }
186
+
187
+ // Preference Center
188
+ "preferenceCenter#display" -> call.resolveResult(method) { proxy.preferenceCenter.displayPreferenceCenter(arg.requireString()) }
189
+ "preferenceCenter#getConfig" -> call.resolvePending(method) { proxy.preferenceCenter.getPreferenceCenterConfig(arg.requireString()) }
190
+ "preferenceCenter#setAutoLaunchPreferenceCenter" -> call.resolveResult(method) {
191
+ val autoLaunchArgs = arg.requireList()
192
+ proxy.preferenceCenter.setAutoLaunchPreferenceCenter(
193
+ autoLaunchArgs.get(0).requireString(),
194
+ autoLaunchArgs.get(1).getBoolean(false)
195
+ )
196
+ }
197
+
198
+ // Privacy Manager
199
+ "privacyManager#setEnabledFeatures" -> call.resolveResult(method) { proxy.privacyManager.setEnabledFeatures(arg.requireStringList()) }
200
+ "privacyManager#getEnabledFeatures" -> call.resolveResult(method) { proxy.privacyManager.getFeatureNames() }
201
+ "privacyManager#enableFeatures" -> call.resolveResult(method) { proxy.privacyManager.enableFeatures(arg.requireStringList()) }
202
+ "privacyManager#disableFeatures" -> call.resolveResult(method) { proxy.privacyManager.disableFeatures(arg.requireStringList()) }
203
+ "privacyManager#isFeaturesEnabled" -> call.resolveResult(method) { proxy.privacyManager.isFeatureEnabled(arg.requireStringList()) }
204
+
205
+ // Locale
206
+ "locale#setLocaleOverride" -> call.resolveResult(method) { proxy.locale.setCurrentLocale(arg.requireString()) }
207
+ "locale#getCurrentLocale" -> call.resolveResult(method) { proxy.locale.getCurrentLocale() }
208
+ "locale#clearLocaleOverride" -> call.resolveResult(method) { proxy.locale.clearLocale() }
209
+
210
+ // Actions
211
+ "actions#run" -> call.resolveDeferred(method) { resolveCallback ->
212
+ val actionArgs = arg.requireList()
213
+ val name= actionArgs.get(0).requireString()
214
+ val value: JsonValue? = if (actionArgs.size() == 2) { actionArgs.get(1) } else { null }
215
+
216
+ proxy.actions.runAction(name, value)
217
+ .addResultCallback { actionResult ->
218
+ if (actionResult != null && actionResult.status == ActionResult.STATUS_COMPLETED) {
219
+ resolveCallback(actionResult.value, null)
220
+ } else {
221
+ resolveCallback(null, Exception("Action failed ${actionResult?.status}"))
222
+ }
223
+ }
224
+ }
225
+
226
+ // Feature Flag
227
+ "featureFlagManager#flag" -> call.resolveDeferred(method) { resolveCallback ->
228
+ scope.launch {
229
+ try {
230
+ val flag = proxy.featureFlagManager.flag(arg.requireString())
231
+ resolveCallback(flag, null)
232
+ } catch (e: Exception) {
233
+ resolveCallback(null, e)
234
+ }
235
+ }
236
+ }
237
+
238
+ "featureFlagManager#trackInteraction" -> {
239
+ call.resolveDeferred(method) { resolveCallback ->
240
+ scope.launch {
241
+ try {
242
+ val featureFlagProxy = FeatureFlagProxy(arg)
243
+ proxy.featureFlagManager.trackInteraction(flag = featureFlagProxy)
244
+ resolveCallback(null, null)
245
+ } catch (e: Exception) {
246
+ resolveCallback(null, e)
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ else -> call.reject("Not implemented")
253
+ }
254
+ }
255
+ }
256
+
257
+
258
+ internal fun PluginCall.resolveResult(method: String, function: () -> Any?) {
259
+ resolveDeferred(method) { callback -> callback(function(), null) }
260
+ }
261
+
262
+ internal fun <T> PluginCall.resolveDeferred(method: String, function: ((T?, Exception?) -> Unit) -> Unit) {
263
+ try {
264
+ function { result, error ->
265
+ if (error != null) {
266
+ this.reject(method, error)
267
+ } else {
268
+
269
+
270
+ try {
271
+ when (result) {
272
+ is Unit -> {
273
+ this.resolve(JSObject())
274
+ }
275
+ else -> {
276
+ this.resolve(jsonMapOf("value" to result).toJSObject())
277
+ }
278
+ }
279
+ } catch (e: Exception) {
280
+ this.reject(method, e)
281
+ }
282
+ }
283
+ }
284
+ } catch (e: Exception) {
285
+ this.reject(method, e)
286
+ }
287
+ }
288
+
289
+ internal fun <T> PluginCall.resolvePending(method: String, function: () -> PendingResult<T>) {
290
+ resolveDeferred(method) { callback ->
291
+ function().addResultCallback {
292
+ callback(it, null)
293
+ }
294
+ }
295
+ }
296
+
297
+ internal fun JsonValue.requireBoolean(): Boolean {
298
+ require(this.isBoolean)
299
+ return this.getBoolean(false)
300
+ }
301
+
302
+ internal fun JsonValue.requireStringList(): List<String> {
303
+ return this.requireList().list.map { it.requireString() }
304
+ }
305
+ internal fun JsonList.toJSONArray(): JSONArray {
306
+ val array = JSONArray()
307
+ this.forEach {
308
+ array.put(it.unwrap())
309
+ }
310
+ return array
311
+ }
312
+
313
+
314
+ internal fun JsonMap.toJSObject(): JSObject {
315
+ return JSObject.fromJSONObject(this.toJSONObject())
316
+ }
317
+
318
+ internal fun JsonMap.toJSONObject(): JSONObject {
319
+ return JSONObject(map.mapValues { it.value.unwrap() })
320
+ }
321
+
322
+
323
+ internal fun JsonSerializable.unwrap(): Any? {
324
+ val json = this.toJsonValue()
325
+ return when {
326
+ json.isNull -> null
327
+ json.isJsonList -> json.requireList().toJSONArray()
328
+ json.isJsonMap -> json.requireMap().toJSONObject()
329
+ else -> json.value
330
+ }
331
+ }
@@ -0,0 +1,39 @@
1
+ /* Copyright Urban Airship and Contributors */
2
+
3
+ package com.airship.capacitor
4
+
5
+ import android.content.Context
6
+ import android.util.Log
7
+ import com.getcapacitor.CapConfig
8
+ import com.urbanairship.AirshipConfigOptions
9
+ import com.urbanairship.UAirship
10
+ import com.urbanairship.analytics.Analytics
11
+ import com.urbanairship.android.framework.proxy.BaseAutopilot
12
+ import com.urbanairship.android.framework.proxy.ProxyConfig
13
+ import com.urbanairship.android.framework.proxy.ProxyStore
14
+ import com.urbanairship.android.framework.proxy.applyProxyConfig
15
+ import com.urbanairship.json.JsonValue
16
+
17
+ class CapacitorAutopilot : BaseAutopilot() {
18
+
19
+ override fun onAirshipReady(airship: UAirship) {
20
+ super.onAirshipReady(airship)
21
+
22
+ Log.i("CapacitorAutopilot", "onAirshipReady")
23
+
24
+ // TODO capacitor
25
+ airship.analytics.registerSDKExtension(Analytics.EXTENSION_CORDOVA, AirshipCapacitorVersion.version)
26
+ }
27
+
28
+ override fun createConfigBuilder(context: Context): AirshipConfigOptions.Builder {
29
+ val pluginConfig = CapConfig.loadDefault(context).getPluginConfiguration("Airship")
30
+ val proxyConfig = ProxyConfig(JsonValue.wrapOpt(pluginConfig.getObject("config")).optMap())
31
+ val builder = AirshipConfigOptions.newBuilder().applyDefaultProperties(context)
32
+ builder.applyProxyConfig(context, proxyConfig)
33
+ return builder
34
+ }
35
+
36
+ override fun onMigrateData(context: Context, proxyStore: ProxyStore) {
37
+
38
+ }
39
+ }
File without changes
@@ -0,0 +1,18 @@
1
+ import type { AirshipPluginWrapper } from './AirshipPlugin';
2
+ import type { JsonValue } from './types';
3
+ /**
4
+ * Airship actions.
5
+ */
6
+ export declare class AirshipActions {
7
+ private readonly plugin;
8
+ constructor(plugin: AirshipPluginWrapper);
9
+ /**
10
+ * Runs an Airship action.
11
+ *
12
+ * @param name The name of the action.
13
+ * @param value The action's value.
14
+ * @return A promise that returns the action result if the action
15
+ * successfully runs, or the Error if the action was unable to be run.
16
+ */
17
+ run(actionName: string, actionValue?: JsonValue): Promise<JsonValue | null | undefined>;
18
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Airship actions.
3
+ */
4
+ export class AirshipActions {
5
+ constructor(plugin) {
6
+ this.plugin = plugin;
7
+ }
8
+ /**
9
+ * Runs an Airship action.
10
+ *
11
+ * @param name The name of the action.
12
+ * @param value The action's value.
13
+ * @return A promise that returns the action result if the action
14
+ * successfully runs, or the Error if the action was unable to be run.
15
+ */
16
+ run(actionName, actionValue) {
17
+ return this.plugin.perform('actions#run', [actionName, actionValue]);
18
+ }
19
+ }
20
+ //# sourceMappingURL=AirshipActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AirshipActions.js","sourceRoot":"","sources":["../../src/AirshipActions.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,cAAc;IACzB,YAA6B,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;IAAG,CAAC;IAE7D;;;;;;;OAOG;IACI,GAAG,CACR,UAAkB,EAClB,WAAuB;QAEvB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IACvE,CAAC;CACF","sourcesContent":["import type { AirshipPluginWrapper } from './AirshipPlugin';\nimport type { JsonValue } from './types';\n\n/**\n * Airship actions.\n */\nexport class AirshipActions {\n constructor(private readonly plugin: AirshipPluginWrapper) {}\n\n /**\n * Runs an Airship action.\n *\n * @param name The name of the action.\n * @param value The action's value.\n * @return A promise that returns the action result if the action\n * successfully runs, or the Error if the action was unable to be run.\n */\n public run(\n actionName: string,\n actionValue?: JsonValue,\n ): Promise<JsonValue | null | undefined> {\n return this.plugin.perform('actions#run', [actionName, actionValue]);\n }\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import type { AirshipPluginWrapper } from './AirshipPlugin';
2
+ import type { CustomEvent } from './types';
3
+ /**
4
+ * Airship analytics.
5
+ */
6
+ export declare class AirshipAnalytics {
7
+ private readonly plugin;
8
+ constructor(plugin: AirshipPluginWrapper);
9
+ /**
10
+ * Associates an identifier.
11
+ *
12
+ * @param key The key.
13
+ * @param identifier The identifier. `null` to remove.
14
+ * @returns A promise.
15
+ */
16
+ associateIdentifier(key: string, identifier?: string): Promise<void>;
17
+ /**
18
+ * Tracks a screen.
19
+ * @param screen The screen. `null` to stop tracking.
20
+ * @returns A promise.
21
+ */
22
+ trackScreen(screen?: string): Promise<void>;
23
+ /**
24
+ * Adds a custom event.
25
+ * @param event The custom event.
26
+ * @return A promise that returns null if resolved, or an Error if the
27
+ * custom event is rejected.
28
+ */
29
+ addCustomEvent(event: CustomEvent): Promise<void>;
30
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Airship analytics.
3
+ */
4
+ export class AirshipAnalytics {
5
+ constructor(plugin) {
6
+ this.plugin = plugin;
7
+ }
8
+ /**
9
+ * Associates an identifier.
10
+ *
11
+ * @param key The key.
12
+ * @param identifier The identifier. `null` to remove.
13
+ * @returns A promise.
14
+ */
15
+ associateIdentifier(key, identifier) {
16
+ return this.plugin.perform('analytics#associateIdentifier', [
17
+ key,
18
+ identifier,
19
+ ]);
20
+ }
21
+ /**
22
+ * Tracks a screen.
23
+ * @param screen The screen. `null` to stop tracking.
24
+ * @returns A promise.
25
+ */
26
+ trackScreen(screen) {
27
+ return this.plugin.perform('analytics#trackScreen', screen);
28
+ }
29
+ /**
30
+ * Adds a custom event.
31
+ * @param event The custom event.
32
+ * @return A promise that returns null if resolved, or an Error if the
33
+ * custom event is rejected.
34
+ */
35
+ addCustomEvent(event) {
36
+ return this.plugin.perform('analytics#addCustomEvent', event);
37
+ }
38
+ }
39
+ //# sourceMappingURL=AirshipAnalytics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AirshipAnalytics.js","sourceRoot":"","sources":["../../src/AirshipAnalytics.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC3B,YAA6B,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;IAAG,CAAC;IAE7D;;;;;;OAMG;IACI,mBAAmB,CAAC,GAAW,EAAE,UAAmB;QACzD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,+BAA+B,EAAE;YAC1D,GAAG;YACH,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,MAAe;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,KAAkB;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import type { AirshipPluginWrapper } from './AirshipPlugin';\nimport type { CustomEvent } from './types';\n\n/**\n * Airship analytics.\n */\nexport class AirshipAnalytics {\n constructor(private readonly plugin: AirshipPluginWrapper) {}\n\n /**\n * Associates an identifier.\n *\n * @param key The key.\n * @param identifier The identifier. `null` to remove.\n * @returns A promise.\n */\n public associateIdentifier(key: string, identifier?: string): Promise<void> {\n return this.plugin.perform('analytics#associateIdentifier', [\n key,\n identifier,\n ]);\n }\n\n /**\n * Tracks a screen.\n * @param screen The screen. `null` to stop tracking.\n * @returns A promise.\n */\n public trackScreen(screen?: string): Promise<void> {\n return this.plugin.perform('analytics#trackScreen', screen);\n }\n\n /**\n * Adds a custom event.\n * @param event The custom event.\n * @return A promise that returns null if resolved, or an Error if the\n * custom event is rejected.\n */\n public addCustomEvent(event: CustomEvent): Promise<void> {\n return this.plugin.perform('analytics#addCustomEvent', event);\n }\n}\n"]}