expo-notifications 0.18.0 → 0.18.1

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 CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 0.18.1 — 2023-02-09
14
+
15
+ ### 💡 Others
16
+
17
+ - Export `getExpoPushTokenAsync` parameter type. ([#21104](https://github.com/expo/expo/pull/21104) by [@Simek](https://github.com/Simek))
18
+
13
19
  ## 0.18.0 — 2023-02-03
14
20
 
15
21
  ### 💡 Others
package/README.md CHANGED
@@ -1,4 +1,11 @@
1
- # expo-notifications
1
+ <p>
2
+ <a href="https://docs.expo.dev/versions/latest/sdk/notifications/">
3
+ <img
4
+ src="../../.github/resources/expo-notifications.svg"
5
+ alt="expo-notifications"
6
+ height="64" />
7
+ </a>
8
+ </p>
2
9
 
3
10
  Provides an API to fetch push notification tokens and to present, schedule, receive and respond to notifications.
4
11
 
@@ -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.18.0'
6
+ version = '0.18.1'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -22,7 +22,7 @@ buildscript {
22
22
  if (ext.has("kotlinVersion")) {
23
23
  ext.kotlinVersion()
24
24
  } else {
25
- ext.safeExtGet("kotlinVersion", "1.6.10")
25
+ ext.safeExtGet("kotlinVersion", "1.8.10")
26
26
  }
27
27
  }
28
28
 
@@ -74,7 +74,7 @@ android {
74
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
75
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
76
76
  versionCode 21
77
- versionName '0.18.0'
77
+ versionName '0.18.1'
78
78
  }
79
79
 
80
80
  lintOptions {
@@ -51,5 +51,58 @@ export interface ExpoPushToken {
51
51
  */
52
52
  data: string;
53
53
  }
54
+ export interface ExpoPushTokenOptions {
55
+ /**
56
+ * Endpoint URL override.
57
+ */
58
+ baseUrl?: string;
59
+ /**
60
+ * Request URL override.
61
+ */
62
+ url?: string;
63
+ /**
64
+ * Request body override.
65
+ */
66
+ type?: string;
67
+ deviceId?: string;
68
+ /**
69
+ * Makes sense only on iOS, where there are two push notification services: "sandbox" and "production".
70
+ * This defines whether the push token is supposed to be used with the sandbox platform notification service.
71
+ * Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](/application/#applicationgetiospushnotificationserviceenvironmentasync)
72
+ * exposed by `expo-application` or `false`. Most probably you won't need to customize that.
73
+ * You may want to customize that if you don't want to install `expo-application` and still use the sandbox APNs.
74
+ * @platform ios
75
+ */
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
+ /**
87
+ * The ID of the project to which the token should be attributed.
88
+ * Defaults to [`Constants.expoConfig.extra.eas.projectId`](/constants/#easconfig) exposed by `expo-constants`.
89
+ *
90
+ * When using EAS Build, this value is automatically set. However, it is
91
+ * **recommended** to set it manually. Once you have EAS Build configured, you can find
92
+ * 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.manifest.projectId`](/constants/#manifest).
94
+ */
95
+ projectId?: string;
96
+ /**
97
+ * The ID of the application to which the token should be attributed.
98
+ * Defaults to [`Application.applicationId`](/application/#applicationapplicationid) exposed by `expo-application`.
99
+ */
100
+ applicationId?: string;
101
+ /**
102
+ * The device push token with which to register at the backend.
103
+ * Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync-devicepushtoken).
104
+ */
105
+ devicePushToken?: DevicePushToken;
106
+ }
54
107
  export {};
55
108
  //# sourceMappingURL=Tokens.types.d.ts.map
@@ -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,MAAM,eAAe,GACvB,kCAAkC,GAClC,kCAAkC,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd"}
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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"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"]}
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 experience to which the token should be attributed.\n * Defaults to [`Constants.manifest.id`](/constants/#constantsmanifest) exposed by `expo-constants`.\n * When building with EAS Build, or in the bare workflow, you must provide a value which takes the shape `@username/projectSlug`,\n * where `username` is the Expo account that the project is associated with, and `projectSlug` is your [`slug`](/config/app.mdx#slug) from Expo config.\n *\n * @deprecated Use `projectId` instead.\n */\n experienceId?: string;\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.manifest.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-devicepushtoken).\n */\n devicePushToken?: DevicePushToken;\n}\n"]}
@@ -1,52 +1,4 @@
1
- import { DevicePushToken, ExpoPushToken } from './Tokens.types';
2
- interface Options {
3
- /**
4
- * Endpoint URL override.
5
- */
6
- baseUrl?: string;
7
- /**
8
- * Request URL override.
9
- */
10
- url?: string;
11
- /**
12
- * Request body override.
13
- */
14
- type?: string;
15
- deviceId?: string;
16
- /**
17
- * Makes sense only on iOS, where there are two push notification services: "sandbox" and "production".
18
- * This defines whether the push token is supposed to be used with the sandbox platform notification service.
19
- * Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](/application/#applicationgetiospushnotificationserviceenvironmentasync)
20
- * exposed by `expo-application` or `false`. Most probably you won't need to customize that.
21
- * You may want to customize that if you don't want to install `expo-application` and still use the sandbox APNs.
22
- * @platform ios
23
- */
24
- development?: boolean;
25
- /**
26
- * @deprecated Use `projectId` instead.
27
- * The ID of the experience to which the token should be attributed.
28
- * Defaults to [`Constants.manifest.id`](/constants/#constantsmanifest) exposed by `expo-constants`.
29
- * When building with EAS Build, or in the bare workflow, **this is required** and you must provide a value which takes the shape `@username/projectSlug`,
30
- * where `username` is the Expo account that the project is associated with, and `projectSlug` is your [`slug`](/config/app.mdx#slug) from Expo config.
31
- */
32
- experienceId?: string;
33
- /**
34
- * The ID of the project to which the token should be attributed.
35
- * Defaults to [`Constants.expoConfig.extra.eas.projectId`](/constants/#easconfig) exposed by `expo-constants`.
36
- * If you are not using EAS Build, it will fallback to [`Constants.manifest.projectId`](/constants/#constantsmanifest).
37
- */
38
- projectId?: string;
39
- /**
40
- * The ID of the application to which the token should be attributed.
41
- * Defaults to [`Application.applicationId`](/application/#applicationapplicationid) exposed by `expo-application`.
42
- */
43
- applicationId?: string;
44
- /**
45
- * The device push token with which to register at the backend.
46
- * Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync-devicepushtoken).
47
- */
48
- devicePushToken?: DevicePushToken;
49
- }
1
+ import { ExpoPushToken, ExpoPushTokenOptions } from './Tokens.types';
50
2
  /**
51
3
  * Returns an Expo token that can be used to send a push notification to the device using Expo's push notifications service.
52
4
  *
@@ -68,7 +20,7 @@ interface Options {
68
20
  *
69
21
  * export async function registerForPushNotificationsAsync(userId: string) {
70
22
  * const expoPushToken = await Notifications.getExpoPushTokenAsync({
71
- * experienceId: '@username/example',
23
+ * projectId: 'your-project-id',
72
24
  * });
73
25
  *
74
26
  * await fetch('https://example.com/', {
@@ -84,6 +36,5 @@ interface Options {
84
36
  * }
85
37
  * ```
86
38
  */
87
- export default function getExpoPushTokenAsync(options?: Options): Promise<ExpoPushToken>;
88
- export {};
39
+ export default function getExpoPushTokenAsync(options?: ExpoPushTokenOptions): Promise<ExpoPushToken>;
89
40
  //# sourceMappingURL=getExpoPushTokenAsync.d.ts.map
@@ -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;IACf;;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;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAA8B,qBAAqB,CAAC,OAAO,GAAE,OAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAgGjG"}
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,CAgGxB"}
@@ -26,7 +26,7 @@ const productionBaseUrl = 'https://exp.host/--/api/v2/';
26
26
  *
27
27
  * export async function registerForPushNotificationsAsync(userId: string) {
28
28
  * const expoPushToken = await Notifications.getExpoPushTokenAsync({
29
- * experienceId: '@username/example',
29
+ * projectId: 'your-project-id',
30
30
  * });
31
31
  *
32
32
  * await fetch('https://example.com/', {
@@ -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,QAA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import 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 /**\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 * @deprecated Use `projectId` instead.\n * The ID of the experience to which the token should be attributed.\n * Defaults to [`Constants.manifest.id`](/constants/#constantsmanifest) exposed by `expo-constants`.\n * When building with EAS Build, or in the bare workflow, **this is required** and you must provide a value which takes the shape `@username/projectSlug`,\n * where `username` is the Expo account that the project is associated with, and `projectSlug` is your [`slug`](/config/app.mdx#slug) from Expo config.\n */\n experienceId?: string;\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 * If you are not using EAS Build, it will fallback to [`Constants.manifest.projectId`](/constants/#constantsmanifest).\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-devicepushtoken).\n */\n devicePushToken?: DevicePushToken;\n}\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 * experienceId: '@username/example',\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(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.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,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ChF;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-notifications",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Notifications module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -57,5 +57,5 @@
57
57
  "peerDependencies": {
58
58
  "expo": "*"
59
59
  },
60
- "gitHead": "1815e2eaad8c753588c7b1eb74420174a28e01f4"
60
+ "gitHead": "1f8a6a09570fd451378565ca34933018ce48454e"
61
61
  }
@@ -62,3 +62,58 @@ export interface ExpoPushToken {
62
62
  */
63
63
  data: string;
64
64
  }
65
+
66
+ export interface ExpoPushTokenOptions {
67
+ /**
68
+ * Endpoint URL override.
69
+ */
70
+ baseUrl?: string;
71
+ /**
72
+ * Request URL override.
73
+ */
74
+ url?: string;
75
+ /**
76
+ * Request body override.
77
+ */
78
+ type?: string;
79
+ // @missingDocs
80
+ deviceId?: string;
81
+ /**
82
+ * Makes sense only on iOS, where there are two push notification services: "sandbox" and "production".
83
+ * This defines whether the push token is supposed to be used with the sandbox platform notification service.
84
+ * Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](/application/#applicationgetiospushnotificationserviceenvironmentasync)
85
+ * exposed by `expo-application` or `false`. Most probably you won't need to customize that.
86
+ * You may want to customize that if you don't want to install `expo-application` and still use the sandbox APNs.
87
+ * @platform ios
88
+ */
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
+ /**
100
+ * The ID of the project to which the token should be attributed.
101
+ * Defaults to [`Constants.expoConfig.extra.eas.projectId`](/constants/#easconfig) exposed by `expo-constants`.
102
+ *
103
+ * When using EAS Build, this value is automatically set. However, it is
104
+ * **recommended** to set it manually. Once you have EAS Build configured, you can find
105
+ * 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.manifest.projectId`](/constants/#manifest).
107
+ */
108
+ projectId?: string;
109
+ /**
110
+ * The ID of the application to which the token should be attributed.
111
+ * Defaults to [`Application.applicationId`](/application/#applicationapplicationid) exposed by `expo-application`.
112
+ */
113
+ applicationId?: string;
114
+ /**
115
+ * The device push token with which to register at the backend.
116
+ * Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync-devicepushtoken).
117
+ */
118
+ devicePushToken?: DevicePushToken;
119
+ }
@@ -4,61 +4,11 @@ import { Platform, CodedError, UnavailabilityError } from 'expo-modules-core';
4
4
 
5
5
  import { setAutoServerRegistrationEnabledAsync } from './DevicePushTokenAutoRegistration.fx';
6
6
  import ServerRegistrationModule from './ServerRegistrationModule';
7
- import { DevicePushToken, ExpoPushToken } from './Tokens.types';
7
+ import { DevicePushToken, ExpoPushToken, ExpoPushTokenOptions } from './Tokens.types';
8
8
  import getDevicePushTokenAsync from './getDevicePushTokenAsync';
9
9
 
10
10
  const productionBaseUrl = 'https://exp.host/--/api/v2/';
11
11
 
12
- interface Options {
13
- /**
14
- * Endpoint URL override.
15
- */
16
- baseUrl?: string;
17
- /**
18
- * Request URL override.
19
- */
20
- url?: string;
21
- /**
22
- * Request body override.
23
- */
24
- type?: string;
25
- // @missingDocs
26
- deviceId?: string;
27
- /**
28
- * Makes sense only on iOS, where there are two push notification services: "sandbox" and "production".
29
- * This defines whether the push token is supposed to be used with the sandbox platform notification service.
30
- * Defaults to [`Application.getIosPushNotificationServiceEnvironmentAsync()`](/application/#applicationgetiospushnotificationserviceenvironmentasync)
31
- * exposed by `expo-application` or `false`. Most probably you won't need to customize that.
32
- * You may want to customize that if you don't want to install `expo-application` and still use the sandbox APNs.
33
- * @platform ios
34
- */
35
- development?: boolean;
36
- /**
37
- * @deprecated Use `projectId` instead.
38
- * The ID of the experience to which the token should be attributed.
39
- * Defaults to [`Constants.manifest.id`](/constants/#constantsmanifest) exposed by `expo-constants`.
40
- * When building with EAS Build, or in the bare workflow, **this is required** and you must provide a value which takes the shape `@username/projectSlug`,
41
- * where `username` is the Expo account that the project is associated with, and `projectSlug` is your [`slug`](/config/app.mdx#slug) from Expo config.
42
- */
43
- experienceId?: string;
44
- /**
45
- * The ID of the project to which the token should be attributed.
46
- * Defaults to [`Constants.expoConfig.extra.eas.projectId`](/constants/#easconfig) exposed by `expo-constants`.
47
- * If you are not using EAS Build, it will fallback to [`Constants.manifest.projectId`](/constants/#constantsmanifest).
48
- */
49
- projectId?: string;
50
- /**
51
- * The ID of the application to which the token should be attributed.
52
- * Defaults to [`Application.applicationId`](/application/#applicationapplicationid) exposed by `expo-application`.
53
- */
54
- applicationId?: string;
55
- /**
56
- * The device push token with which to register at the backend.
57
- * Defaults to a token fetched with [`getDevicePushTokenAsync()`](#getdevicepushtokenasync-devicepushtoken).
58
- */
59
- devicePushToken?: DevicePushToken;
60
- }
61
-
62
12
  /**
63
13
  * Returns an Expo token that can be used to send a push notification to the device using Expo's push notifications service.
64
14
  *
@@ -80,7 +30,7 @@ interface Options {
80
30
  *
81
31
  * export async function registerForPushNotificationsAsync(userId: string) {
82
32
  * const expoPushToken = await Notifications.getExpoPushTokenAsync({
83
- * experienceId: '@username/example',
33
+ * projectId: 'your-project-id',
84
34
  * });
85
35
  *
86
36
  * await fetch('https://example.com/', {
@@ -96,7 +46,9 @@ interface Options {
96
46
  * }
97
47
  * ```
98
48
  */
99
- export default async function getExpoPushTokenAsync(options: Options = {}): Promise<ExpoPushToken> {
49
+ export default async function getExpoPushTokenAsync(
50
+ options: ExpoPushTokenOptions = {}
51
+ ): Promise<ExpoPushToken> {
100
52
  const devicePushToken = options.devicePushToken || (await getDevicePushTokenAsync());
101
53
 
102
54
  const deviceId = options.deviceId || (await getDeviceIdAsync());