expo-notifications 0.16.0 → 0.16.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,10 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 0.16.1 — 2022-07-16
14
+
15
+ _This version does not introduce any user-facing changes._
16
+
13
17
  ## 0.16.0 — 2022-07-07
14
18
 
15
19
  ### 🛠 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.16.1'
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.16.1'
78
78
  }
79
79
 
80
80
  lintOptions {
@@ -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 +1 @@
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,iB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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 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,EAA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,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,IAA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AAC;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 ||\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,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,IAAI,SAAS,CAAC,UAAU,EAAE,gBAAgB,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC;IAE3F,MAAM,SAAS,GACb,OAAO,CAAC,SAAS;Q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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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-notifications",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Notifications module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -58,5 +58,5 @@
58
58
  "peerDependencies": {
59
59
  "expo": "*"
60
60
  },
61
- "gitHead": "6e131f2da851a47c3a24eb3d6fc971a1a7822086"
61
+ "gitHead": "c6678c65b68e45062d49a2deea8e822f69388278"
62
62
  }
@@ -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 ||