expo-pusher-push-notifications 0.5.1 → 0.5.3

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/README.md CHANGED
@@ -1,84 +1,127 @@
1
1
  # expo-pusher-push-notifications
2
2
 
3
- Push notifications for Expo and React Native. Two ways to use it:
3
+ Push notifications for Expo and React Native, with two independent paths:
4
4
 
5
- 1. **Pusher Beams** — subscribe devices to interests (topics) and/or bind them to your signed-in users. Uses [Pusher Beams](https://pusher.com/beams).
6
- 2. **Device token** — get the raw FCM (Android) / APNs (iOS) token for your own push path. No Beams, no `expo-notifications`, no EAS.
5
+ - **Pusher Beams** — subscribe devices to interests (topics) and/or bind them to your signed-in users. Uses [Pusher Beams](https://pusher.com/beams).
6
+ - **Device token** — get the raw FCM (Android) / APNs (iOS) token for your own push path. No Beams, no `expo-notifications`, no EAS.
7
7
 
8
8
  Both get custom sounds, Android channels, badges, and local notifications.
9
9
 
10
+ You can use **either or both**: Beams only, device token only, or Beams and device token together in the same app. The two paths are independent, and each section below is self-contained, so follow only the one(s) you need.
11
+
12
+ ## Prerequisites
13
+
14
+ Links only; set up what your path needs.
15
+
16
+ - [Android: Firebase / FCM setup](https://firebase.google.com/docs/android/setup) — create a Firebase project and add `google-services.json` (all paths).
17
+ - [Apple: APNs setup](https://developer.apple.com/documentation/usernotifications/registering-your-app-with-apns) — enable Push Notifications and create an APNs key (all paths).
18
+ - [Pusher Beams instance setup](https://pusher.com/docs/beams/getting-started/create-instance/) — create an instance and upload your FCM / APNs credentials (Beams path only).
19
+
20
+ More detail in [Setup](docs/setup.md#prerequisites).
21
+
22
+ ## Install
23
+
10
24
  ```sh
11
25
  npx expo install expo-pusher-push-notifications
12
26
  ```
13
27
 
14
- Needs Expo SDK 58+ and a development build (Expo Go can't load native modules).
28
+ Needs Expo SDK 58+ and a development build (Expo Go can't load native modules). Run `npx expo prebuild` after adding the plugin.
15
29
 
16
- ## Quick start
30
+ ## Beams path
17
31
 
18
- Add the config plugin to `app.json`:
32
+ Use Pusher Beams to push to topics (interests) and/or to your signed-in users.
19
33
 
20
- ```json
21
- ["expo-pusher-push-notifications", { "instanceId": "YOUR_BEAMS_INSTANCE_ID" }]
22
- ```
34
+ 1. **Add the plugin with your Beams instance ID** in `app.json`. Add `"mode": "users"` if you bind users (interests still work in that mode):
23
35
 
24
- Then in your app:
36
+ ```json
37
+ ["expo-pusher-push-notifications", { "instanceId": "YOUR_BEAMS_INSTANCE_ID", "apsEnvironment": "development" }]
38
+ ```
25
39
 
26
- ```ts
27
- import { Interests } from 'expo-pusher-push-notifications';
40
+ 2. **Prebuild and build** a development build: `npx expo prebuild`.
28
41
 
29
- await Interests.start('YOUR_BEAMS_INSTANCE_ID');
30
- await Interests.subscribe('news');
31
- ```
42
+ 3. **Start Beams and subscribe to interests** (topics like `news`, `order-42`):
32
43
 
33
- That device now gets pushes sent to `news`. Full console steps (APNs, Firebase, Beams) are in [Setup](docs/setup.md).
44
+ ```ts
45
+ import { Interests } from 'expo-pusher-push-notifications';
34
46
 
35
- ## Path 1: Pusher Beams
47
+ await Interests.start('YOUR_BEAMS_INSTANCE_ID'); // asks for permission
48
+ await Interests.subscribe('news');
49
+ await Interests.unsubscribe('news');
50
+ ```
36
51
 
37
- ### Subscribe to interests (topics)
52
+ 4. **Bind the device to your signed-in user** (optional), so pushes for that user reach all their devices:
38
53
 
39
- Interests are topics like `news`, `order-42`, or `team-7`. Every device subscribed to one gets the push.
54
+ ```ts
55
+ import { Users } from 'expo-pusher-push-notifications';
40
56
 
41
- ```ts
42
- await Interests.subscribe('order-42');
43
- await Interests.unsubscribe('order-42');
44
- ```
57
+ await Users.start('YOUR_BEAMS_INSTANCE_ID');
58
+ // after your own sign-in; url = your Beams token provider
59
+ await Users.login('user-123', {
60
+ url: 'YOUR_BEAMS_TOKEN_URL',
61
+ headers: { Authorization: `Bearer ${sessionToken}` },
62
+ });
63
+ ```
45
64
 
46
- More in [Interests](docs/interests.md).
65
+ 5. **On sign-out**, clear state:
47
66
 
48
- ### Bind a device to a user
67
+ ```ts
68
+ await Users.logout();
69
+ await Interests.reset();
70
+ ```
49
71
 
50
- To get pushes meant for a specific signed-in user on all their devices, bind the device to that user.
72
+ 6. **Send pushes** from your server with the Beams API (to interests or user IDs).
51
73
 
52
- ```ts
53
- import { Users } from 'expo-pusher-push-notifications';
74
+ More in [Interests](docs/interests.md) and [Users](docs/users.md).
54
75
 
55
- await Users.start('YOUR_BEAMS_INSTANCE_ID');
76
+ ## Device token path
56
77
 
57
- // after your own sign-in (url = your Beams token provider)
58
- await Users.login('user-123', {
59
- url: 'YOUR_BEAMS_TOKEN_URL',
60
- headers: { Authorization: `Bearer ${sessionToken}` },
61
- });
78
+ Get the raw FCM (Android) / APNs (iOS) token and push from your own backend. No Beams, no `expo-notifications`, no EAS.
62
79
 
63
- // on sign-out
64
- await Users.logout();
65
- ```
80
+ 1. **Add the plugin** in `app.json` with `"mode": "device"` and no `instanceId`:
81
+
82
+ ```json
83
+ ["expo-pusher-push-notifications", { "mode": "device", "apsEnvironment": "development" }]
84
+ ```
85
+
86
+ 2. **Prebuild and build** a development build: `npx expo prebuild`.
87
+
88
+ 3. **Get the token** and send it to your backend:
89
+
90
+ ```ts
91
+ import { DeviceToken } from 'expo-pusher-push-notifications';
92
+
93
+ const token = await DeviceToken.start(); // { type: 'fcm' | 'apns', platform, token }
94
+ await api.saveDevice(token);
95
+ ```
96
+
97
+ 4. **Keep it fresh** — tokens rotate:
66
98
 
67
- You can use interests and users together. More in [Users](docs/users.md).
99
+ ```ts
100
+ DeviceToken.onChange((t) => api.saveDevice(t));
101
+ ```
68
102
 
69
- ## Path 2: Device token
103
+ 5. **On sign-out**, delete it: `await DeviceToken.delete();`
70
104
 
71
- No Beams instance needed (leave `instanceId` out of the plugin config).
105
+ 6. **Send pushes** from your backend directly to FCM / APNs with that token.
106
+
107
+ More in [Device token](docs/direct.md).
108
+
109
+ ## Using both together
110
+
111
+ Follow the Beams path, then also grab the raw token. `registerForDeviceToken()` works in any mode, so it doesn't stop Beams:
72
112
 
73
113
  ```ts
74
- import { DeviceToken } from 'expo-pusher-push-notifications';
114
+ import { Interests, registerForDeviceToken, DeviceToken } from 'expo-pusher-push-notifications';
115
+
116
+ await Interests.start('YOUR_BEAMS_INSTANCE_ID');
117
+ await Interests.subscribe('news');
75
118
 
76
- const token = await DeviceToken.start(); // { type: 'fcm' | 'apns', platform, token }
77
- DeviceToken.onChange((t) => { /* token rotated */ });
78
- await DeviceToken.delete(); // on sign-out
119
+ const token = await registerForDeviceToken(); // raw FCM / APNs token
120
+ await api.saveDevice(token);
121
+ DeviceToken.onChange((t) => api.saveDevice(t));
79
122
  ```
80
123
 
81
- You get the token in the app; sending it to your backend and pushing from there is up to you. More in [Device token](docs/direct.md).
124
+ Keep the plugin config from the Beams path (with `instanceId`). Don't call `DeviceToken.start()` here, as that switches the module to device-only mode.
82
125
 
83
126
  ## Extras
84
127
 
package/docs/direct.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Device token (raw FCM / APNs, no Beams)
2
2
 
3
+ > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs; no Beams instance needed).
4
+
3
5
  **Use this when** your app has its own push path: your backend (or another provider) sends to FCM and APNs directly.
6
+
4
7
  No Beams instance needed. You get the raw native token and do what you want with it.
5
8
 
6
9
  ## Client
package/docs/interests.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Interests (topics)
2
2
 
3
+ > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs, plus a Beams instance).
4
+
3
5
  Use interests when many devices should get the same push. Think topics: `news`, `order-42`, `team-7`.
4
6
 
5
7
  ## Client
package/docs/setup.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Setup
2
2
 
3
+ ## Prerequisites
4
+
5
+ Set these up first. Android and Apple steps apply to every path; the Beams step only to Interests / Users.
6
+
7
+ ### Android: Firebase / FCM
8
+
9
+ 1. Create a project in the [Firebase console](https://console.firebase.google.com).
10
+ 2. Add an Android app whose package name matches `android.package` in `app.json`.
11
+ 3. Download `google-services.json`, put it in your project root, and set `"android": { "googleServicesFile": "./google-services.json" }`.
12
+ 4. **Beams only:** Project settings → Service accounts → *Generate new private key*. Keep the JSON for the Beams dashboard.
13
+
14
+ ### Apple: APNs
15
+
16
+ 1. In [Apple Developer → Identifiers](https://developer.apple.com/account/resources/identifiers/list), open your App ID (`ios.bundleIdentifier`) and enable **Push Notifications**.
17
+ 2. Under Keys, create a key with **Apple Push Notifications service (APNs)** enabled. Download the `.p8` and note the Key ID and your Team ID. (A `.p12` APNs certificate also works, but certificates expire yearly.)
18
+ 3. Choose `apsEnvironment` in the plugin config: `development` for dev builds, `production` for TestFlight and the App Store. The plugin writes the `aps-environment` entitlement and the `remote-notification` background mode — you don't edit Xcode by hand.
19
+ 4. Test on a real device; the iOS simulator doesn't get APNs tokens reliably.
20
+
21
+ ### Beams (Interests / Users only)
22
+
23
+ Create an instance in the [Pusher dashboard](https://dashboard.pusher.com/beams), upload the APNs key (with Key ID / Team ID) and the FCM service account JSON, and copy the instance ID. For the device-token path, skip this — your backend talks to FCM / APNs with those same credentials.
24
+
3
25
  ## Install
4
26
 
5
27
  ```sh
@@ -31,6 +53,8 @@ npx expo install expo-pusher-push-notifications
31
53
  }
32
54
  ```
33
55
 
56
+ Leave out `instanceId` (and set `"mode": "device"`) if you use the device-token path.
57
+
34
58
  Then run `npx expo prebuild` and build a development build. Expo Go cannot load this native module.
35
59
 
36
60
  ### Plugin options
@@ -47,11 +71,15 @@ Then run `npx expo prebuild` and build a development build. Expo Go cannot load
47
71
 
48
72
  The plugin also adds the `remote-notification` background mode on iOS. On Android, the library manifest declares one FCM service (it extends the Beams `MessagingService`), the `POST_NOTIFICATIONS` permission, and a receiver for scheduled local notifications.
49
73
 
50
- ## Console setup
74
+ ## Start, per path
51
75
 
52
- 1. **iOS:** enable the Push Notifications capability. The plugin sets the entitlement. Create an APNs auth key (.p8).
53
- 2. **Android:** create a Firebase project, download `google-services.json`, and point `android.googleServicesFile` at it.
54
- 3. **Beams path only:** create a Beams instance in the [Pusher dashboard](https://dashboard.pusher.com/beams), then upload your APNs key and your FCM service account to it.
76
+ The Beams paths (Interests, Users) and the DeviceToken path are independent: use either or both. To use both, start Beams and call `registerForDeviceToken()` (works in any mode) instead of `DeviceToken.start()`.
77
+
78
+ | Path | Plugin config | First call |
79
+ |---|---|---|
80
+ | Interests | `instanceId` | `Interests.start(instanceId)` then `Interests.subscribe('news')` — see [Interests](interests.md) |
81
+ | Users | `instanceId`, `mode: "users"` | `Users.start(instanceId)` then `Users.login(userId, tokenProvider)` after sign-in — see [Users](users.md) |
82
+ | DeviceToken | `mode: "device"`, no `instanceId` | `DeviceToken.start()` → send `token` to your backend — see [Device token](direct.md) |
55
83
 
56
84
  ## Permissions
57
85
 
package/docs/users.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Bind a device to a user
2
2
 
3
+ > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs, plus a Beams instance).
4
+
3
5
  Bind the device to the signed-in user so pushes for that user reach every device they're signed in on. Call `Users.login` after your own sign-in, and `Users.logout` on sign-out.
4
6
 
5
7
  ## In the app
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-pusher-push-notifications",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Push notifications for Expo: Pusher Beams (interests / users) or raw FCM/APNs device tokens (no EAS needed), with custom sounds, channels, badges and local notifications",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",