expo-pusher-push-notifications 0.5.2 → 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,33 +1,23 @@
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
- ## Prerequisites
11
-
12
- Do these before installing. Which ones you need depends on your path.
13
-
14
- **Android (all paths)**
15
-
16
- 1. Create a project in the [Firebase console](https://console.firebase.google.com) and add an Android app with your `android.package`.
17
- 2. Download `google-services.json` into your project and set `"android": { "googleServicesFile": "./google-services.json" }` in `app.json`.
18
- 3. Beams path only: in Firebase → Project settings → Service accounts, generate a private key (JSON). You'll upload it to Beams.
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.
19
11
 
20
- **Apple (all paths)**
21
-
22
- 1. In your Apple Developer account, enable the **Push Notifications** capability on your App ID (`ios.bundleIdentifier`).
23
- 2. Create an **APNs auth key (.p8)** under Keys (note the Key ID and Team ID). A .p12 certificate works too, but the key is simpler and doesn't expire.
24
- 3. Set `apsEnvironment` in the plugin: `development` for dev builds, `production` for TestFlight / App Store. The plugin writes the `aps-environment` entitlement for you.
12
+ ## Prerequisites
25
13
 
26
- **Beams (Interests / Users paths only)**
14
+ Links only; set up what your path needs.
27
15
 
28
- Create a Beams instance in the [Pusher dashboard](https://dashboard.pusher.com/beams), upload your APNs key and FCM service account JSON, and copy the instance ID. Skip this entirely for the device-token path.
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).
29
19
 
30
- Full details in [Setup](docs/setup.md).
20
+ More detail in [Setup](docs/setup.md#prerequisites).
31
21
 
32
22
  ## Install
33
23
 
@@ -37,110 +27,101 @@ npx expo install expo-pusher-push-notifications
37
27
 
38
28
  Needs Expo SDK 58+ and a development build (Expo Go can't load native modules). Run `npx expo prebuild` after adding the plugin.
39
29
 
40
- ## Getting started
30
+ ## Beams path
41
31
 
42
- Pick the path that matches how you send pushes. You can combine Interests and Users; DeviceToken is for when you don't use Beams at all.
32
+ Use Pusher Beams to push to topics (interests) and/or to your signed-in users.
43
33
 
44
- ### Interests (Beams topics)
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):
45
35
 
46
- `app.json`:
36
+ ```json
37
+ ["expo-pusher-push-notifications", { "instanceId": "YOUR_BEAMS_INSTANCE_ID", "apsEnvironment": "development" }]
38
+ ```
47
39
 
48
- ```json
49
- ["expo-pusher-push-notifications", { "instanceId": "YOUR_BEAMS_INSTANCE_ID" }]
50
- ```
51
-
52
- ```ts
53
- import { Interests } from 'expo-pusher-push-notifications';
54
-
55
- await Interests.start('YOUR_BEAMS_INSTANCE_ID');
56
- await Interests.subscribe('news');
57
- ```
40
+ 2. **Prebuild and build** a development build: `npx expo prebuild`.
58
41
 
59
- That device now gets pushes sent to `news`.
42
+ 3. **Start Beams and subscribe to interests** (topics like `news`, `order-42`):
60
43
 
61
- ### Users (Beams, bind to your signed-in user)
44
+ ```ts
45
+ import { Interests } from 'expo-pusher-push-notifications';
62
46
 
63
- `app.json`:
47
+ await Interests.start('YOUR_BEAMS_INSTANCE_ID'); // asks for permission
48
+ await Interests.subscribe('news');
49
+ await Interests.unsubscribe('news');
50
+ ```
64
51
 
65
- ```json
66
- ["expo-pusher-push-notifications", { "instanceId": "YOUR_BEAMS_INSTANCE_ID", "mode": "users" }]
67
- ```
52
+ 4. **Bind the device to your signed-in user** (optional), so pushes for that user reach all their devices:
68
53
 
69
- ```ts
70
- import { Users } from 'expo-pusher-push-notifications';
71
-
72
- await Users.start('YOUR_BEAMS_INSTANCE_ID');
73
- // after your own sign-in; url = your Beams token provider
74
- await Users.login('user-123', {
75
- url: 'YOUR_BEAMS_TOKEN_URL',
76
- headers: { Authorization: `Bearer ${sessionToken}` },
77
- });
78
- ```
54
+ ```ts
55
+ import { Users } from 'expo-pusher-push-notifications';
79
56
 
80
- That user now gets pushes on every device they're signed in on.
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
+ ```
81
64
 
82
- ### DeviceToken (no Beams)
65
+ 5. **On sign-out**, clear state:
83
66
 
84
- `app.json` — no `instanceId`:
67
+ ```ts
68
+ await Users.logout();
69
+ await Interests.reset();
70
+ ```
85
71
 
86
- ```json
87
- ["expo-pusher-push-notifications", { "mode": "device" }]
88
- ```
72
+ 6. **Send pushes** from your server with the Beams API (to interests or user IDs).
89
73
 
90
- ```ts
91
- import { DeviceToken } from 'expo-pusher-push-notifications';
74
+ More in [Interests](docs/interests.md) and [Users](docs/users.md).
92
75
 
93
- const { type, token } = await DeviceToken.start(); // type: 'fcm' | 'apns'
94
- // send token to your backend, which pushes via FCM / APNs directly
95
- ```
76
+ ## Device token path
96
77
 
97
- ## Path 1: Pusher Beams
78
+ Get the raw FCM (Android) / APNs (iOS) token and push from your own backend. No Beams, no `expo-notifications`, no EAS.
98
79
 
99
- ### Subscribe to interests (topics)
80
+ 1. **Add the plugin** in `app.json` with `"mode": "device"` and no `instanceId`:
100
81
 
101
- Interests are topics like `news`, `order-42`, or `team-7`. Every device subscribed to one gets the push.
82
+ ```json
83
+ ["expo-pusher-push-notifications", { "mode": "device", "apsEnvironment": "development" }]
84
+ ```
102
85
 
103
- ```ts
104
- await Interests.subscribe('order-42');
105
- await Interests.unsubscribe('order-42');
106
- ```
86
+ 2. **Prebuild and build** a development build: `npx expo prebuild`.
107
87
 
108
- More in [Interests](docs/interests.md).
88
+ 3. **Get the token** and send it to your backend:
109
89
 
110
- ### Bind a device to a user
90
+ ```ts
91
+ import { DeviceToken } from 'expo-pusher-push-notifications';
111
92
 
112
- To get pushes meant for a specific signed-in user on all their devices, bind the device to that user.
93
+ const token = await DeviceToken.start(); // { type: 'fcm' | 'apns', platform, token }
94
+ await api.saveDevice(token);
95
+ ```
113
96
 
114
- ```ts
115
- import { Users } from 'expo-pusher-push-notifications';
97
+ 4. **Keep it fresh** — tokens rotate:
116
98
 
117
- await Users.start('YOUR_BEAMS_INSTANCE_ID');
99
+ ```ts
100
+ DeviceToken.onChange((t) => api.saveDevice(t));
101
+ ```
118
102
 
119
- // after your own sign-in (url = your Beams token provider)
120
- await Users.login('user-123', {
121
- url: 'YOUR_BEAMS_TOKEN_URL',
122
- headers: { Authorization: `Bearer ${sessionToken}` },
123
- });
103
+ 5. **On sign-out**, delete it: `await DeviceToken.delete();`
124
104
 
125
- // on sign-out
126
- await Users.logout();
127
- ```
105
+ 6. **Send pushes** from your backend directly to FCM / APNs with that token.
128
106
 
129
- You can use interests and users together. More in [Users](docs/users.md).
107
+ More in [Device token](docs/direct.md).
130
108
 
131
- ## Path 2: Device token
109
+ ## Using both together
132
110
 
133
- No Beams instance needed (leave `instanceId` out of the plugin config).
111
+ Follow the Beams path, then also grab the raw token. `registerForDeviceToken()` works in any mode, so it doesn't stop Beams:
134
112
 
135
113
  ```ts
136
- 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');
137
118
 
138
- const token = await DeviceToken.start(); // { type: 'fcm' | 'apns', platform, token }
139
- DeviceToken.onChange((t) => { /* token rotated */ });
140
- 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));
141
122
  ```
142
123
 
143
- 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.
144
125
 
145
126
  ## Extras
146
127
 
package/docs/direct.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Device token (raw FCM / APNs, no Beams)
2
2
 
3
-
4
3
  > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs; no Beams instance needed).
4
+
5
5
  **Use this when** your app has its own push path: your backend (or another provider) sends to FCM and APNs directly.
6
+
6
7
  No Beams instance needed. You get the raw native token and do what you want with it.
7
8
 
8
9
  ## Client
package/docs/interests.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Interests (topics)
2
2
 
3
-
4
3
  > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs, plus a Beams instance).
4
+
5
5
  Use interests when many devices should get the same push. Think topics: `news`, `order-42`, `team-7`.
6
6
 
7
7
  ## Client
package/docs/setup.md CHANGED
@@ -73,7 +73,7 @@ The plugin also adds the `remote-notification` background mode on iOS. On Androi
73
73
 
74
74
  ## Start, per path
75
75
 
76
- Pick one (Interests and Users can be combined).
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
77
 
78
78
  | Path | Plugin config | First call |
79
79
  |---|---|---|
package/docs/users.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Bind a device to a user
2
2
 
3
-
4
3
  > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs, plus a Beams instance).
4
+
5
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.
6
6
 
7
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.2",
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",