expo-notifications 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +3 -3
- package/android/build.gradle +2 -2
- package/build/Tokens.types.d.ts +5 -14
- package/build/Tokens.types.d.ts.map +1 -1
- package/build/Tokens.types.js.map +1 -1
- package/build/getExpoPushTokenAsync.d.ts.map +1 -1
- package/build/getExpoPushTokenAsync.js +4 -7
- package/build/getExpoPushTokenAsync.js.map +1 -1
- package/package.json +4 -4
- package/src/Tokens.types.ts +5 -14
- package/src/getExpoPushTokenAsync.ts +4 -11
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 0.19.0 — 2023-05-08
|
|
14
|
+
|
|
15
|
+
### 🛠 Breaking changes
|
|
16
|
+
|
|
17
|
+
- Removed the deprecated `ExpoPushTokenOptions.experienceId` field. ([#22303](https://github.com/expo/expo/pull/22303) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
18
|
+
|
|
19
|
+
### 💡 Others
|
|
20
|
+
|
|
21
|
+
- Update fixtures. ([#21397](https://github.com/expo/expo/pull/21397) by [@EvanBacon](https://github.com/EvanBacon))
|
|
22
|
+
- Warn on use of Constants.manifest. ([#22247](https://github.com/expo/expo/pull/22247) by [@wschurman](https://github.com/wschurman))
|
|
23
|
+
|
|
13
24
|
## 0.18.1 — 2023-02-09
|
|
14
25
|
|
|
15
26
|
### 💡 Others
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ For bare React Native projects, you must ensure that you have [installed and con
|
|
|
34
34
|
### Add the package to your npm dependencies
|
|
35
35
|
|
|
36
36
|
```
|
|
37
|
-
expo install expo-notifications
|
|
37
|
+
npx expo install expo-notifications
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### Configure for iOS
|
|
@@ -126,7 +126,7 @@ This module requires permission to subscribe to device boot. It's used to setup
|
|
|
126
126
|
|
|
127
127
|
### Config plugin setup (optional)
|
|
128
128
|
|
|
129
|
-
If you're using EAS Build, you can set your Android notification icon and color tint, add custom push notification sounds, and set your iOS notification environment using the expo-notifications config plugin ([what's a config plugin?](
|
|
129
|
+
If you're using EAS Build, you can set your Android notification icon and color tint, add custom push notification sounds, and set your iOS notification environment using the expo-notifications config plugin ([what's a config plugin?](https://docs.expo.dev/home/config-plugins/introduction)). To setup, just add the config plugin to the plugins array of your `app.json` or `app.config.js` as shown below, then rebuild the app.
|
|
130
130
|
|
|
131
131
|
```json
|
|
132
132
|
{
|
|
@@ -680,7 +680,7 @@ export default function App() {
|
|
|
680
680
|
Linking.addEventListener('url', onReceiveURL);
|
|
681
681
|
|
|
682
682
|
// Listen to expo push notifications
|
|
683
|
-
const subscription = Notifications.addNotificationResponseReceivedListener(response => {
|
|
683
|
+
const subscription = Notifications.addNotificationResponseReceivedListener((response) => {
|
|
684
684
|
const url = response.notification.request.content.data.url;
|
|
685
685
|
|
|
686
686
|
// Any custom logic to see whether the URL needs to be handled
|
package/android/build.gradle
CHANGED
|
@@ -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.
|
|
6
|
+
version = '0.19.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", 33)
|
|
76
76
|
versionCode 21
|
|
77
|
-
versionName '0.
|
|
77
|
+
versionName '0.19.0'
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
lintOptions {
|
package/build/Tokens.types.d.ts
CHANGED
|
@@ -68,39 +68,30 @@ export interface ExpoPushTokenOptions {
|
|
|
68
68
|
/**
|
|
69
69
|
* Makes sense only on iOS, where there are two push notification services: "sandbox" and "production".
|
|
70
70
|
* This defines whether the push token is supposed to be used with the sandbox platform notification service.
|
|
71
|
-
* Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](
|
|
71
|
+
* Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](./application/#applicationgetiospushnotificationserviceenvironmentasync)
|
|
72
72
|
* exposed by `expo-application` or `false`. Most probably you won't need to customize that.
|
|
73
73
|
* You may want to customize that if you don't want to install `expo-application` and still use the sandbox APNs.
|
|
74
74
|
* @platform ios
|
|
75
75
|
*/
|
|
76
76
|
development?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* The ID of the experience to which the token should be attributed.
|
|
79
|
-
* Defaults to [`Constants.manifest.id`](/constants/#constantsmanifest) exposed by `expo-constants`.
|
|
80
|
-
* When building with EAS Build, or in the bare workflow, you must provide a value which takes the shape `@username/projectSlug`,
|
|
81
|
-
* where `username` is the Expo account that the project is associated with, and `projectSlug` is your [`slug`](/config/app.mdx#slug) from Expo config.
|
|
82
|
-
*
|
|
83
|
-
* @deprecated Use `projectId` instead.
|
|
84
|
-
*/
|
|
85
|
-
experienceId?: string;
|
|
86
77
|
/**
|
|
87
78
|
* The ID of the project to which the token should be attributed.
|
|
88
|
-
* Defaults to [`Constants.expoConfig.extra.eas.projectId`](
|
|
79
|
+
* Defaults to [`Constants.expoConfig.extra.eas.projectId`](./constants/#easconfig) exposed by `expo-constants`.
|
|
89
80
|
*
|
|
90
81
|
* When using EAS Build, this value is automatically set. However, it is
|
|
91
82
|
* **recommended** to set it manually. Once you have EAS Build configured, you can find
|
|
92
83
|
* the value in **app.json** under `extra.eas.projectId`. You can copy and paste it into your code.
|
|
93
|
-
* If you are not using EAS Build, it will fallback to [`Constants.
|
|
84
|
+
* If you are not using EAS Build, it will fallback to [`Constants.expoConfig?.extra?.eas?.projectId`](./constants/#manifest).
|
|
94
85
|
*/
|
|
95
86
|
projectId?: string;
|
|
96
87
|
/**
|
|
97
88
|
* The ID of the application to which the token should be attributed.
|
|
98
|
-
* Defaults to [`Application.applicationId`](
|
|
89
|
+
* Defaults to [`Application.applicationId`](./application/#applicationapplicationid) exposed by `expo-application`.
|
|
99
90
|
*/
|
|
100
91
|
applicationId?: string;
|
|
101
92
|
/**
|
|
102
93
|
* The device push token with which to register at the backend.
|
|
103
|
-
* Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync
|
|
94
|
+
* Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync).
|
|
104
95
|
*/
|
|
105
96
|
devicePushToken?: DevicePushToken;
|
|
106
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tokens.types.d.ts","sourceRoot":"","sources":["../src/Tokens.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;CACd;AAGD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE;YACJ,MAAM,EAAE,MAAM,CAAC;YACf,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;KACH,CAAC;CACH;AAGD,KAAK,kCAAkC,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAErF,KAAK,kCAAkC,GAAG;IACxC;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,OAAO,QAAQ,CAAC,EAAE,EAAE,kCAAkC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9E;;;;;;;;;;;OAWG;IACH,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;GAGG;AACH,MAAM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EG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tokens.types.js","sourceRoot":"","sources":["../src/Tokens.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Platform } from 'expo-modules-core';\n\n// @docsMissing\nexport interface NativeDevicePushToken {\n type: 'ios' | 'android';\n data: string;\n}\n\n// @docsMissing\nexport interface WebDevicePushToken {\n type: 'web';\n data: {\n endpoint: string;\n keys: {\n p256dh: string;\n auth: string;\n };\n };\n}\n\n// @docsMissing\ntype ExplicitlySupportedDevicePushToken = NativeDevicePushToken | WebDevicePushToken;\n\ntype ImplicitlySupportedDevicePushToken = {\n /**\n * Either `android`, `ios` or `web`.\n */\n type: Exclude<typeof Platform.OS, ExplicitlySupportedDevicePushToken['type']>;\n /**\n * Either the push token as a string (when for native platforms), or an object conforming to the type below (for web):\n * ```ts\n * {\n * endpoint: string;\n * keys: {\n * p256dh: string;\n * auth: string;\n * }\n * }\n * ```\n */\n data: any;\n};\n\n/**\n * In simple terms, an object of `type: Platform.OS` and `data: any`. The `data` type depends on the environment - on a native device it will be a string,\n * which you can then use to send notifications via Firebase Cloud Messaging (Android) or APNs (iOS); on web it will be a registration object (VAPID).\n */\nexport type DevicePushToken =\n | ExplicitlySupportedDevicePushToken\n | ImplicitlySupportedDevicePushToken;\n\n/**\n * Borrowing structure from `DevicePushToken` a little. You can use the `data` value to send notifications via Expo Notifications service.\n */\nexport interface ExpoPushToken {\n /**\n * Always set to `\"expo\"`.\n */\n type: 'expo';\n /**\n * The acquired push token.\n */\n data: string;\n}\n\nexport interface ExpoPushTokenOptions {\n /**\n * Endpoint URL override.\n */\n baseUrl?: string;\n /**\n * Request URL override.\n */\n url?: string;\n /**\n * Request body override.\n */\n type?: string;\n // @missingDocs\n deviceId?: string;\n /**\n * Makes sense only on iOS, where there are two push notification services: \"sandbox\" and \"production\".\n * This defines whether the push token is supposed to be used with the sandbox platform notification service.\n * Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](
|
|
1
|
+
{"version":3,"file":"Tokens.types.js","sourceRoot":"","sources":["../src/Tokens.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Platform } from 'expo-modules-core';\n\n// @docsMissing\nexport interface NativeDevicePushToken {\n type: 'ios' | 'android';\n data: string;\n}\n\n// @docsMissing\nexport interface WebDevicePushToken {\n type: 'web';\n data: {\n endpoint: string;\n keys: {\n p256dh: string;\n auth: string;\n };\n };\n}\n\n// @docsMissing\ntype ExplicitlySupportedDevicePushToken = NativeDevicePushToken | WebDevicePushToken;\n\ntype ImplicitlySupportedDevicePushToken = {\n /**\n * Either `android`, `ios` or `web`.\n */\n type: Exclude<typeof Platform.OS, ExplicitlySupportedDevicePushToken['type']>;\n /**\n * Either the push token as a string (when for native platforms), or an object conforming to the type below (for web):\n * ```ts\n * {\n * endpoint: string;\n * keys: {\n * p256dh: string;\n * auth: string;\n * }\n * }\n * ```\n */\n data: any;\n};\n\n/**\n * In simple terms, an object of `type: Platform.OS` and `data: any`. The `data` type depends on the environment - on a native device it will be a string,\n * which you can then use to send notifications via Firebase Cloud Messaging (Android) or APNs (iOS); on web it will be a registration object (VAPID).\n */\nexport type DevicePushToken =\n | ExplicitlySupportedDevicePushToken\n | ImplicitlySupportedDevicePushToken;\n\n/**\n * Borrowing structure from `DevicePushToken` a little. You can use the `data` value to send notifications via Expo Notifications service.\n */\nexport interface ExpoPushToken {\n /**\n * Always set to `\"expo\"`.\n */\n type: 'expo';\n /**\n * The acquired push token.\n */\n data: string;\n}\n\nexport interface ExpoPushTokenOptions {\n /**\n * Endpoint URL override.\n */\n baseUrl?: string;\n /**\n * Request URL override.\n */\n url?: string;\n /**\n * Request body override.\n */\n type?: string;\n // @missingDocs\n deviceId?: string;\n /**\n * Makes sense only on iOS, where there are two push notification services: \"sandbox\" and \"production\".\n * This defines whether the push token is supposed to be used with the sandbox platform notification service.\n * Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](./application/#applicationgetiospushnotificationserviceenvironmentasync)\n * exposed by `expo-application` or `false`. Most probably you won't need to customize that.\n * You may want to customize that if you don't want to install `expo-application` and still use the sandbox APNs.\n * @platform ios\n */\n development?: boolean;\n /**\n * The ID of the project to which the token should be attributed.\n * Defaults to [`Constants.expoConfig.extra.eas.projectId`](./constants/#easconfig) exposed by `expo-constants`.\n *\n * When using EAS Build, this value is automatically set. However, it is\n * **recommended** to set it manually. Once you have EAS Build configured, you can find\n * the value in **app.json** under `extra.eas.projectId`. You can copy and paste it into your code.\n * If you are not using EAS Build, it will fallback to [`Constants.expoConfig?.extra?.eas?.projectId`](./constants/#manifest).\n */\n projectId?: string;\n /**\n * The ID of the application to which the token should be attributed.\n * Defaults to [`Application.applicationId`](./application/#applicationapplicationid) exposed by `expo-application`.\n */\n applicationId?: string;\n /**\n * The device push token with which to register at the backend.\n * Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync).\n */\n devicePushToken?: DevicePushToken;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExpoPushTokenAsync.d.ts","sourceRoot":"","sources":["../src/getExpoPushTokenAsync.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,aAAa,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAKtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAA8B,qBAAqB,CACjD,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"getExpoPushTokenAsync.d.ts","sourceRoot":"","sources":["../src/getExpoPushTokenAsync.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,aAAa,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAKtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAA8B,qBAAqB,CACjD,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,CAyFxB"}
|
|
@@ -45,15 +45,12 @@ const productionBaseUrl = 'https://exp.host/--/api/v2/';
|
|
|
45
45
|
export default async function getExpoPushTokenAsync(options = {}) {
|
|
46
46
|
const devicePushToken = options.devicePushToken || (await getDevicePushTokenAsync());
|
|
47
47
|
const deviceId = options.deviceId || (await getDeviceIdAsync());
|
|
48
|
-
const
|
|
49
|
-
const projectId = options.projectId ||
|
|
50
|
-
Constants.expoConfig?.extra?.eas?.projectId ||
|
|
51
|
-
Constants.manifest?.projectId;
|
|
48
|
+
const projectId = options.projectId || Constants.easConfig?.projectId;
|
|
52
49
|
if (!projectId) {
|
|
53
50
|
console.warn('Calling getExpoPushTokenAsync without specifying a projectId is deprecated and will no longer be supported in SDK 49+');
|
|
54
51
|
}
|
|
55
|
-
if (!
|
|
56
|
-
throw new CodedError('ERR_NOTIFICATIONS_NO_EXPERIENCE_ID', "No
|
|
52
|
+
if (!projectId) {
|
|
53
|
+
throw new CodedError('ERR_NOTIFICATIONS_NO_EXPERIENCE_ID', "No 'projectId' found. If 'projectId' can't be inferred from the manifest (eg. in bare workflow), you have to pass it in yourself.");
|
|
57
54
|
}
|
|
58
55
|
const applicationId = options.applicationId || Application.applicationId;
|
|
59
56
|
if (!applicationId) {
|
|
@@ -69,7 +66,7 @@ export default async function getExpoPushTokenAsync(options = {}) {
|
|
|
69
66
|
development,
|
|
70
67
|
appId: applicationId,
|
|
71
68
|
deviceToken: getDeviceToken(devicePushToken),
|
|
72
|
-
|
|
69
|
+
projectId,
|
|
73
70
|
};
|
|
74
71
|
const response = await fetch(url, {
|
|
75
72
|
method: 'POST',
|
|
@@ -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;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,qBAAqB,CACjD,UAAgC,EAAE;IAElC,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,IAAI,SAAS,CAAC,UAAU,EAAE,gBAAgB,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC;IAE3F,MAAM,SAAS,GACb,OAAO,CAAC,SAAS;QACjB,SAAS,CAAC,UAAU,EAAE,KAA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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, ExpoPushTokenOptions } from './Tokens.types';\nimport getDevicePushTokenAsync from './getDevicePushTokenAsync';\n\nconst productionBaseUrl = 'https://exp.host/--/api/v2/';\n\n/**\n * Returns an Expo token that can be used to send a push notification to the device using Expo's push notifications service.\n *\n * This method makes requests to the Expo's servers. It can get rejected in cases where the request itself fails\n * (for example, due to the device being offline, experiencing a network timeout, or other HTTPS request failures).\n * To provide offline support to your users, you should `try/catch` this method and implement retry logic to attempt\n * to get the push token later, once the device is back online.\n *\n * > For Expo's backend to be able to send notifications to your app, you will need to provide it with push notification keys.\n * For more information, see [credentials](/push-notifications/push-notifications-setup/#get-credentials-for-development-builds) in the push notifications setup.\n *\n * @param options Object allowing you to pass in push notification configuration.\n * @return Returns a `Promise` that resolves to an object representing acquired push token.\n * @header fetch\n *\n * @example\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * export async function registerForPushNotificationsAsync(userId: string) {\n * const expoPushToken = await Notifications.getExpoPushTokenAsync({\n * projectId: 'your-project-id',\n * });\n *\n * await fetch('https://example.com/', {\n * method: 'POST',\n * headers: {\n * 'Content-Type': 'application/json',\n * },\n * body: JSON.stringify({\n * userId,\n * expoPushToken,\n * }),\n * });\n * }\n * ```\n */\nexport default async function getExpoPushTokenAsync(\n options: ExpoPushTokenOptions = {}\n): 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.expoConfig?.extra?.eas?.projectId ||\n Constants.manifest?.projectId;\n\n if (!projectId) {\n console.warn(\n 'Calling getExpoPushTokenAsync without specifying a projectId is deprecated and will no longer be supported in SDK 49+'\n );\n }\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,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;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,qBAAqB,CACjD,UAAgC,EAAE;IAElC,MAAM,eAAe,GAAG,OAAO,CA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ACpD,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, ExpoPushTokenOptions } from './Tokens.types';\nimport getDevicePushTokenAsync from './getDevicePushTokenAsync';\n\nconst productionBaseUrl = 'https://exp.host/--/api/v2/';\n\n/**\n * Returns an Expo token that can be used to send a push notification to the device using Expo's push notifications service.\n *\n * This method makes requests to the Expo's servers. It can get rejected in cases where the request itself fails\n * (for example, due to the device being offline, experiencing a network timeout, or other HTTPS request failures).\n * To provide offline support to your users, you should `try/catch` this method and implement retry logic to attempt\n * to get the push token later, once the device is back online.\n *\n * > For Expo's backend to be able to send notifications to your app, you will need to provide it with push notification keys.\n * For more information, see [credentials](/push-notifications/push-notifications-setup/#get-credentials-for-development-builds) in the push notifications setup.\n *\n * @param options Object allowing you to pass in push notification configuration.\n * @return Returns a `Promise` that resolves to an object representing acquired push token.\n * @header fetch\n *\n * @example\n * ```ts\n * import * as Notifications from 'expo-notifications';\n *\n * export async function registerForPushNotificationsAsync(userId: string) {\n * const expoPushToken = await Notifications.getExpoPushTokenAsync({\n * projectId: 'your-project-id',\n * });\n *\n * await fetch('https://example.com/', {\n * method: 'POST',\n * headers: {\n * 'Content-Type': 'application/json',\n * },\n * body: JSON.stringify({\n * userId,\n * expoPushToken,\n * }),\n * });\n * }\n * ```\n */\nexport default async function getExpoPushTokenAsync(\n options: ExpoPushTokenOptions = {}\n): Promise<ExpoPushToken> {\n const devicePushToken = options.devicePushToken || (await getDevicePushTokenAsync());\n\n const deviceId = options.deviceId || (await getDeviceIdAsync());\n const projectId = options.projectId || Constants.easConfig?.projectId;\n\n if (!projectId) {\n console.warn(\n 'Calling getExpoPushTokenAsync without specifying a projectId is deprecated and will no longer be supported in SDK 49+'\n );\n }\n\n if (!projectId) {\n throw new CodedError(\n 'ERR_NOTIFICATIONS_NO_EXPERIENCE_ID',\n \"No 'projectId' found. If 'projectId' can't be inferred from the manifest (eg. in bare workflow), you have to pass it 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,\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-notifications",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Notifications module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"abort-controller": "^3.0.0",
|
|
43
43
|
"assert": "^2.0.0",
|
|
44
44
|
"badgin": "^1.1.5",
|
|
45
|
-
"expo-application": "~5.
|
|
46
|
-
"expo-constants": "~14.
|
|
45
|
+
"expo-application": "~5.2.0",
|
|
46
|
+
"expo-constants": "~14.3.0",
|
|
47
47
|
"fs-extra": "^9.1.0",
|
|
48
48
|
"uuid": "^3.4.0"
|
|
49
49
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"expo": "*"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "4ba50c428c8369bb6b3a51a860d4898ad4ccbe78"
|
|
61
61
|
}
|
package/src/Tokens.types.ts
CHANGED
|
@@ -81,39 +81,30 @@ export interface ExpoPushTokenOptions {
|
|
|
81
81
|
/**
|
|
82
82
|
* Makes sense only on iOS, where there are two push notification services: "sandbox" and "production".
|
|
83
83
|
* This defines whether the push token is supposed to be used with the sandbox platform notification service.
|
|
84
|
-
* Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](
|
|
84
|
+
* Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](./application/#applicationgetiospushnotificationserviceenvironmentasync)
|
|
85
85
|
* exposed by `expo-application` or `false`. Most probably you won't need to customize that.
|
|
86
86
|
* You may want to customize that if you don't want to install `expo-application` and still use the sandbox APNs.
|
|
87
87
|
* @platform ios
|
|
88
88
|
*/
|
|
89
89
|
development?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* The ID of the experience to which the token should be attributed.
|
|
92
|
-
* Defaults to [`Constants.manifest.id`](/constants/#constantsmanifest) exposed by `expo-constants`.
|
|
93
|
-
* When building with EAS Build, or in the bare workflow, you must provide a value which takes the shape `@username/projectSlug`,
|
|
94
|
-
* where `username` is the Expo account that the project is associated with, and `projectSlug` is your [`slug`](/config/app.mdx#slug) from Expo config.
|
|
95
|
-
*
|
|
96
|
-
* @deprecated Use `projectId` instead.
|
|
97
|
-
*/
|
|
98
|
-
experienceId?: string;
|
|
99
90
|
/**
|
|
100
91
|
* The ID of the project to which the token should be attributed.
|
|
101
|
-
* Defaults to [`Constants.expoConfig.extra.eas.projectId`](
|
|
92
|
+
* Defaults to [`Constants.expoConfig.extra.eas.projectId`](./constants/#easconfig) exposed by `expo-constants`.
|
|
102
93
|
*
|
|
103
94
|
* When using EAS Build, this value is automatically set. However, it is
|
|
104
95
|
* **recommended** to set it manually. Once you have EAS Build configured, you can find
|
|
105
96
|
* the value in **app.json** under `extra.eas.projectId`. You can copy and paste it into your code.
|
|
106
|
-
* If you are not using EAS Build, it will fallback to [`Constants.
|
|
97
|
+
* If you are not using EAS Build, it will fallback to [`Constants.expoConfig?.extra?.eas?.projectId`](./constants/#manifest).
|
|
107
98
|
*/
|
|
108
99
|
projectId?: string;
|
|
109
100
|
/**
|
|
110
101
|
* The ID of the application to which the token should be attributed.
|
|
111
|
-
* Defaults to [`Application.applicationId`](
|
|
102
|
+
* Defaults to [`Application.applicationId`](./application/#applicationapplicationid) exposed by `expo-application`.
|
|
112
103
|
*/
|
|
113
104
|
applicationId?: string;
|
|
114
105
|
/**
|
|
115
106
|
* The device push token with which to register at the backend.
|
|
116
|
-
* Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync
|
|
107
|
+
* Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync).
|
|
117
108
|
*/
|
|
118
109
|
devicePushToken?: DevicePushToken;
|
|
119
110
|
}
|
|
@@ -52,14 +52,7 @@ export default async function getExpoPushTokenAsync(
|
|
|
52
52
|
const devicePushToken = options.devicePushToken || (await getDevicePushTokenAsync());
|
|
53
53
|
|
|
54
54
|
const deviceId = options.deviceId || (await getDeviceIdAsync());
|
|
55
|
-
|
|
56
|
-
const experienceId =
|
|
57
|
-
options.experienceId || Constants.expoConfig?.originalFullName || Constants.manifest?.id;
|
|
58
|
-
|
|
59
|
-
const projectId =
|
|
60
|
-
options.projectId ||
|
|
61
|
-
Constants.expoConfig?.extra?.eas?.projectId ||
|
|
62
|
-
Constants.manifest?.projectId;
|
|
55
|
+
const projectId = options.projectId || Constants.easConfig?.projectId;
|
|
63
56
|
|
|
64
57
|
if (!projectId) {
|
|
65
58
|
console.warn(
|
|
@@ -67,10 +60,10 @@ export default async function getExpoPushTokenAsync(
|
|
|
67
60
|
);
|
|
68
61
|
}
|
|
69
62
|
|
|
70
|
-
if (!
|
|
63
|
+
if (!projectId) {
|
|
71
64
|
throw new CodedError(
|
|
72
65
|
'ERR_NOTIFICATIONS_NO_EXPERIENCE_ID',
|
|
73
|
-
"No
|
|
66
|
+
"No 'projectId' found. If 'projectId' can't be inferred from the manifest (eg. in bare workflow), you have to pass it in yourself."
|
|
74
67
|
);
|
|
75
68
|
}
|
|
76
69
|
|
|
@@ -93,7 +86,7 @@ export default async function getExpoPushTokenAsync(
|
|
|
93
86
|
development,
|
|
94
87
|
appId: applicationId,
|
|
95
88
|
deviceToken: getDeviceToken(devicePushToken),
|
|
96
|
-
|
|
89
|
+
projectId,
|
|
97
90
|
};
|
|
98
91
|
|
|
99
92
|
const response = await fetch(url, {
|