@biltme/backend 0.9.0 → 0.10.0
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 +10 -4
- package/dist/notifications.d.ts +14 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -179,8 +179,9 @@ const { data, error } = await bilt.notifications.send({
|
|
|
179
179
|
body: 'See you at 8',
|
|
180
180
|
data: { chatId: chat.id }, // optional, passed to the app on open
|
|
181
181
|
url: `/chat/${chat.id}`, // optional in-app path a tap opens
|
|
182
|
+
category: 'New messages', // optional: a kind of notification the user can turn off
|
|
182
183
|
})
|
|
183
|
-
// data.outcome: 'accepted' | 'no_devices' | 'notifications_off' | 'platform_off'
|
|
184
|
+
// data.outcome: 'accepted' | 'no_devices' | 'notifications_off' | 'platform_off' | 'opted_out' | 'suspended'
|
|
184
185
|
```
|
|
185
186
|
|
|
186
187
|
A `to` typed as `string` could hold `'all'`, so its answer is typed as either
|
|
@@ -191,9 +192,14 @@ the way the client's other calls are: a `global.headers` Authorization header,
|
|
|
191
192
|
else `accessToken`, else the session, else the client's key. The client's other
|
|
192
193
|
`global.headers` go along. Bilt Cloud accepts the key only from an edge
|
|
193
194
|
function, so an app without a session gets a 403 `auth_role_denied`. `accepted` means
|
|
194
|
-
Apple or Google took the notification, not that it arrived. `
|
|
195
|
+
Apple or Google took the notification, not that it arrived. `suspended` means Bilt has
|
|
196
|
+
stopped push for this app: nothing was sent, and the owner should contact Bilt support. `url` must be an in-app path
|
|
195
197
|
starting with a single `/`, `data` may not have its own `url` key, and the two
|
|
196
|
-
together stay under 2 KB.
|
|
198
|
+
together stay under 2 KB. `category`, at most 64 bytes, names a kind of
|
|
199
|
+
notification such as new messages or daily reminders. A recipient who turned it
|
|
200
|
+
off with `@biltme/notifications-expo`'s `setCategoryEnabled` gets `opted_out`:
|
|
201
|
+
nothing is sent, and the send counts against no limit. On Android the category is
|
|
202
|
+
also the notification channel, shown by this name in system settings. A user may send 10 a minute
|
|
197
203
|
and 200 a day, and a recipient receives at most 30 a minute; over that, `error`
|
|
198
204
|
is a `NotificationsError` with `code` `rate_limited` and `status` 429. The
|
|
199
205
|
method never throws. The app registers devices and handles taps through
|
|
@@ -207,7 +213,7 @@ import { createClient } from 'npm:@biltme/backend'
|
|
|
207
213
|
const bilt = createClient(Deno.env.get('EXPO_PUBLIC_BILT_URL')!, Deno.env.get('BILT_SERVICE_KEY')!)
|
|
208
214
|
await bilt.notifications.send({ to: userId, title: 'Order shipped', body: 'It arrives Friday' })
|
|
209
215
|
const { data } = await bilt.notifications.send({ to: 'all', title: 'We are back', body: 'Service is restored' })
|
|
210
|
-
// data.counts: { accepted, notifications_off, platform_off, error, rate_limited }, in devices
|
|
216
|
+
// data.counts: { accepted, notifications_off, platform_off, error, rate_limited, opted_out, suspended }, in devices
|
|
211
217
|
```
|
|
212
218
|
|
|
213
219
|
A function sends with its `BILT_SERVICE_KEY` and needs no session. Only a
|
package/dist/notifications.d.ts
CHANGED
|
@@ -11,12 +11,20 @@ export type NotificationMessage = {
|
|
|
11
11
|
data?: Record<string, unknown>;
|
|
12
12
|
/** An in-app path such as `/chat/123`, opened on tap. */
|
|
13
13
|
url?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The kind of notification, such as `'New messages'`, at most 64 bytes. A
|
|
16
|
+
* recipient who turned it off gets nothing. On Android it is also the
|
|
17
|
+
* notification channel, which the user sees by this name in system settings.
|
|
18
|
+
*/
|
|
19
|
+
category?: string;
|
|
14
20
|
};
|
|
15
21
|
/**
|
|
16
22
|
* What happened for the recipient. `accepted` means Google or Apple took the
|
|
17
|
-
* notification, not that it arrived.
|
|
23
|
+
* notification, not that it arrived. `opted_out` means the recipient turned
|
|
24
|
+
* the send's category off, and `suspended` that Bilt has stopped push for
|
|
25
|
+
* this app; neither sends anything.
|
|
18
26
|
*/
|
|
19
|
-
export type NotificationOutcome = 'accepted' | 'no_devices' | 'notifications_off' | 'platform_off';
|
|
27
|
+
export type NotificationOutcome = 'accepted' | 'no_devices' | 'notifications_off' | 'platform_off' | 'opted_out' | 'suspended';
|
|
20
28
|
/** A send bilt-cloud refused or never answered, with its error code, such as `rate_limited`. */
|
|
21
29
|
export declare class NotificationsError extends Error {
|
|
22
30
|
readonly status: number;
|
|
@@ -39,6 +47,10 @@ export type NotificationCounts = {
|
|
|
39
47
|
platform_off: number;
|
|
40
48
|
error: number;
|
|
41
49
|
rate_limited: number;
|
|
50
|
+
/** Devices whose user, or the signed-out device itself, turned the send's category off. */
|
|
51
|
+
opted_out: number;
|
|
52
|
+
/** Every device of an app Bilt has stopped push for; then the only nonzero count. */
|
|
53
|
+
suspended: number;
|
|
42
54
|
};
|
|
43
55
|
export type NotificationSendAllResult = {
|
|
44
56
|
data: {
|