expo-notifications 0.16.0 → 0.17.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 (32) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/AndroidManifest.xml +1 -0
  4. package/android/src/main/java/expo/modules/notifications/permissions/NotificationPermissionsModule.kt +144 -0
  5. package/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt +1 -1
  6. package/build/NotificationPermissions.d.ts +1 -1
  7. package/build/NotificationPermissions.js +1 -1
  8. package/build/NotificationPermissions.js.map +1 -1
  9. package/build/getDevicePushTokenAsync.web.js +3 -11
  10. package/build/getDevicePushTokenAsync.web.js.map +1 -1
  11. package/build/getExpoPushTokenAsync.d.ts.map +1 -1
  12. package/build/getExpoPushTokenAsync.js +1 -4
  13. package/build/getExpoPushTokenAsync.js.map +1 -1
  14. package/ios/EXNotifications.podspec +1 -1
  15. package/ios/EXNotifications.xcframework/ios-arm64/EXNotifications.framework/EXNotifications +0 -0
  16. package/ios/EXNotifications.xcframework/ios-arm64/EXNotifications.framework/Info.plist +0 -0
  17. package/ios/EXNotifications.xcframework/ios-arm64_x86_64-simulator/EXNotifications.framework/EXNotifications +0 -0
  18. package/ios/EXNotifications.xcframework/ios-arm64_x86_64-simulator/EXNotifications.framework/Info.plist +0 -0
  19. package/package.json +5 -6
  20. package/plugin/build/withNotifications.d.ts +1 -1
  21. package/plugin/build/withNotifications.js +1 -1
  22. package/plugin/build/withNotificationsAndroid.d.ts +2 -2
  23. package/plugin/build/withNotificationsAndroid.js +3 -5
  24. package/plugin/build/withNotificationsIOS.d.ts +1 -1
  25. package/plugin/build/withNotificationsIOS.js +1 -1
  26. package/plugin/src/withNotifications.ts +1 -1
  27. package/plugin/src/withNotificationsAndroid.ts +3 -3
  28. package/plugin/src/withNotificationsIOS.ts +1 -1
  29. package/src/NotificationPermissions.ts +1 -1
  30. package/src/getDevicePushTokenAsync.web.ts +5 -15
  31. package/src/getExpoPushTokenAsync.ts +1 -4
  32. package/android/src/main/java/expo/modules/notifications/permissions/NotificationPermissionsModule.java +0 -74
