expo-pusher-push-notifications 0.5.1 → 0.5.2

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
@@ -7,22 +7,48 @@ Push notifications for Expo and React Native. Two ways to use it:
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.
19
+
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.
25
+
26
+ **Beams (Interests / Users paths only)**
27
+
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.
29
+
30
+ Full details in [Setup](docs/setup.md).
31
+
32
+ ## Install
33
+
10
34
  ```sh
11
35
  npx expo install expo-pusher-push-notifications
12
36
  ```
13
37
 
14
- Needs Expo SDK 58+ and a development build (Expo Go can't load native modules).
38
+ Needs Expo SDK 58+ and a development build (Expo Go can't load native modules). Run `npx expo prebuild` after adding the plugin.
15
39
 
16
- ## Quick start
40
+ ## Getting started
17
41
 
18
- Add the config plugin to `app.json`:
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.
43
+
44
+ ### Interests (Beams topics)
45
+
46
+ `app.json`:
19
47
 
20
48
  ```json
21
49
  ["expo-pusher-push-notifications", { "instanceId": "YOUR_BEAMS_INSTANCE_ID" }]
22
50
  ```
23
51
 
24
- Then in your app:
25
-
26
52
  ```ts
27
53
  import { Interests } from 'expo-pusher-push-notifications';
28
54
 
@@ -30,7 +56,43 @@ await Interests.start('YOUR_BEAMS_INSTANCE_ID');
30
56
  await Interests.subscribe('news');
31
57
  ```
32
58
 
33
- That device now gets pushes sent to `news`. Full console steps (APNs, Firebase, Beams) are in [Setup](docs/setup.md).
59
+ That device now gets pushes sent to `news`.
60
+
61
+ ### Users (Beams, bind to your signed-in user)
62
+
63
+ `app.json`:
64
+
65
+ ```json
66
+ ["expo-pusher-push-notifications", { "instanceId": "YOUR_BEAMS_INSTANCE_ID", "mode": "users" }]
67
+ ```
68
+
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
+ ```
79
+
80
+ That user now gets pushes on every device they're signed in on.
81
+
82
+ ### DeviceToken (no Beams)
83
+
84
+ `app.json` — no `instanceId`:
85
+
86
+ ```json
87
+ ["expo-pusher-push-notifications", { "mode": "device" }]
88
+ ```
89
+
90
+ ```ts
91
+ import { DeviceToken } from 'expo-pusher-push-notifications';
92
+
93
+ const { type, token } = await DeviceToken.start(); // type: 'fcm' | 'apns'
94
+ // send token to your backend, which pushes via FCM / APNs directly
95
+ ```
34
96
 
35
97
  ## Path 1: Pusher Beams
36
98
 
package/docs/direct.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Device token (raw FCM / APNs, no Beams)
2
2
 
3
+
4
+ > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs; no Beams instance needed).
3
5
  **Use this when** your app has its own push path: your backend (or another provider) sends to FCM and APNs directly.
4
6
  No Beams instance needed. You get the raw native token and do what you want with it.
5
7
 
package/docs/interests.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Interests (topics)
2
2
 
3
+
4
+ > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs, plus a Beams instance).
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
+ Pick one (Interests and Users can be combined).
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
+
4
+ > Before you start: finish the [Prerequisites](setup.md#prerequisites) (Firebase + APNs, plus a Beams instance).
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.2",
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",