package/CHANGELOG.md CHANGED
@@ -10,6 +10,27 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 0.17.0 — 2022-10-25
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - [plugin] Upgrade minimum runtime requirement to Node 14 (LTS). ([#18204](https://github.com/expo/expo/pull/18204) by [@EvanBacon](https://github.com/EvanBacon))
18
+ - Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
19
+
20
+ ### 🐛 Bug fixes
21
+
22
+ - Fixed build error for setting `compileSdkVersion` to 33. ([#19432](https://github.com/expo/expo/pull/19432) by [@kudo](https://github.com/kudo))
23
+ - Fixed the `POST_NOTIFICATIONS` runtime permission integration when `targerSdkVersion` is set to 33. ([#19672](https://github.com/expo/expo/pull/19672) by [@kudo](https://github.com/kudo), [@kudo](https://github.com/kudo))
24
+
25
+ ### 💡 Others
26
+
27
+ - [plugin] Migrate import from @expo/config-plugins to expo/config-plugins and @expo/config-types to expo/config. ([#18855](https://github.com/expo/expo/pull/18855) by [@brentvatne](https://github.com/brentvatne))
28
+ - Drop `@expo/config-plugins` dependency in favor of peer dependency on `expo`. ([#18595](https://github.com/expo/expo/pull/18595) by [@EvanBacon](https://github.com/EvanBacon))
29
+
30
+ ## 0.16.1 — 2022-07-16
31
+
32
+ _This version does not introduce any user-facing changes._
33
+
13
34
  ## 0.16.0 — 2022-07-07
14
35
 
15
36
  ### 🛠 Breaking changes
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '0.16.0'
6
+ version = '0.17.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -74,7 +74,7 @@ android {
74
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
75
  targetSdkVersion safeExtGet("targetSdkVersion", 31)
76
76
  versionCode 21
77
- versionName '0.16.0'
77
+ versionName '0.17.0'
78
78
  }
79
79
 
80
80
  lintOptions {
@@ -2,6 +2,7 @@
2
2
  package="expo.modules.notifications">
3
3
 
4
4
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
5
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
5
6
 
6
7
  <application>
7
8
  <service
@@ -0,0 +1,144 @@
1
+ package expo.modules.notifications.permissions
2
+
3
+ import android.app.NotificationManager
4
+ import android.content.Context
5
+ import android.os.Build
6
+ import androidx.annotation.RequiresApi
7
+ import androidx.core.app.NotificationManagerCompat
8
+ import androidx.core.os.bundleOf
9
+ import expo.modules.core.ExportedModule
10
+ import expo.modules.core.ModuleRegistry
11
+ import expo.modules.core.Promise
12
+ import expo.modules.core.arguments.ReadableArguments
13
+ import expo.modules.core.interfaces.ExpoMethod
14
+ import expo.modules.interfaces.permissions.Permissions
15
+ import expo.modules.interfaces.permissions.PermissionsResponse
16
+ import expo.modules.interfaces.permissions.PermissionsStatus
17
+
18
+ class NotificationPermissionsModule(context: Context?) : ExportedModule(context) {
19
+ private lateinit var moduleRegistry: ModuleRegistry
20
+
21
+ override fun onCreate(moduleRegistry: ModuleRegistry) {
22
+ this.moduleRegistry = moduleRegistry
23
+ }
24
+
25
+ override fun getName(): String {
26
+ return EXPORTED_NAME
27
+ }
28
+
29
+ @ExpoMethod
30
+ fun getPermissionsAsync(promise: Promise) {
31
+ if (context.applicationContext.applicationInfo.targetSdkVersion >= 33 && Build.VERSION.SDK_INT >= 33) {
32
+ getPermissionsWithPromiseImplApi33(promise)
33
+ } else {
34
+ getPermissionsWithPromiseImplClassic(promise)
35
+ }
36
+ }
37
+
38
+ @ExpoMethod
39
+ fun requestPermissionsAsync(permissionsTypes: ReadableArguments?, promise: Promise) {
40
+ if (context.applicationContext.applicationInfo.targetSdkVersion >= 33 && Build.VERSION.SDK_INT >= 33) {
41
+ requestPermissionsWithPromiseImplApi33(promise)
42
+ } else {
43
+ getPermissionsWithPromiseImplClassic(promise)
44
+ }
45
+ }
46
+
47
+ @RequiresApi(33)
48
+ private fun getPermissionsWithPromiseImplApi33(promise: Promise) {
49
+ val permissionManager = moduleRegistry.getModule(Permissions::class.java)
50
+ if (permissionManager == null) {
51
+ promise.reject("E_NO_PERMISSIONS", "Permissions module is null. Are you sure all the installed Expo modules are properly linked?")
52
+ return
53
+ }
54
+
55
+ permissionManager.getPermissions(
56
+ { permissionsMap: Map<String, PermissionsResponse> ->
57
+ val managerCompat = NotificationManagerCompat.from(context)
58
+ val areEnabled = managerCompat.areNotificationsEnabled()
59
+ val platformBundle = bundleOf(
60
+ IMPORTANCE_KEY to managerCompat.importance,
61
+ ).apply {
62
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
63
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && notificationManager != null) {
64
+ putInt(INTERRUPTION_FILTER_KEY, notificationManager.currentInterruptionFilter)
65
+ }
66
+ }
67
+
68
+ val areAllGranted = permissionsMap.all { (_, response) -> response.status == PermissionsStatus.GRANTED }
69
+ val areAllDenied = permissionsMap.all { (_, response) -> response.status == PermissionsStatus.DENIED }
70
+ val canAskAgain = permissionsMap.all { (_, response) -> response.canAskAgain }
71
+ val status = when {
72
+ areAllDenied -> PermissionsStatus.DENIED.status
73
+ !areEnabled -> PermissionsStatus.DENIED.status
74
+ areAllGranted -> PermissionsStatus.GRANTED.status
75
+ else -> PermissionsStatus.UNDETERMINED.status
76
+ }
77
+
78
+ promise.resolve(
79
+ bundleOf(
80
+ PermissionsResponse.EXPIRES_KEY to PermissionsResponse.PERMISSION_EXPIRES_NEVER,
81
+ PermissionsResponse.STATUS_KEY to status,
82
+ PermissionsResponse.CAN_ASK_AGAIN_KEY to canAskAgain,
83
+ PermissionsResponse.GRANTED_KEY to areAllGranted,
84
+ ANDROID_RESPONSE_KEY to platformBundle,
85
+ )
86
+ )
87
+ },
88
+ *PERMISSIONS
89
+ )
90
+ }
91
+
92
+ private fun getPermissionsWithPromiseImplClassic(promise: Promise) {
93
+ val managerCompat = NotificationManagerCompat.from(context)
94
+ val areEnabled = managerCompat.areNotificationsEnabled()
95
+ val status = if (areEnabled) PermissionsStatus.GRANTED else PermissionsStatus.DENIED
96
+ val platformBundle = bundleOf(
97
+ IMPORTANCE_KEY to managerCompat.importance,
98
+ ).apply {
99
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
100
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && notificationManager != null) {
101
+ putInt(INTERRUPTION_FILTER_KEY, notificationManager.currentInterruptionFilter)
102
+ }
103
+ }
104
+
105
+ promise.resolve(
106
+ bundleOf(
107
+ PermissionsResponse.EXPIRES_KEY to PermissionsResponse.PERMISSION_EXPIRES_NEVER,
108
+ PermissionsResponse.STATUS_KEY to status.status,
109
+ PermissionsResponse.CAN_ASK_AGAIN_KEY to areEnabled,
110
+ PermissionsResponse.GRANTED_KEY to (status == PermissionsStatus.GRANTED),
111
+ ANDROID_RESPONSE_KEY to platformBundle,
112
+ )
113
+ )
114
+ }
115
+
116
+ @RequiresApi(33)
117
+ private fun requestPermissionsWithPromiseImplApi33(promise: Promise) {
118
+ val permissionManager = moduleRegistry.getModule(Permissions::class.java)
119
+ if (permissionManager == null) {
120
+ promise.reject("E_NO_PERMISSIONS", "Permissions module is null. Are you sure all the installed Expo modules are properly linked?")
121
+ return
122
+ }
123
+
124
+ permissionManager.askForPermissions(
125
+ {
126
+ getPermissionsWithPromiseImplApi33(promise)
127
+ },
128
+ *PERMISSIONS
129
+ )
130
+ }
131
+
132
+ companion object {
133
+ private const val EXPORTED_NAME = "ExpoNotificationPermissionsModule"
134
+ private const val ANDROID_RESPONSE_KEY = "android"
135
+ private const val IMPORTANCE_KEY = "importance"
136
+ private const val INTERRUPTION_FILTER_KEY = "interruptionFilter"
137
+
138
+ private val PERMISSIONS: Array<String>
139
+ /**
140
+ * TODO: Use {@link Android.Manifest.permission.POST_NOTIFICATIONS} when we support compileSdkVersion 33
141
+ */
142
+ get() = arrayOf("android.permission.POST_NOTIFICATIONS")
143
+ }
144
+ }
@@ -502,7 +502,7 @@ open class NotificationsService : BroadcastReceiver() {
502
502
  val notification = intent.getParcelableExtra<Notification>(NOTIFICATION_KEY) ?: throw IllegalArgumentException("$NOTIFICATION_KEY not found in the intent extras.")
503
503
  val action = intent.getParcelableExtra<NotificationAction>(NOTIFICATION_ACTION_KEY) ?: throw IllegalArgumentException("$NOTIFICATION_ACTION_KEY not found in the intent extras.")
504
504
  val response = if (action is TextInputNotificationAction) {
505
- val userText = action.placeholder ?: RemoteInput.getResultsFromIntent(intent).getString(USER_TEXT_RESPONSE_KEY)
505
+ val userText = action.placeholder ?: RemoteInput.getResultsFromIntent(intent)?.getString(USER_TEXT_RESPONSE_KEY) ?: ""
506
506
  TextInputNotificationResponse(action, notification, userText)
507
507
  } else {
508
508
  NotificationResponse(action, notification)
@@ -7,7 +7,7 @@ export declare function requestPermissionsAsync(permissions?: NotificationPermis
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
- * const [status, requestPermission] = Notifications.usePermissions();
10
+ * const [permissionResponse, requestPermission] = Notifications.usePermissions();
11
11
  * ```
12
12
  */
13
13
  export declare const usePermissions: (options?: import("expo-modules-core").PermissionHookOptions<NotificationPermissionsRequest> | undefined) => [NotificationPermissionsStatus | null, () => Promise<NotificationPermissionsStatus>, () => Promise<NotificationPermissionsStatus>];
@@ -27,7 +27,7 @@ export async function requestPermissionsAsync(permissions) {
27
27
  *
28
28
  * @example
29
29
  * ```ts
30
- * const [status, requestPermission] = Notifications.usePermissions();
30
+ * const [permissionResponse, requestPermission] = Notifications.usePermissions();
31
31
  * ```
32
32
  */
33
33
  export const usePermissions = createPermissionHook({
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationPermissions.js","sourceRoot":"","sources":["../src/NotificationPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMxF,OAAO,6BAA6B,MAAM,iCAAiC,CAAC;AAE5E,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,IAAI,CAAC,6BAA6B,CAAC,mBAAmB,EAAE;QACtD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;KACvE;IAED,OAAO,MAAM,6BAA6B,CAAC,mBAAmB,EAAE,CAAC;AACnE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,WAA4C;IACxF,IAAI,CAAC,6BAA6B,CAAC,uBAAuB,EAAE;QAC1D,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC;KAC3E;IAED,MAAM,oBAAoB,GAAG,WAAW,IAAI;QAC1C,GAAG,EAAE;YACH,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;SACjB;KACF,CAAC;IACF,MAAM,4BAA4B,GAAG,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,OAAO,MAAM,6BAA6B,CAAC,uBAAuB,CAAC,4BAA4B,CAAC,CAAC;AACnG,CAAC;AAED,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAGhD;IACA,aAAa,EAAE,uBAAuB;IACtC,SAAS,EAAE,mBAAmB;CAC/B,CAAC,CAAC","sourcesContent":["import { createPermissionHook, Platform, UnavailabilityError } from 'expo-modules-core';\n\nimport {\n NotificationPermissionsRequest,\n NotificationPermissionsStatus,\n} from './NotificationPermissions.types';\nimport NotificationPermissionsModule from './NotificationPermissionsModule';\n\nexport async function getPermissionsAsync() {\n if (!NotificationPermissionsModule.getPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'getPermissionsAsync');\n }\n\n return await NotificationPermissionsModule.getPermissionsAsync();\n}\n\nexport async function requestPermissionsAsync(permissions?: NotificationPermissionsRequest) {\n if (!NotificationPermissionsModule.requestPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'requestPermissionsAsync');\n }\n\n const requestedPermissions = permissions ?? {\n ios: {\n allowAlert: true,\n allowBadge: true,\n allowSound: true,\n },\n };\n const requestedPlatformPermissions = requestedPermissions[Platform.OS];\n return await NotificationPermissionsModule.requestPermissionsAsync(requestedPlatformPermissions);\n}\n\n// @needsAudit\n/**\n * Check or request permissions to send and receive push notifications.\n * This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = Notifications.usePermissions();\n * ```\n */\nexport const usePermissions = createPermissionHook<\n NotificationPermissionsStatus,\n NotificationPermissionsRequest\n>({\n requestMethod: requestPermissionsAsync,\n getMethod: getPermissionsAsync,\n});\n"]}
1
+ {"version":3,"file":"NotificationPermissions.js","sourceRoot":"","sources":["../src/NotificationPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMxF,OAAO,6BAA6B,MAAM,iCAAiC,CAAC;AAE5E,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,IAAI,CAAC,6BAA6B,CAAC,mBAAmB,EAAE;QACtD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC;KACvE;IAED,OAAO,MAAM,6BAA6B,CAAC,mBAAmB,EAAE,CAAC;AACnE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,WAA4C;IACxF,IAAI,CAAC,6BAA6B,CAAC,uBAAuB,EAAE;QAC1D,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC;KAC3E;IAED,MAAM,oBAAoB,GAAG,WAAW,IAAI;QAC1C,GAAG,EAAE;YACH,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI;SACjB;KACF,CAAC;IACF,MAAM,4BAA4B,GAAG,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,OAAO,MAAM,6BAA6B,CAAC,uBAAuB,CAAC,4BAA4B,CAAC,CAAC;AACnG,CAAC;AAED,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAGhD;IACA,aAAa,EAAE,uBAAuB;IACtC,SAAS,EAAE,mBAAmB;CAC/B,CAAC,CAAC","sourcesContent":["import { createPermissionHook, Platform, UnavailabilityError } from 'expo-modules-core';\n\nimport {\n NotificationPermissionsRequest,\n NotificationPermissionsStatus,\n} from './NotificationPermissions.types';\nimport NotificationPermissionsModule from './NotificationPermissionsModule';\n\nexport async function getPermissionsAsync() {\n if (!NotificationPermissionsModule.getPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'getPermissionsAsync');\n }\n\n return await NotificationPermissionsModule.getPermissionsAsync();\n}\n\nexport async function requestPermissionsAsync(permissions?: NotificationPermissionsRequest) {\n if (!NotificationPermissionsModule.requestPermissionsAsync) {\n throw new UnavailabilityError('Notifications', 'requestPermissionsAsync');\n }\n\n const requestedPermissions = permissions ?? {\n ios: {\n allowAlert: true,\n allowBadge: true,\n allowSound: true,\n },\n };\n const requestedPlatformPermissions = requestedPermissions[Platform.OS];\n return await NotificationPermissionsModule.requestPermissionsAsync(requestedPlatformPermissions);\n}\n\n// @needsAudit\n/**\n * Check or request permissions to send and receive push notifications.\n * This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [permissionResponse, requestPermission] = Notifications.usePermissions();\n * ```\n */\nexport const usePermissions = createPermissionHook<\n NotificationPermissionsStatus,\n NotificationPermissionsRequest\n>({\n requestMethod: requestPermissionsAsync,\n getMethod: getPermissionsAsync,\n});\n"]}
@@ -17,19 +17,13 @@ function guardPermission() {
17
17
  }
18
18
  }
19
19
  async function _subscribeDeviceToPushNotificationsAsync() {
20
- const vapidPublicKey =
21
20
  // @ts-expect-error: TODO: not on the schema
22
- Constants.manifest?.notification?.vapidPublicKey ??
23
- // @ts-expect-error: TODO: not on the schema
24
- Constants.manifest2?.extra?.expoClient?.notification?.vapidPublicKey;
21
+ const vapidPublicKey = Constants.expoConfig?.notification?.vapidPublicKey;
25
22
  if (!vapidPublicKey) {
26
23
  throw new CodedError('ERR_NOTIFICATIONS_PUSH_WEB_MISSING_CONFIG', 'You must provide `notification.vapidPublicKey` in `app.json` to use push notifications on web. Learn more: https://docs.expo.dev/versions/latest/guides/using-vapid/.');
27
24
  }
28
- const serviceWorkerPath =
29
25
  // @ts-expect-error: TODO: not on the schema
30
- Constants.manifest?.notification.serviceWorkerPath ??
31
- // @ts-expect-error: TODO: not on the schema
32
- Constants.manifest2?.extra?.expoClient?.notification?.serviceWorkerPath;
26
+ const serviceWorkerPath = Constants.expoConfig?.notification?.serviceWorkerPath;
33
27
  if (!serviceWorkerPath) {
34
28
  throw new CodedError('ERR_NOTIFICATIONS_PUSH_MISSING_CONFIGURATION', 'You must specify `notification.serviceWorkerPath` in `app.json` to use push notifications on the web. Please provide the path to the service worker that will handle notifications.');
35
29
  }
@@ -71,9 +65,7 @@ async function _subscribeDeviceToPushNotificationsAsync() {
71
65
  // We wrap it with `fromExpoWebClient` to make sure other message
72
66
  // will not override content such as `notificationIcon`.
73
67
  // https://stackoverflow.com/a/35729334/2603230
74
- const notificationIcon = (Constants.manifest?.notification ??
75
- Constants.manifest2?.extra?.expoClient?.notification ??
76
- {}).icon;
68
+ const notificationIcon = (Constants.expoConfig?.notification ?? {}).icon;
77
69
  await registration.active.postMessage(JSON.stringify({ fromExpoWebClient: { notificationIcon } }));
78
70
  return subscriptionObject;
79
71
  }
@@ -1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 'expo-modules-core';\n\nimport { DevicePushToken } from './Tokens.types';\n\nexport default async function getDevicePushTokenAsync(): Promise<DevicePushToken> {\n const data = await _subscribeDeviceToPushNotificationsAsync();\n SyntheticPlatformEmitter.emit('onDevicePushToken', { devicePushToken: data });\n return { type: Platform.OS, data };\n}\n\nfunction guardPermission() {\n if (!('Notification' in window)) {\n throw new CodedError(\n 'ERR_UNAVAILABLE',\n 'The Web Notifications API is not available on this device.'\n );\n }\n if (!navigator.serviceWorker) {\n throw new CodedError(\n 'ERR_UNAVAILABLE',\n 'Notifications cannot be used because the service worker API is not supported on this device. This might also happen because your web page does not support HTTPS.'\n );\n }\n if (Notification.permission !== 'granted') {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PERMISSION_DENIED',\n `Cannot use web notifications without permissions granted. Request permissions with \"expo-permissions\".`\n );\n }\n}\n\nasync function _subscribeDeviceToPushNotificationsAsync(): Promise<DevicePushToken['data']> {\n const vapidPublicKey: string | null =\n // @ts-expect-error: TODO: not on the schema\n Constants.manifest?.notification?.vapidPublicKey ??\n // @ts-expect-error: TODO: not on the schema\n Constants.manifest2?.extra?.expoClient?.notification?.vapidPublicKey;\n if (!vapidPublicKey) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_WEB_MISSING_CONFIG',\n 'You must provide `notification.vapidPublicKey` in `app.json` to use push notifications on web. Learn more: https://docs.expo.dev/versions/latest/guides/using-vapid/.'\n );\n }\n\n const serviceWorkerPath =\n // @ts-expect-error: TODO: not on the schema\n Constants.manifest?.notification.serviceWorkerPath ??\n // @ts-expect-error: TODO: not on the schema\n Constants.manifest2?.extra?.expoClient?.notification?.serviceWorkerPath;\n if (!serviceWorkerPath) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_MISSING_CONFIGURATION',\n 'You must specify `notification.serviceWorkerPath` in `app.json` to use push notifications on the web. Please provide the path to the service worker that will handle notifications.'\n );\n }\n guardPermission();\n\n let registration: ServiceWorkerRegistration | null = null;\n try {\n registration = await navigator.serviceWorker.register(serviceWorkerPath);\n } catch (error) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_REGISTRATION_FAILED',\n `Could not register this device for push notifications because the service worker (${serviceWorkerPath}) could not be registered: ${error}`\n );\n }\n await navigator.serviceWorker.ready;\n\n if (!registration.active) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_REGISTRATION_FAILED',\n 'Could not register this device for push notifications because the service worker is not active.'\n );\n }\n\n const subscribeOptions = {\n userVisibleOnly: true,\n applicationServerKey: _urlBase64ToUint8Array(vapidPublicKey),\n };\n let pushSubscription: PushSubscription | null = null;\n try {\n pushSubscription = await registration.pushManager.subscribe(subscribeOptions);\n } catch (error) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_REGISTRATION_FAILED',\n 'The device was unable to register for remote notifications with the browser endpoint. (' +\n error +\n ')'\n );\n }\n const pushSubscriptionJson = pushSubscription.toJSON();\n\n const subscriptionObject = {\n endpoint: pushSubscriptionJson.endpoint,\n keys: {\n p256dh: pushSubscriptionJson.keys!.p256dh,\n auth: pushSubscriptionJson.keys!.auth,\n },\n };\n\n // Store notification icon string in service worker.\n // This message is received by `/expo-service-worker.js`.\n // We wrap it with `fromExpoWebClient` to make sure other message\n // will not override content such as `notificationIcon`.\n // https://stackoverflow.com/a/35729334/2603230\n const notificationIcon = (\n Constants.manifest?.notification ??\n Constants.manifest2?.extra?.expoClient?.notification ??\n {}\n ).icon;\n await registration.active.postMessage(\n JSON.stringify({ fromExpoWebClient: { notificationIcon } })\n );\n\n return subscriptionObject;\n}\n\n// https://github.com/web-push-libs/web-push#using-vapid-key-for-applicationserverkey\nfunction _urlBase64ToUint8Array(base64String: string): Uint8Array {\n const padding = '='.repeat((4 - (base64String.length % 4)) % 4);\n const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');\n\n const rawData = window.atob(base64);\n const outputArray = new Uint8Array(rawData.length);\n\n for (let i = 0; i < rawData.length; ++i) {\n outputArray[i] = rawData.charCodeAt(i);\n }\n return outputArray;\n}\n"]}
1
+ {"version":3,"file":"getDevicePushTokenAsync.web.js","sourceRoot":"","sources":["../src/getDevicePushTokenAsync.web.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAInF,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,uBAAuB;IACnD,MAAM,IAAI,GAAG,MAAM,wCAAwC,EAAE,CAAC;IAC9D,wBAAwB,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9E,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC;AACrC,CAAC;AAED,SAAS,eAAe;IACtB,IAAI,CAAC,CAAC,cAAc,IAAI,MAAM,CAAC,EAAE;QAC/B,MAAM,IAAI,UAAU,CAClB,iBAAiB,EACjB,4DAA4D,CAC7D,CAAC;KACH;IACD,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;QAC5B,MAAM,IAAI,UAAU,CAClB,iBAAiB,EACjB,mKAAmK,CACpK,CAAC;KACH;IACD,IAAI,YAAY,CAAC,UAAU,KAAK,SAAS,EAAE;QACzC,MAAM,IAAI,UAAU,CAClB,qCAAqC,EACrC,wGAAwG,CACzG,CAAC;KACH;AACH,CAAC;AAED,KAAK,UAAU,wCAAwC;IACrD,4CAA4C;IAC5C,MAAM,cAAc,GAAkB,SAAS,CAAC,UAAU,EAAE,YAAY,EAAE,cAAc,CAAC;IACzF,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,IAAI,UAAU,CAClB,2CAA2C,EAC3C,uKAAuK,CACxK,CAAC;KACH;IAED,4CAA4C;IAC5C,MAAM,iBAAiB,GAAG,SAAS,CAAC,UAAU,EAAE,YAAY,EAAE,iBAAiB,CAAC;IAChF,IAAI,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A+C;IAC/C,MAAM,gBAAgB,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,YAAY,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACzE,MAAM,YAAY,CAAC,MAAM,CAAC,WAAW,CACnC,IAAI,CAAC,SAAS,CAAC,EAAE,iBAAiB,EAAE,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAC5D,CAAC;IAEF,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,qFAAqF;AACrF,SAAS,sBAAsB,CAAC,YAAoB;IAClD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,CAAC,YAAY,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAE9E,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACvC,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KACxC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import Constants from 'expo-constants';\nimport { CodedError, Platform, SyntheticPlatformEmitter } from 'expo-modules-core';\n\nimport { DevicePushToken } from './Tokens.types';\n\nexport default async function getDevicePushTokenAsync(): Promise<DevicePushToken> {\n const data = await _subscribeDeviceToPushNotificationsAsync();\n SyntheticPlatformEmitter.emit('onDevicePushToken', { devicePushToken: data });\n return { type: Platform.OS, data };\n}\n\nfunction guardPermission() {\n if (!('Notification' in window)) {\n throw new CodedError(\n 'ERR_UNAVAILABLE',\n 'The Web Notifications API is not available on this device.'\n );\n }\n if (!navigator.serviceWorker) {\n throw new CodedError(\n 'ERR_UNAVAILABLE',\n 'Notifications cannot be used because the service worker API is not supported on this device. This might also happen because your web page does not support HTTPS.'\n );\n }\n if (Notification.permission !== 'granted') {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PERMISSION_DENIED',\n `Cannot use web notifications without permissions granted. Request permissions with \"expo-permissions\".`\n );\n }\n}\n\nasync function _subscribeDeviceToPushNotificationsAsync(): Promise<DevicePushToken['data']> {\n // @ts-expect-error: TODO: not on the schema\n const vapidPublicKey: string | null = Constants.expoConfig?.notification?.vapidPublicKey;\n if (!vapidPublicKey) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_WEB_MISSING_CONFIG',\n 'You must provide `notification.vapidPublicKey` in `app.json` to use push notifications on web. Learn more: https://docs.expo.dev/versions/latest/guides/using-vapid/.'\n );\n }\n\n // @ts-expect-error: TODO: not on the schema\n const serviceWorkerPath = Constants.expoConfig?.notification?.serviceWorkerPath;\n if (!serviceWorkerPath) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_MISSING_CONFIGURATION',\n 'You must specify `notification.serviceWorkerPath` in `app.json` to use push notifications on the web. Please provide the path to the service worker that will handle notifications.'\n );\n }\n guardPermission();\n\n let registration: ServiceWorkerRegistration | null = null;\n try {\n registration = await navigator.serviceWorker.register(serviceWorkerPath);\n } catch (error) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_REGISTRATION_FAILED',\n `Could not register this device for push notifications because the service worker (${serviceWorkerPath}) could not be registered: ${error}`\n );\n }\n await navigator.serviceWorker.ready;\n\n if (!registration.active) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_REGISTRATION_FAILED',\n 'Could not register this device for push notifications because the service worker is not active.'\n );\n }\n\n const subscribeOptions = {\n userVisibleOnly: true,\n applicationServerKey: _urlBase64ToUint8Array(vapidPublicKey),\n };\n let pushSubscription: PushSubscription | null = null;\n try {\n pushSubscription = await registration.pushManager.subscribe(subscribeOptions);\n } catch (error) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_PUSH_REGISTRATION_FAILED',\n 'The device was unable to register for remote notifications with the browser endpoint. (' +\n error +\n ')'\n );\n }\n const pushSubscriptionJson = pushSubscription.toJSON();\n\n const subscriptionObject = {\n endpoint: pushSubscriptionJson.endpoint,\n keys: {\n p256dh: pushSubscriptionJson.keys!.p256dh,\n auth: pushSubscriptionJson.keys!.auth,\n },\n };\n\n // Store notification icon string in service worker.\n // This message is received by `/expo-service-worker.js`.\n // We wrap it with `fromExpoWebClient` to make sure other message\n // will not override content such as `notificationIcon`.\n // https://stackoverflow.com/a/35729334/2603230\n const notificationIcon = (Constants.expoConfig?.notification ?? {}).icon;\n await registration.active.postMessage(\n JSON.stringify({ fromExpoWebClient: { notificationIcon } })\n );\n\n return subscriptionObject;\n}\n\n// https://github.com/web-push-libs/web-push#using-vapid-key-for-applicationserverkey\nfunction _urlBase64ToUint8Array(base64String: string): Uint8Array {\n const padding = '='.repeat((4 - (base64String.length % 4)) % 4);\n const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');\n\n const rawData = window.atob(base64);\n const outputArray = new Uint8Array(rawData.length);\n\n for (let i = 0; i < rawData.length; ++i) {\n outputArray[i] = rawData.charCodeAt(i);\n }\n return outputArray;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getExpoPushTokenAsync.d.ts","sourceRoot":"","sources":["../src/getExpoPushTokenAsync.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKhE,UAAU,OAAO;IAEf,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,GAAG,CAAC,EAAE,MAAM,CAAC;IAGb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,wBAA8B,qBAAqB,CAAC,OAAO,GAAE,OAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA6FjG"}
1
+ {"version":3,"file":"getExpoPushTokenAsync.d.ts","sourceRoot":"","sources":["../src/getExpoPushTokenAsync.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKhE,UAAU,OAAO;IAEf,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,GAAG,CAAC,EAAE,MAAM,CAAC;IAGb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,wBAA8B,qBAAqB,CAAC,OAAO,GAAE,OAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA0FjG"}
@@ -8,10 +8,7 @@ const productionBaseUrl = 'https://exp.host/--/api/v2/';
8
8
  export default async function getExpoPushTokenAsync(options = {}) {
9
9
  const devicePushToken = options.devicePushToken || (await getDevicePushTokenAsync());
10
10
  const deviceId = options.deviceId || (await getDeviceIdAsync());
11
- const experienceId = options.experienceId ||
12
- Constants.manifest?.originalFullName ||
13
- Constants.manifest2?.extra?.expoClient?.originalFullName ||
14
- Constants.manifest?.id;
11
+ const experienceId = options.experienceId || Constants.expoConfig?.originalFullName || Constants.manifest?.id;
15
12
  const projectId = options.projectId ||
16
13
  Constants.manifest2?.extra?.eas?.projectId ||
17
14
  Constants.manifest?.projectId;
@@ -1 +1 @@
1
- {"version":3,"file":"getExpoPushTokenAsync.js","sourceRoot":"","sources":["../src/getExpoPushTokenAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAElE,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAEhE,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAmBxD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,qBAAqB,CAAC,UAAmB,EAAE;IACvE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,CAAC,MAAM,uBAAuB,EAAE,CAAC,CAAC;IAErF,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,MAAM,gBAAgB,EAAE,CAAC,CAAC;IAEhE,MAAM,YAAY,GAChB,OAAO,CAAC,YAAY;QACpB,SAAS,CAAC,QAAQ,EAAE,gBAAgB;QACpC,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB;QACxD,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC;IAEzB,MAAM,SAAS,GACb,OAAO,CAAC,SAAS;QACjB,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS;QAC1C,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC;IAEhC,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE;QAC/B,MAAM,IAAI,UAAU,CAClB,oCAAoC,EACpC,uJAAuJ,CACxJ,CAAC;KACH;IAED,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAA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K,KAAK;YACR,OAAO,MAAM,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC;QACf,gFAAgF;QAChF;YACE,OAAO,eAAe,CAAC,IAAI,CAAC;KAC/B;AACH,CAAC","sourcesContent":["import * as Application from 'expo-application';\nimport Constants from 'expo-constants';\nimport { Platform, CodedError, UnavailabilityError } from 'expo-modules-core';\n\nimport { setAutoServerRegistrationEnabledAsync } from './DevicePushTokenAutoRegistration.fx';\nimport ServerRegistrationModule from './ServerRegistrationModule';\nimport { DevicePushToken, ExpoPushToken } from './Tokens.types';\nimport getDevicePushTokenAsync from './getDevicePushTokenAsync';\n\nconst productionBaseUrl = 'https://exp.host/--/api/v2/';\n\ninterface Options {\n // Endpoint URL override\n baseUrl?: string;\n\n // Request URL override\n url?: string;\n\n // Request body overrides\n type?: string;\n deviceId?: string;\n development?: boolean;\n experienceId?: string;\n projectId?: string;\n applicationId?: string;\n devicePushToken?: DevicePushToken;\n}\n\nexport default async function getExpoPushTokenAsync(options: Options = {}): Promise<ExpoPushToken> {\n const devicePushToken = options.devicePushToken || (await getDevicePushTokenAsync());\n\n const deviceId = options.deviceId || (await getDeviceIdAsync());\n\n const experienceId =\n options.experienceId ||\n Constants.manifest?.originalFullName ||\n Constants.manifest2?.extra?.expoClient?.originalFullName ||\n Constants.manifest?.id;\n\n const projectId =\n options.projectId ||\n Constants.manifest2?.extra?.eas?.projectId ||\n Constants.manifest?.projectId;\n\n if (!experienceId && !projectId) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_NO_EXPERIENCE_ID',\n \"No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.\"\n );\n }\n\n const applicationId = options.applicationId || Application.applicationId;\n if (!applicationId) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_NO_APPLICATION_ID',\n \"No applicationId found. If it can't be inferred from native configuration by expo-application, you have to pass it in yourself.\"\n );\n }\n const type = options.type || getTypeOfToken(devicePushToken);\n const development = options.development || (await shouldUseDevelopmentNotificationService());\n\n const baseUrl = options.baseUrl ?? productionBaseUrl;\n const url = options.url ?? `${baseUrl}push/getExpoPushToken`;\n\n const body = {\n type,\n deviceId: deviceId.toLowerCase(),\n development,\n appId: applicationId,\n deviceToken: getDeviceToken(devicePushToken),\n ...(projectId ? { projectId } : { experienceId }),\n };\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n },\n body: JSON.stringify(body),\n }).catch((error) => {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_NETWORK_ERROR',\n `Error encountered while fetching Expo token: ${error}.`\n );\n });\n\n if (!response.ok) {\n const statusInfo = response.statusText || response.status;\n let body: string | undefined = undefined;\n try {\n body = await response.text();\n } catch {\n // do nothing\n }\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Error encountered while fetching Expo token, expected an OK response, received: ${statusInfo} (body: \"${body}\").`\n );\n }\n\n const expoPushToken = getExpoPushToken(await parseResponse(response));\n\n try {\n if (options.url || options.baseUrl) {\n console.debug(\n `[expo-notifications] Since the URL endpoint to register in has been customized in the options, expo-notifications won't try to auto-update the device push token on the server.`\n );\n } else {\n await setAutoServerRegistrationEnabledAsync(true);\n }\n } catch (e) {\n console.warn(\n '[expo-notifications] Could not enable automatically registering new device tokens with the Expo notification service',\n e\n );\n }\n\n return {\n type: 'expo',\n data: expoPushToken,\n };\n}\n\nasync function parseResponse(response: Response) {\n try {\n return await response.json();\n } catch {\n try {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Expected a JSON response from server when fetching Expo token, received body: ${JSON.stringify(\n await response.text()\n )}.`\n );\n } catch {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Expected a JSON response from server when fetching Expo token, received response: ${JSON.stringify(\n response\n )}.`\n );\n }\n }\n}\n\nfunction getExpoPushToken(data: any) {\n if (\n !data ||\n !(typeof data === 'object') ||\n !data.data ||\n !(typeof data.data === 'object') ||\n !data.data.expoPushToken ||\n !(typeof data.data.expoPushToken === 'string')\n ) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Malformed response from server, expected \"{ data: { expoPushToken: string } }\", received: ${JSON.stringify(\n data,\n null,\n 2\n )}.`\n );\n }\n\n return data.data.expoPushToken as string;\n}\n\n// Same as in DevicePushTokenAutoRegistration\nasync function getDeviceIdAsync() {\n try {\n if (!ServerRegistrationModule.getInstallationIdAsync) {\n throw new UnavailabilityError('ExpoServerRegistrationModule', 'getInstallationIdAsync');\n }\n\n return await ServerRegistrationModule.getInstallationIdAsync();\n } catch (e) {\n throw new CodedError(\n 'ERR_NOTIF_DEVICE_ID',\n `Could not have fetched installation ID of the application: ${e}.`\n );\n }\n}\n\nfunction getDeviceToken(devicePushToken: DevicePushToken) {\n if (typeof devicePushToken.data === 'string') {\n return devicePushToken.data;\n }\n\n return JSON.stringify(devicePushToken.data);\n}\n\n// Same as in DevicePushTokenAutoRegistration\nasync function shouldUseDevelopmentNotificationService() {\n if (Platform.OS === 'ios') {\n try {\n const notificationServiceEnvironment =\n await Application.getIosPushNotificationServiceEnvironmentAsync();\n if (notificationServiceEnvironment === 'development') {\n return true;\n }\n } catch {\n // We can't do anything here, we'll fallback to false then.\n }\n }\n\n return false;\n}\n\n// Same as in DevicePushTokenAutoRegistration\nfunction getTypeOfToken(devicePushToken: DevicePushToken) {\n switch (devicePushToken.type) {\n case 'ios':\n return 'apns';\n case 'android':\n return 'fcm';\n // This probably will error on server, but let's make this function future-safe.\n default:\n return devicePushToken.type;\n }\n}\n"]}
1
+ {"version":3,"file":"getExpoPushTokenAsync.js","sourceRoot":"","sources":["../src/getExpoPushTokenAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CA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AsB,EAAE;YACpD,MAAM,IAAI,mBAAmB,CAAC,8BAA8B,EAAE,wBAAwB,CAAC,CAAC;SACzF;QAED,OAAO,MAAM,wBAAwB,CAAC,sBAAsB,EAAE,CAAC;KAChE;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,UAAU,CAClB,qBAAqB,EACrB,8DAA8D,CAAC,GAAG,CACnE,CAAC;KACH;AACH,CAAC;AAED,SAAS,cAAc,CAAC,eAAgC;IACtD,IAAI,OAAO,eAAe,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC5C,OAAO,eAAe,CAAC,IAAI,CAAC;KAC7B;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAED,6CAA6C;AAC7C,KAAK,UAAU,uCAAuC;IACpD,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE;QACzB,IAAI;YACF,MAAM,8BAA8B,GAClC,MAAM,WAAW,CAAC,6CAA6C,EAAE,CAAC;YACpE,IAAI,8BAA8B,KAAK,aAAa,EAAE;gBACpD,OAAO,IAAI,CAAC;aACb;SACF;QAAC,MAAM;YACN,2DAA2D;SAC5D;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,6CAA6C;AAC7C,SAAS,cAAc,CAAC,eAAgC;IACtD,QAAQ,eAAe,CAAC,IAAI,EAAE;QAC5B,KAAK,KAAK;YACR,OAAO,MAAM,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC;QACf,gFAAgF;QAChF;YACE,OAAO,eAAe,CAAC,IAAI,CAAC;KAC/B;AACH,CAAC","sourcesContent":["import * as Application from 'expo-application';\nimport Constants from 'expo-constants';\nimport { Platform, CodedError, UnavailabilityError } from 'expo-modules-core';\n\nimport { setAutoServerRegistrationEnabledAsync } from './DevicePushTokenAutoRegistration.fx';\nimport ServerRegistrationModule from './ServerRegistrationModule';\nimport { DevicePushToken, ExpoPushToken } from './Tokens.types';\nimport getDevicePushTokenAsync from './getDevicePushTokenAsync';\n\nconst productionBaseUrl = 'https://exp.host/--/api/v2/';\n\ninterface Options {\n // Endpoint URL override\n baseUrl?: string;\n\n // Request URL override\n url?: string;\n\n // Request body overrides\n type?: string;\n deviceId?: string;\n development?: boolean;\n experienceId?: string;\n projectId?: string;\n applicationId?: string;\n devicePushToken?: DevicePushToken;\n}\n\nexport default async function getExpoPushTokenAsync(options: Options = {}): Promise<ExpoPushToken> {\n const devicePushToken = options.devicePushToken || (await getDevicePushTokenAsync());\n\n const deviceId = options.deviceId || (await getDeviceIdAsync());\n\n const experienceId =\n options.experienceId || Constants.expoConfig?.originalFullName || Constants.manifest?.id;\n\n const projectId =\n options.projectId ||\n Constants.manifest2?.extra?.eas?.projectId ||\n Constants.manifest?.projectId;\n\n if (!experienceId && !projectId) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_NO_EXPERIENCE_ID',\n \"No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.\"\n );\n }\n\n const applicationId = options.applicationId || Application.applicationId;\n if (!applicationId) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_NO_APPLICATION_ID',\n \"No applicationId found. If it can't be inferred from native configuration by expo-application, you have to pass it in yourself.\"\n );\n }\n const type = options.type || getTypeOfToken(devicePushToken);\n const development = options.development || (await shouldUseDevelopmentNotificationService());\n\n const baseUrl = options.baseUrl ?? productionBaseUrl;\n const url = options.url ?? `${baseUrl}push/getExpoPushToken`;\n\n const body = {\n type,\n deviceId: deviceId.toLowerCase(),\n development,\n appId: applicationId,\n deviceToken: getDeviceToken(devicePushToken),\n ...(projectId ? { projectId } : { experienceId }),\n };\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n },\n body: JSON.stringify(body),\n }).catch((error) => {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_NETWORK_ERROR',\n `Error encountered while fetching Expo token: ${error}.`\n );\n });\n\n if (!response.ok) {\n const statusInfo = response.statusText || response.status;\n let body: string | undefined = undefined;\n try {\n body = await response.text();\n } catch {\n // do nothing\n }\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Error encountered while fetching Expo token, expected an OK response, received: ${statusInfo} (body: \"${body}\").`\n );\n }\n\n const expoPushToken = getExpoPushToken(await parseResponse(response));\n\n try {\n if (options.url || options.baseUrl) {\n console.debug(\n `[expo-notifications] Since the URL endpoint to register in has been customized in the options, expo-notifications won't try to auto-update the device push token on the server.`\n );\n } else {\n await setAutoServerRegistrationEnabledAsync(true);\n }\n } catch (e) {\n console.warn(\n '[expo-notifications] Could not enable automatically registering new device tokens with the Expo notification service',\n e\n );\n }\n\n return {\n type: 'expo',\n data: expoPushToken,\n };\n}\n\nasync function parseResponse(response: Response) {\n try {\n return await response.json();\n } catch {\n try {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Expected a JSON response from server when fetching Expo token, received body: ${JSON.stringify(\n await response.text()\n )}.`\n );\n } catch {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Expected a JSON response from server when fetching Expo token, received response: ${JSON.stringify(\n response\n )}.`\n );\n }\n }\n}\n\nfunction getExpoPushToken(data: any) {\n if (\n !data ||\n !(typeof data === 'object') ||\n !data.data ||\n !(typeof data.data === 'object') ||\n !data.data.expoPushToken ||\n !(typeof data.data.expoPushToken === 'string')\n ) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_SERVER_ERROR',\n `Malformed response from server, expected \"{ data: { expoPushToken: string } }\", received: ${JSON.stringify(\n data,\n null,\n 2\n )}.`\n );\n }\n\n return data.data.expoPushToken as string;\n}\n\n// Same as in DevicePushTokenAutoRegistration\nasync function getDeviceIdAsync() {\n try {\n if (!ServerRegistrationModule.getInstallationIdAsync) {\n throw new UnavailabilityError('ExpoServerRegistrationModule', 'getInstallationIdAsync');\n }\n\n return await ServerRegistrationModule.getInstallationIdAsync();\n } catch (e) {\n throw new CodedError(\n 'ERR_NOTIF_DEVICE_ID',\n `Could not have fetched installation ID of the application: ${e}.`\n );\n }\n}\n\nfunction getDeviceToken(devicePushToken: DevicePushToken) {\n if (typeof devicePushToken.data === 'string') {\n return devicePushToken.data;\n }\n\n return JSON.stringify(devicePushToken.data);\n}\n\n// Same as in DevicePushTokenAutoRegistration\nasync function shouldUseDevelopmentNotificationService() {\n if (Platform.OS === 'ios') {\n try {\n const notificationServiceEnvironment =\n await Application.getIosPushNotificationServiceEnvironmentAsync();\n if (notificationServiceEnvironment === 'development') {\n return true;\n }\n } catch {\n // We can't do anything here, we'll fallback to false then.\n }\n }\n\n return false;\n}\n\n// Same as in DevicePushTokenAutoRegistration\nfunction getTypeOfToken(devicePushToken: DevicePushToken) {\n switch (devicePushToken.type) {\n case 'ios':\n return 'apns';\n case 'android':\n return 'fcm';\n // This probably will error on server, but let's make this function future-safe.\n default:\n return devicePushToken.type;\n }\n}\n"]}
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package['license']
11
11
  s.author = package['author']
12
12
  s.homepage = package['homepage']
13
- s.platform = :ios, '12.0'
13
+ s.platform = :ios, '13.0'
14
14
  s.source = { git: 'https://github.com/expo/expo.git' }
15
15
  s.static_framework = true
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-notifications",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Notifications module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -37,26 +37,25 @@
37
37
  "preset": "expo-module-scripts/ios"
38
38
  },
39
39
  "dependencies": {
40
- "@expo/config-plugins": "~5.0.0",
41
40
  "@expo/image-utils": "^0.3.18",
42
41
  "@ide/backoff": "^1.0.0",
43
42
  "abort-controller": "^3.0.0",
44
43
  "assert": "^2.0.0",
45
44
  "badgin": "^1.1.5",
46
- "expo-application": "~4.2.0",
47
- "expo-constants": "~13.2.0",
45
+ "expo-application": "~5.0.0",
46
+ "expo-constants": "~14.0.0",
48
47
  "fs-extra": "^9.1.0",
49
48
  "uuid": "^3.4.0"
50
49
  },
51
50
  "devDependencies": {
52
51
  "@types/node-fetch": "^2.5.7",
53
52
  "@types/uuid": "^3.4.7",
54
- "expo-module-scripts": "^2.0.0",
53
+ "expo-module-scripts": "^3.0.0",
55
54
  "memfs": "^3.2.0",
56
55
  "node-fetch": "^2.6.7"
57
56
  },
58
57
  "peerDependencies": {
59
58
  "expo": "*"
60
59
  },
61
- "gitHead": "6e131f2da851a47c3a24eb3d6fc971a1a7822086"
60
+ "gitHead": "eab2b09c735fb0fc2bf734a3f29a6593adba3838"
62
61
  }
@@ -1,4 +1,4 @@
1
- import { ConfigPlugin } from '@expo/config-plugins';
1
+ import { ConfigPlugin } from 'expo/config-plugins';
2
2
  export declare type NotificationsPluginProps = {
3
3
  /**
4
4
  * Local path to an image to use as the icon for push notifications.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const config_plugins_1 = require("@expo/config-plugins");
3
+ const config_plugins_1 = require("expo/config-plugins");
4
4
  const withNotificationsAndroid_1 = require("./withNotificationsAndroid");
5
5
  const withNotificationsIOS_1 = require("./withNotificationsIOS");
6
6
  const pkg = require('expo-notifications/package.json');
@@ -1,5 +1,5 @@
1
- import { AndroidConfig, ConfigPlugin } from '@expo/config-plugins';
2
- import { ExpoConfig } from '@expo/config-types';
1
+ import { ExpoConfig } from 'expo/config';
2
+ import { AndroidConfig, ConfigPlugin } from 'expo/config-plugins';
3
3
  import { NotificationsPluginProps } from './withNotifications';
4
4
  declare type DPIString = 'mdpi' | 'hdpi' | 'xhdpi' | 'xxhdpi' | 'xxxhdpi';
5
5
  declare type dpiMap = Record<DPIString, {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withNotificationsAndroid = exports.setNotificationSounds = exports.setNotificationIconAsync = exports.setNotificationIconColor = exports.getNotificationColor = exports.getNotificationIcon = exports.withNotificationSounds = exports.withNotificationManifest = exports.withNotificationIconColor = exports.withNotificationIcons = exports.NOTIFICATION_ICON_COLOR_RESOURCE = exports.NOTIFICATION_ICON_COLOR = exports.NOTIFICATION_ICON_RESOURCE = exports.NOTIFICATION_ICON = exports.META_DATA_NOTIFICATION_ICON_COLOR = exports.META_DATA_NOTIFICATION_ICON = exports.dpiValues = exports.ANDROID_RES_PATH = void 0;
4
- const config_plugins_1 = require("@expo/config-plugins");
5
4
  const image_utils_1 = require("@expo/image-utils");
5
+ const config_plugins_1 = require("expo/config-plugins");
6
6
  const fs_1 = require("fs");
7
7
  const path_1 = require("path");
8
8
  const { Colors } = config_plugins_1.AndroidConfig;
@@ -65,13 +65,11 @@ const withNotificationSounds = (config, { sounds }) => {
65
65
  };
66
66
  exports.withNotificationSounds = withNotificationSounds;
67
67
  function getNotificationIcon(config) {
68
- var _a;
69
- return ((_a = config.notification) === null || _a === void 0 ? void 0 : _a.icon) || null;
68
+ return config.notification?.icon || null;
70
69
  }
71
70
  exports.getNotificationIcon = getNotificationIcon;
72
71
  function getNotificationColor(config) {
73
- var _a;
74
- return ((_a = config.notification) === null || _a === void 0 ? void 0 : _a.color) || null;
72
+ return config.notification?.color || null;
75
73
  }
76
74
  exports.getNotificationColor = getNotificationColor;
77
75
  function setNotificationIconColor(color, colors) {
@@ -1,4 +1,4 @@
1
- import { ConfigPlugin, XcodeProject } from '@expo/config-plugins';
1
+ import { ConfigPlugin, XcodeProject } from 'expo/config-plugins';
2
2
  import { NotificationsPluginProps } from './withNotifications';
3
3
  export declare const withNotificationsIOS: ConfigPlugin<NotificationsPluginProps>;
4
4
  export declare const withNotificationSounds: ConfigPlugin<{
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setNotificationSounds = exports.withNotificationSounds = exports.withNotificationsIOS = void 0;
4
- const config_plugins_1 = require("@expo/config-plugins");
4
+ const config_plugins_1 = require("expo/config-plugins");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
7
  const ERROR_MSG_PREFIX = 'An error occurred while configuring iOS notifications. ';
@@ -1,4 +1,4 @@
1
- import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
1
+ import { ConfigPlugin, createRunOncePlugin } from 'expo/config-plugins';
2
2
 
3
3
  import { withNotificationsAndroid } from './withNotificationsAndroid';
4
4
  import { withNotificationsIOS } from './withNotificationsIOS';
@@ -1,12 +1,12 @@
1
+ import { generateImageAsync } from '@expo/image-utils';
2
+ import { ExpoConfig } from 'expo/config';
1
3
  import {
2
4
  AndroidConfig,
3
5
  ConfigPlugin,
4
6
  withDangerousMod,
5
7
  withAndroidColors,
6
8
  withAndroidManifest,
7
- } from '@expo/config-plugins';
8
- import { ExpoConfig } from '@expo/config-types';
9
- import { generateImageAsync } from '@expo/image-utils';
9
+ } from 'expo/config-plugins';
10
10
  import { writeFileSync, unlinkSync, copyFileSync, existsSync, mkdirSync } from 'fs';
11
11
  import { basename, resolve } from 'path';
12
12
 
@@ -4,7 +4,7 @@ import {
4
4
  IOSConfig,
5
5
  withXcodeProject,
6
6
  XcodeProject,
7
- } from '@expo/config-plugins';
7
+ } from 'expo/config-plugins';
8
8
  import { copyFileSync } from 'fs';
9
9
  import { basename, resolve } from 'path';
10
10
 
@@ -37,7 +37,7 @@ export async function requestPermissionsAsync(permissions?: NotificationPermissi
37
37
  *
38
38
  * @example
39
39
  * ```ts
40
- * const [status, requestPermission] = Notifications.usePermissions();
40
+ * const [permissionResponse, requestPermission] = Notifications.usePermissions();
41
41
  * ```
42
42
  */
43
43
  export const usePermissions = createPermissionHook<
@@ -31,11 +31,8 @@ function guardPermission() {
31
31
  }
32
32
 
33
33
  async function _subscribeDeviceToPushNotificationsAsync(): Promise<DevicePushToken['data']> {
34
- const vapidPublicKey: string | null =
35
- // @ts-expect-error: TODO: not on the schema
36
- Constants.manifest?.notification?.vapidPublicKey ??
37
- // @ts-expect-error: TODO: not on the schema
38
- Constants.manifest2?.extra?.expoClient?.notification?.vapidPublicKey;
34
+ // @ts-expect-error: TODO: not on the schema
35
+ const vapidPublicKey: string | null = Constants.expoConfig?.notification?.vapidPublicKey;
39
36
  if (!vapidPublicKey) {
40
37
  throw new CodedError(
41
38
  'ERR_NOTIFICATIONS_PUSH_WEB_MISSING_CONFIG',
@@ -43,11 +40,8 @@ async function _subscribeDeviceToPushNotificationsAsync(): Promise<DevicePushTok
43
40
  );
44
41
  }
45
42
 
46
- const serviceWorkerPath =
47
- // @ts-expect-error: TODO: not on the schema
48
- Constants.manifest?.notification.serviceWorkerPath ??
49
- // @ts-expect-error: TODO: not on the schema
50
- Constants.manifest2?.extra?.expoClient?.notification?.serviceWorkerPath;
43
+ // @ts-expect-error: TODO: not on the schema
44
+ const serviceWorkerPath = Constants.expoConfig?.notification?.serviceWorkerPath;
51
45
  if (!serviceWorkerPath) {
52
46
  throw new CodedError(
53
47
  'ERR_NOTIFICATIONS_PUSH_MISSING_CONFIGURATION',
@@ -104,11 +98,7 @@ async function _subscribeDeviceToPushNotificationsAsync(): Promise<DevicePushTok
104
98
  // We wrap it with `fromExpoWebClient` to make sure other message
105
99
  // will not override content such as `notificationIcon`.
106
100
  // https://stackoverflow.com/a/35729334/2603230
107
- const notificationIcon = (
108
- Constants.manifest?.notification ??
109
- Constants.manifest2?.extra?.expoClient?.notification ??
110
- {}
111
- ).icon;
101
+ const notificationIcon = (Constants.expoConfig?.notification ?? {}).icon;
112
102
  await registration.active.postMessage(
113
103
  JSON.stringify({ fromExpoWebClient: { notificationIcon } })
114
104
  );
@@ -32,10 +32,7 @@ export default async function getExpoPushTokenAsync(options: Options = {}): Prom
32
32
  const deviceId = options.deviceId || (await getDeviceIdAsync());
33
33
 
34
34
  const experienceId =
35
- options.experienceId ||
36
- Constants.manifest?.originalFullName ||
37
- Constants.manifest2?.extra?.expoClient?.originalFullName ||
38
- Constants.manifest?.id;
35
+ options.experienceId || Constants.expoConfig?.originalFullName || Constants.manifest?.id;
39
36
 
40
37
  const projectId =
41
38
  options.projectId ||
@@ -1,74 +0,0 @@
1
- package expo.modules.notifications.permissions;
2
-
3
- import android.app.NotificationManager;
4
- import android.content.Context;
5
- import android.os.Build;
6
- import android.os.Bundle;
7
-
8
- import expo.modules.core.ExportedModule;
9
- import expo.modules.core.Promise;
10
- import expo.modules.core.arguments.ReadableArguments;
11
- import expo.modules.core.interfaces.ExpoMethod;
12
-
13
- import androidx.core.app.NotificationManagerCompat;
14
-
15
- import expo.modules.interfaces.permissions.PermissionsStatus;
16
-
17
- import static expo.modules.interfaces.permissions.PermissionsResponse.CAN_ASK_AGAIN_KEY;
18
- import static expo.modules.interfaces.permissions.PermissionsResponse.EXPIRES_KEY;
19
- import static expo.modules.interfaces.permissions.PermissionsResponse.GRANTED_KEY;
20
- import static expo.modules.interfaces.permissions.PermissionsResponse.PERMISSION_EXPIRES_NEVER;
21
- import static expo.modules.interfaces.permissions.PermissionsResponse.STATUS_KEY;
22
-
23
- public class NotificationPermissionsModule extends ExportedModule {
24
- private static final String EXPORTED_NAME = "ExpoNotificationPermissionsModule";
25
-
26
- private static final String ANDROID_RESPONSE_KEY = "android";
27
- private static final String IMPORTANCE_KEY = "importance";
28
- private static final String INTERRUPTION_FILTER_KEY = "interruptionFilter";
29
-
30
- public NotificationPermissionsModule(Context context) {
31
- super(context);
32
- }
33
-
34
- @Override
35
- public String getName() {
36
- return EXPORTED_NAME;
37
- }
38
-
39
- @ExpoMethod
40
- public void getPermissionsAsync(final Promise promise) {
41
- promise.resolve(getPermissionsBundle());
42
- }
43
-
44
- @ExpoMethod
45
- public void requestPermissionsAsync(@SuppressWarnings("unused") final ReadableArguments permissionsTypes, final Promise promise) {
46
- promise.resolve(getPermissionsBundle());
47
- }
48
-
49
- private Bundle getPermissionsBundle() {
50
- NotificationManagerCompat managerCompat = NotificationManagerCompat.from(getContext());
51
- boolean areEnabled = managerCompat.areNotificationsEnabled();
52
- PermissionsStatus status = areEnabled ? PermissionsStatus.GRANTED : PermissionsStatus.DENIED;
53
-
54
- Bundle permissions = new Bundle();
55
-
56
- permissions.putString(EXPIRES_KEY, PERMISSION_EXPIRES_NEVER);
57
- permissions.putBoolean(CAN_ASK_AGAIN_KEY, areEnabled);
58
- permissions.putString(STATUS_KEY, status.getStatus());
59
- permissions.putBoolean(GRANTED_KEY, PermissionsStatus.GRANTED == status);
60
-
61
- Bundle platformPermissions = new Bundle();
62
-
63
- platformPermissions.putInt(IMPORTANCE_KEY, managerCompat.getImportance());
64
-
65
- NotificationManager manager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
66
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && manager != null) {
67
- platformPermissions.putInt(INTERRUPTION_FILTER_KEY, manager.getCurrentInterruptionFilter());
68
- }
69
-
70
- permissions.putBundle(ANDROID_RESPONSE_KEY, platformPermissions);
71
-
72
- return permissions;
73
- }
74
- }