@venturekit/notify 0.0.47 → 0.0.48
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 +37 -15
- package/dist/devices/devices.d.ts +10 -9
- package/dist/devices/devices.d.ts.map +1 -1
- package/dist/devices/devices.js +8 -7
- package/dist/devices/devices.js.map +1 -1
- package/dist/devices/index.d.ts +2 -2
- package/dist/devices/index.d.ts.map +1 -1
- package/dist/devices/index.js +1 -1
- package/dist/devices/index.js.map +1 -1
- package/dist/devices/push.d.ts +91 -21
- package/dist/devices/push.d.ts.map +1 -1
- package/dist/devices/push.js +119 -34
- package/dist/devices/push.js.map +1 -1
- package/dist/providers/index.d.ts +3 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/push-apns.d.ts +117 -0
- package/dist/providers/push-apns.d.ts.map +1 -0
- package/dist/providers/push-apns.js +279 -0
- package/dist/providers/push-apns.js.map +1 -0
- package/dist/providers/push-fcm.d.ts +92 -0
- package/dist/providers/push-fcm.d.ts.map +1 -0
- package/dist/providers/push-fcm.js +299 -0
- package/dist/providers/push-fcm.js.map +1 -0
- package/dist/providers/types.d.ts +49 -1
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +2 -1
- package/dist/providers/types.js.map +1 -1
- package/package.json +14 -6
package/README.md
CHANGED
|
@@ -181,7 +181,7 @@ Three persistent failure modes are recorded distinctly:
|
|
|
181
181
|
| `email` | AWS SESv2 (`@aws-sdk/client-sesv2`, lazy-loaded) | ✅ |
|
|
182
182
|
| `whatsapp` | Meta Cloud API (Graph `/messages`, `fetch`) | ✅ |
|
|
183
183
|
| `sms` | `noop-sms` placeholder — logs and returns success | ❌ — register a real provider in your `createNotifyClient({ providers })` array. |
|
|
184
|
-
| `push` |
|
|
184
|
+
| `push` | FCM HTTP v1 (`…/providers/push-fcm`, `fetch`), APNs (`…/providers/push-apns`, `node:http2`), Expo (`…/providers/push-expo`, `fetch`) — or `noop-push` | ✅ — with the device registry below. |
|
|
185
185
|
|
|
186
186
|
The dispatcher uses whichever provider is registered last for a given channel — wire your own SNS / Twilio / Pinpoint provider by passing it in the `providers` array; it overrides the noop.
|
|
187
187
|
|
|
@@ -505,35 +505,57 @@ the categories a user may opt out of; transactional templates are never asked.
|
|
|
505
505
|
## Push devices
|
|
506
506
|
|
|
507
507
|
`@venturekit/notify/devices` keeps the phones a person can be pushed to
|
|
508
|
-
(`vk_push_devices`) and pushes to people rather than to tokens. The app hands its
|
|
509
|
-
|
|
508
|
+
(`vk_push_devices`) and pushes to people rather than to tokens. The app hands its token
|
|
509
|
+
over once signed in and takes it back at sign-out; each row names the provider the token
|
|
510
|
+
belongs to, and a push goes through that provider:
|
|
510
511
|
|
|
511
512
|
```ts
|
|
512
|
-
import { registerPushDevice, revokePushDevice, pushToUsers } from '@venturekit/notify/devices';
|
|
513
|
+
import { registerPushDevice, revokePushDevice, pushToUsers, nativePushProvider } from '@venturekit/notify/devices';
|
|
513
514
|
|
|
514
|
-
// PUT /me/push-device
|
|
515
|
-
await registerPushDevice(tx.query, { userId, tenantId, token, platform:
|
|
515
|
+
// PUT /me/push-device — the app's native token (expo-notifications' getDevicePushTokenAsync)
|
|
516
|
+
await registerPushDevice(tx.query, { userId, tenantId, token, platform, provider: nativePushProvider(platform), app: 'driver', locale: 'fr' });
|
|
516
517
|
// DELETE /me/push-device — while the session can still say so
|
|
517
518
|
await revokePushDevice(tx.query, { userId, tenantId, token });
|
|
518
519
|
|
|
519
|
-
// every live phone of these people,
|
|
520
|
-
const sent = await pushToUsers(tx.query, { userIds, tenantId, app: 'driver', message: { title, body, data: { tripId } } }, {
|
|
520
|
+
// every live phone of these people, each through its provider; a token the provider says is gone is revoked
|
|
521
|
+
const sent = await pushToUsers(tx.query, { userIds, tenantId, app: 'driver', message: { title, body, data: { tripId } } }, {
|
|
522
|
+
fcm: { serviceAccount: firebaseKeyJson, format: 'expo-notifications' },
|
|
523
|
+
apns: { key: { teamId, keyId, privateKey: p8 }, environment: 'production', format: 'expo-notifications', topics: { driver: 'com.acme.driver' } },
|
|
524
|
+
});
|
|
521
525
|
```
|
|
522
526
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
527
|
+
| `provider` | Sent through | Credentials | Answer |
|
|
528
|
+
| --- | --- | --- | --- |
|
|
529
|
+
| `fcm` | Firebase Cloud Messaging HTTP v1, one request per token | the Firebase service-account key (an OAuth token is minted from it and cached) | final, per token |
|
|
530
|
+
| `apns` | Apple's push service over HTTP/2, to the app's bundle id (`topics[app]`, else `topic`) | an APNs auth key (`.p8`, key id, team id; an ES256 provider token is signed and cached) | final, per token |
|
|
531
|
+
| `expo` | Expo's push service, 100 tokens per request | an Expo access token when the project enforces one | a ticket; the receipt later (`reconcilePushTickets`) |
|
|
532
|
+
|
|
533
|
+
`format: 'expo-notifications'` lays the payload out the way `expo-notifications` reads a
|
|
534
|
+
native push (a data-only FCM message; the payload under `body` on iOS), so the app finds it in
|
|
535
|
+
`notification.request.content.data` as it did through Expo; `'standard'` (the default) is the
|
|
536
|
+
platforms' own notification fields. A provider left out of the config is not a failure of the
|
|
537
|
+
others: its devices come back `not_configured`, kept. Credentials that cannot work throw before
|
|
538
|
+
anything is sent. `sendPushToDevices(targets, message, config)` is the same send for a product
|
|
539
|
+
that has read the devices itself.
|
|
540
|
+
|
|
541
|
+
- **The token is the key, per tenant.** An install hands the same token back on every launch
|
|
542
|
+
(until FCM rotates it — register on every launch), so registering again is a `lastSeenAt`;
|
|
543
|
+
a token registered by someone else is re-pointed to them — the phone was handed over —
|
|
544
|
+
never kept for both.
|
|
526
545
|
- **Revoked, never deleted**, with a reason (`signed_out`, `device_gone`, `user_removed`,
|
|
527
546
|
`stale`): "why does my phone not ring" has an answer. `revokeUserPushDevices` when an
|
|
528
547
|
account goes, `revokePushTokens` for what the provider reports dead, `prunePushDevices`
|
|
529
548
|
in a cron (revoke what is unseen for months, delete what was revoked long ago),
|
|
530
549
|
`forgetPushDevices` for an erasure request.
|
|
531
|
-
- **
|
|
532
|
-
|
|
533
|
-
a device
|
|
550
|
+
- **An accepted push is not a read one.** FCM and APNs answer finally at the send (`gone`
|
|
551
|
+
tokens are revoked by `pushToUsers`, `retryable` refusals counted apart). Expo answers with
|
|
552
|
+
a ticket per device; keep them and ask for their receipts a few minutes later with
|
|
553
|
+
`reconcilePushTickets`, which revokes a device the receipt says is gone. None says the
|
|
554
|
+
person saw it.
|
|
534
555
|
- **Through the outbox**, with retries and an audit row per phone: give the client the
|
|
535
556
|
directory, and a push to a person fans out at `enqueue`; the dispatcher revokes a token
|
|
536
|
-
the provider reports gone (`PushDeviceGoneError`).
|
|
557
|
+
the provider reports gone (`PushDeviceGoneError`). The outbox takes one push provider
|
|
558
|
+
(`createFcmPushProvider`, `createApnsPushProvider({ topic })` or `createExpoPushProvider`).
|
|
537
559
|
|
|
538
560
|
```ts
|
|
539
561
|
const notify = createNotifyClient({ store, providers: [createExpoPushProvider()], pushDevices: pushDeviceDirectory(tx.query, { tenantId }) });
|
|
@@ -4,18 +4,19 @@
|
|
|
4
4
|
* ```ts
|
|
5
5
|
* import { registerPushDevice, revokePushDevice, pushToUsers } from '@venturekit/notify/devices';
|
|
6
6
|
*
|
|
7
|
-
* // PUT /me/push-device — the app, once signed in, hands its Expo token
|
|
8
|
-
*
|
|
7
|
+
* // PUT /me/push-device — the app, once signed in, hands its token over (an Expo token, or the
|
|
8
|
+
* // native one: provider: nativePushProvider(platform) → 'fcm' / 'apns')
|
|
9
|
+
* await registerPushDevice(tx.query, { userId, tenantId, token, platform: 'android', provider: 'fcm', app: 'driver', locale: 'fr' });
|
|
9
10
|
*
|
|
10
11
|
* // DELETE /me/push-device — at sign-out, while the session can still say so
|
|
11
12
|
* await revokePushDevice(tx.query, { userId, tenantId, token });
|
|
12
13
|
*
|
|
13
|
-
* // every live phone of these people; a token
|
|
14
|
-
* await pushToUsers(tx.query, { userIds, tenantId, message: { title, body, data } }, {
|
|
14
|
+
* // every live phone of these people, each through its provider; a token the provider says is gone is revoked on the spot
|
|
15
|
+
* await pushToUsers(tx.query, { userIds, tenantId, message: { title, body, data } }, { fcm, apns });
|
|
15
16
|
* ```
|
|
16
17
|
*
|
|
17
|
-
* The token is the key, per tenant.
|
|
18
|
-
*
|
|
18
|
+
* The token is the key, per tenant. An install hands the same token back on every launch
|
|
19
|
+
* (until FCM rotates it), so registering again is a `last_seen_at`; a token registered by someone else is
|
|
19
20
|
* re-pointed to whoever registered it last — the phone was handed over — rather than kept for
|
|
20
21
|
* both. Rows are revoked with a reason, never deleted, except by {@link prunePushDevices}
|
|
21
22
|
* (long-revoked rows) and {@link forgetPushDevices} (an erasure request).
|
|
@@ -46,10 +47,10 @@ export interface PushDevice {
|
|
|
46
47
|
export interface RegisterPushDeviceInput {
|
|
47
48
|
userId: string;
|
|
48
49
|
tenantId?: string | null;
|
|
49
|
-
/** The provider's token
|
|
50
|
+
/** The provider's token: an Expo push token (`ExponentPushToken[…]`), an FCM registration token, an APNs device token. */
|
|
50
51
|
token: string;
|
|
51
52
|
platform: PushPlatform;
|
|
52
|
-
/** Default `'expo'`. */
|
|
53
|
+
/** Whose token it is — `'expo'`, `'fcm'`, `'apns'` (what `pushToUsers` routes on). Default `'expo'`. */
|
|
53
54
|
provider?: string;
|
|
54
55
|
/** Which of the product's apps it is, when there are several. */
|
|
55
56
|
app?: string | null;
|
|
@@ -73,7 +74,7 @@ export declare function revokePushDevice(querier: Querier, input: {
|
|
|
73
74
|
reason?: PushRevocationReason;
|
|
74
75
|
}): Promise<boolean>;
|
|
75
76
|
/**
|
|
76
|
-
* Tokens the provider says are dead (`DeviceNotRegistered
|
|
77
|
+
* Tokens the provider says are dead (Expo's `DeviceNotRegistered`, FCM's `UNREGISTERED`, APNs' `Unregistered`), whoever
|
|
77
78
|
* holds them: a token gone is gone in every tenant that has it. Returns how many rows went.
|
|
78
79
|
*/
|
|
79
80
|
export declare function revokePushTokens(querier: Querier, input: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../src/devices/devices.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../src/devices/devices.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAEzE,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,CAAC;AAErD,iIAAiI;AACjI,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,aAAa,GAAG,cAAc,GAAG,OAAO,CAAC;AAE3F,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,YAAY,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,EAAE,IAAI,CAAC;IACjB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0HAA0H;IAC1H,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,YAAY,CAAC;IACvB,wGAAwG;IACxG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,qGAAqG;IACrG,MAAM,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AAG,IAAI,CAAC;IACzB,+BAA+B;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,uDAAuD;AACvD,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAgB9G;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAO,GACtE,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB/C;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED,wGAAwG;AACxG,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,mBAAmB,CAUjI"}
|
package/dist/devices/devices.js
CHANGED
|
@@ -4,18 +4,19 @@
|
|
|
4
4
|
* ```ts
|
|
5
5
|
* import { registerPushDevice, revokePushDevice, pushToUsers } from '@venturekit/notify/devices';
|
|
6
6
|
*
|
|
7
|
-
* // PUT /me/push-device — the app, once signed in, hands its Expo token
|
|
8
|
-
*
|
|
7
|
+
* // PUT /me/push-device — the app, once signed in, hands its token over (an Expo token, or the
|
|
8
|
+
* // native one: provider: nativePushProvider(platform) → 'fcm' / 'apns')
|
|
9
|
+
* await registerPushDevice(tx.query, { userId, tenantId, token, platform: 'android', provider: 'fcm', app: 'driver', locale: 'fr' });
|
|
9
10
|
*
|
|
10
11
|
* // DELETE /me/push-device — at sign-out, while the session can still say so
|
|
11
12
|
* await revokePushDevice(tx.query, { userId, tenantId, token });
|
|
12
13
|
*
|
|
13
|
-
* // every live phone of these people; a token
|
|
14
|
-
* await pushToUsers(tx.query, { userIds, tenantId, message: { title, body, data } }, {
|
|
14
|
+
* // every live phone of these people, each through its provider; a token the provider says is gone is revoked on the spot
|
|
15
|
+
* await pushToUsers(tx.query, { userIds, tenantId, message: { title, body, data } }, { fcm, apns });
|
|
15
16
|
* ```
|
|
16
17
|
*
|
|
17
|
-
* The token is the key, per tenant.
|
|
18
|
-
*
|
|
18
|
+
* The token is the key, per tenant. An install hands the same token back on every launch
|
|
19
|
+
* (until FCM rotates it), so registering again is a `last_seen_at`; a token registered by someone else is
|
|
19
20
|
* re-pointed to whoever registered it last — the phone was handed over — rather than kept for
|
|
20
21
|
* both. Rows are revoked with a reason, never deleted, except by {@link prunePushDevices}
|
|
21
22
|
* (long-revoked rows) and {@link forgetPushDevices} (an erasure request).
|
|
@@ -89,7 +90,7 @@ export async function revokePushDevice(querier, input) {
|
|
|
89
90
|
return rows.length > 0;
|
|
90
91
|
}
|
|
91
92
|
/**
|
|
92
|
-
* Tokens the provider says are dead (`DeviceNotRegistered
|
|
93
|
+
* Tokens the provider says are dead (Expo's `DeviceNotRegistered`, FCM's `UNREGISTERED`, APNs' `Unregistered`), whoever
|
|
93
94
|
* holds them: a token gone is gone in every tenant that has it. Returns how many rows went.
|
|
94
95
|
*/
|
|
95
96
|
export async function revokePushTokens(querier, input) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devices.js","sourceRoot":"","sources":["../../src/devices/devices.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"devices.js","sourceRoot":"","sources":["../../src/devices/devices.ts"],"names":[],"mappings":"AAAA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gB,EAChB,UAAqE,EAAE;IAEvE,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,MAAM,OAAO,CACzB;;oBAEc,EACd,CAAC,OAAO,CAAC,aAAa,CAAC,CACxB,CAAC;QACF,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,OAAO,CACxB,0HAA0H,EAC1H,CAAC,OAAO,CAAC,oBAAoB,IAAI,EAAE,CAAC,CACrC,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAC3C,CAAC;AAaD,wGAAwG;AACxG,MAAM,UAAU,mBAAmB,CAAC,OAAgB,EAAE,QAAoD,EAAE;IAC1G,OAAO;QACL,KAAK,CAAC,SAAS,CAAC,MAAM;YACpB,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;YAChH,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,MAAM,gBAAgB,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QAC/F,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/devices/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { registerPushDevice, revokePushDevice, revokePushTokens, revokeUserPushDevices, forgetPushDevices, listPushDevices, prunePushDevices, pushDeviceDirectory, } from './devices.js';
|
|
2
2
|
export type { PushDevice, PushPlatform, PushRevocationReason, RegisterPushDeviceInput, ListPushDevicesOptions, PushDeviceDirectory, } from './devices.js';
|
|
3
|
-
export { pushToUsers, reconcilePushTickets } from './push.js';
|
|
4
|
-
export type { PushMessage, PushToUsersInput, PushToUsersResult, PushTicketOutcome, PushReceiptsSummary } from './push.js';
|
|
3
|
+
export { pushToUsers, sendPushToDevices, nativePushProvider, reconcilePushTickets } from './push.js';
|
|
4
|
+
export type { PushMessage, PushConfig, PushTarget, PushDeviceOutcome, PushToUsersInput, PushToUsersResult, PushTicketOutcome, PushReceiptsSummary, } from './push.js';
|
|
5
5
|
export type { Querier as DevicesQuerier } from '../querier.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACrG,YAAY,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/devices/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { registerPushDevice, revokePushDevice, revokePushTokens, revokeUserPushDevices, forgetPushDevices, listPushDevices, prunePushDevices, pushDeviceDirectory, } from './devices.js';
|
|
2
|
-
export { pushToUsers, reconcilePushTickets } from './push.js';
|
|
2
|
+
export { pushToUsers, sendPushToDevices, nativePushProvider, reconcilePushTickets } from './push.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAStB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAStB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/devices/push.d.ts
CHANGED
|
@@ -1,24 +1,88 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pushing to people rather than to tokens: every live phone of each,
|
|
3
|
-
*
|
|
2
|
+
* Pushing to people rather than to tokens: every live phone of each, through the provider its
|
|
3
|
+
* token belongs to, and a token the provider says is gone revoked in the same call.
|
|
4
4
|
*
|
|
5
5
|
* Two ways to push with this package, for two kinds of product:
|
|
6
6
|
*
|
|
7
7
|
* - **through the outbox** — `createNotifyClient({ pushDevices: pushDeviceDirectory(q) })`, then
|
|
8
8
|
* `enqueue({ channel: 'push', recipientUserId })` writes a row per phone, the dispatcher sends
|
|
9
|
-
* them with retries and revokes a gone token. Audit, retries, scheduling.
|
|
10
|
-
* - **directly** — {@link pushToUsers}, for a product whose own table is the outbox
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* them with retries and revokes a gone token. Audit, retries, scheduling. One push provider.
|
|
10
|
+
* - **directly** — {@link pushToUsers}, for a product whose own table is the outbox, or for a
|
|
11
|
+
* message that is only worth sending now; {@link sendPushToDevices} when the product has
|
|
12
|
+
* already read the devices itself.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* ### Providers
|
|
15
|
+
*
|
|
16
|
+
* A device row names its provider (`vk_push_devices.provider`):
|
|
17
|
+
*
|
|
18
|
+
* - `expo` — Expo's push service (`providers/push-expo.ts`), many tokens per request. Its
|
|
19
|
+
* answer is a *ticket*; whether APNs / FCM took the message is in a receipt minutes later
|
|
20
|
+
* ({@link reconcilePushTickets}).
|
|
21
|
+
* - `fcm` — Firebase Cloud Messaging directly (`providers/push-fcm.ts`): an Android app's
|
|
22
|
+
* native token (`getDevicePushTokenAsync`). Final answer per token.
|
|
23
|
+
* - `apns` — Apple's push service directly (`providers/push-apns.ts`): an iOS app's native
|
|
24
|
+
* token, sent to the app's bundle id ({@link PushConfig.apns} `topics`). Final answer per token.
|
|
25
|
+
*
|
|
26
|
+
* A provider the config does not set up is not a failure of the others: its devices come back
|
|
27
|
+
* refused with `not_configured`, kept, not revoked. {@link nativePushProvider} is which native
|
|
28
|
+
* provider a platform's token is for, at registration.
|
|
29
|
+
*
|
|
30
|
+
* Neither kind of answer says the person saw the message.
|
|
17
31
|
*/
|
|
18
32
|
import { type ExpoPushConfig, type ExpoPushMessage } from '../providers/push-expo.js';
|
|
33
|
+
import { type FcmPushConfig } from '../providers/push-fcm.js';
|
|
34
|
+
import { type ApnsPushConfig } from '../providers/push-apns.js';
|
|
19
35
|
import type { Querier } from '../querier.js';
|
|
20
|
-
|
|
36
|
+
import { type PushPlatform } from './devices.js';
|
|
37
|
+
/** The message, for every phone: the provider-neutral fields less the address. */
|
|
21
38
|
export type PushMessage = Omit<ExpoPushMessage, 'to'>;
|
|
39
|
+
/**
|
|
40
|
+
* How to reach each provider. Expo's fields stay at the top level (`accessToken`, `fetchImpl`),
|
|
41
|
+
* as before; `fcm` and `apns` are set up only when the product has native tokens.
|
|
42
|
+
*/
|
|
43
|
+
export interface PushConfig extends ExpoPushConfig {
|
|
44
|
+
fcm?: FcmPushConfig;
|
|
45
|
+
apns?: ApnsPushConfig & {
|
|
46
|
+
/** The bundle id per app (`vk_push_devices.app`): an iOS push must name the app it is for. Falls back to `topic`. */
|
|
47
|
+
topics?: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** The native provider a platform's own token belongs to: Apple's on iOS, Firebase's elsewhere. */
|
|
51
|
+
export declare function nativePushProvider(platform: PushPlatform): 'apns' | 'fcm';
|
|
52
|
+
/** A device to push to, as {@link sendPushToDevices} takes it. */
|
|
53
|
+
export interface PushTarget {
|
|
54
|
+
token: string;
|
|
55
|
+
/** `vk_push_devices.provider`. */
|
|
56
|
+
provider: string;
|
|
57
|
+
/** `vk_push_devices.app`: picks the APNs topic. */
|
|
58
|
+
app?: string | null;
|
|
59
|
+
}
|
|
60
|
+
/** What became of the push for one device. */
|
|
61
|
+
export interface PushDeviceOutcome {
|
|
62
|
+
token: string;
|
|
63
|
+
provider: string;
|
|
64
|
+
/** The provider's id for the accepted message: Expo's ticket id, FCM's message name, APNs' `apns-id`. */
|
|
65
|
+
messageId: string | null;
|
|
66
|
+
/** Expo only: the ticket id, which is also the receipt id to reconcile. `null` for providers that answer finally. */
|
|
67
|
+
ticketId: string | null;
|
|
68
|
+
/** The provider's reason, when it refused. */
|
|
69
|
+
error: string | null;
|
|
70
|
+
/** The token is dead at the provider. */
|
|
71
|
+
gone: boolean;
|
|
72
|
+
/** A refusal a later attempt may get through. */
|
|
73
|
+
retryable: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Send one message to these devices, each through its provider; one outcome per device, in
|
|
77
|
+
* order. Revokes nothing — the caller decides what to do with `gone`.
|
|
78
|
+
*
|
|
79
|
+
* Everything that can fail for a whole provider is done first (FCM's access token, APNs'
|
|
80
|
+
* provider token), so a throw leaves nothing sent: {@link ProviderHardError} for credentials
|
|
81
|
+
* that cannot work, {@link ProviderSendError} for an outage worth retrying — and Expo's
|
|
82
|
+
* transport failure, as `sendExpoPush` throws it, which is sent first for the same reason.
|
|
83
|
+
* After that, a refusal is data.
|
|
84
|
+
*/
|
|
85
|
+
export declare function sendPushToDevices(targets: readonly PushTarget[], message: PushMessage, config?: PushConfig): Promise<PushDeviceOutcome[]>;
|
|
22
86
|
export interface PushToUsersInput {
|
|
23
87
|
userIds: readonly string[];
|
|
24
88
|
tenantId?: string | null;
|
|
@@ -29,31 +93,36 @@ export interface PushToUsersInput {
|
|
|
29
93
|
export interface PushTicketOutcome {
|
|
30
94
|
userId: string;
|
|
31
95
|
token: string;
|
|
32
|
-
|
|
96
|
+
provider: string;
|
|
97
|
+
/** The provider's id for the accepted message. */
|
|
98
|
+
messageId: string | null;
|
|
99
|
+
/** Expo's ticket id — the receipt id — when it accepted the message; `null` for the native providers, whose answer is final. */
|
|
33
100
|
ticketId: string | null;
|
|
34
|
-
/**
|
|
101
|
+
/** The provider's reason, when it refused it. */
|
|
35
102
|
error: string | null;
|
|
36
103
|
}
|
|
37
104
|
export interface PushToUsersResult {
|
|
38
105
|
/** Live devices found for these people. */
|
|
39
106
|
devices: number;
|
|
40
|
-
/** Devices
|
|
107
|
+
/** Devices a provider accepted the message for. */
|
|
41
108
|
sent: number;
|
|
42
109
|
/** Devices it refused. */
|
|
43
110
|
failed: number;
|
|
111
|
+
/** Of `failed`, the refusals a later attempt may get through (rate limit, outage, network). */
|
|
112
|
+
retryable: number;
|
|
44
113
|
/** Devices it said are gone, revoked now. */
|
|
45
114
|
revoked: number;
|
|
46
115
|
/** One per device, for a caller that keeps ticket ids to reconcile later. */
|
|
47
116
|
tickets: PushTicketOutcome[];
|
|
48
117
|
}
|
|
49
118
|
/**
|
|
50
|
-
* Send one message to every live device of these people.
|
|
119
|
+
* Send one message to every live device of these people, through each device's provider.
|
|
51
120
|
*
|
|
52
|
-
* Throws what
|
|
53
|
-
*
|
|
54
|
-
* refusal is data, in `tickets`.
|
|
121
|
+
* Throws what {@link sendPushToDevices} throws — credentials that cannot work, an outage before
|
|
122
|
+
* the first send, Expo's transport failure — having sent nothing and revoked nothing. A
|
|
123
|
+
* per-device refusal is data, in `tickets`.
|
|
55
124
|
*/
|
|
56
|
-
export declare function pushToUsers(querier: Querier, input: PushToUsersInput, config?:
|
|
125
|
+
export declare function pushToUsers(querier: Querier, input: PushToUsersInput, config?: PushConfig): Promise<PushToUsersResult>;
|
|
57
126
|
export interface PushReceiptsSummary {
|
|
58
127
|
/** Tickets whose receipt says the gateway took the message. */
|
|
59
128
|
ok: number;
|
|
@@ -70,9 +139,10 @@ export interface PushReceiptsSummary {
|
|
|
70
139
|
}>;
|
|
71
140
|
}
|
|
72
141
|
/**
|
|
73
|
-
* The second half of a direct send: Expo's receipts for tickets {@link pushToUsers}
|
|
74
|
-
* (and the caller kept), a gone device revoked. Ask from a couple of minutes after the
|
|
75
|
-
* Expo's advice — until about a day after it.
|
|
142
|
+
* The second half of a direct send to Expo: Expo's receipts for tickets {@link pushToUsers}
|
|
143
|
+
* returned (and the caller kept), a gone device revoked. Ask from a couple of minutes after the
|
|
144
|
+
* send — Expo's advice — until about a day after it. FCM and APNs answer finally at the send;
|
|
145
|
+
* they have no tickets to reconcile.
|
|
76
146
|
*/
|
|
77
147
|
export declare function reconcilePushTickets(querier: Querier, input: {
|
|
78
148
|
tickets: ReadonlyArray<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/devices/push.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/devices/push.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAqD,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACzI,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEjF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAqC,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAEpF,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,UAAW,SAAQ,cAAc;IAChD,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,IAAI,CAAC,EAAE,cAAc,GAAG;QACtB,qHAAqH;QACrH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACjC,CAAC;CACH;AAED,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,GAAG,KAAK,CAEzE;AAED,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,M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;IAChB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,+FAA+F;IAC/F,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,GAAE,UAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuBhI;AAED,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,EAAE,EAAE,MAAM,CAAC;IACX,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;CAC5E;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE;IAAE,OAAO,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAChG,MAAM,GAAE,cAAmB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAwB9B"}
|
package/dist/devices/push.js
CHANGED
|
@@ -1,60 +1,145 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pushing to people rather than to tokens: every live phone of each,
|
|
3
|
-
*
|
|
2
|
+
* Pushing to people rather than to tokens: every live phone of each, through the provider its
|
|
3
|
+
* token belongs to, and a token the provider says is gone revoked in the same call.
|
|
4
4
|
*
|
|
5
5
|
* Two ways to push with this package, for two kinds of product:
|
|
6
6
|
*
|
|
7
7
|
* - **through the outbox** — `createNotifyClient({ pushDevices: pushDeviceDirectory(q) })`, then
|
|
8
8
|
* `enqueue({ channel: 'push', recipientUserId })` writes a row per phone, the dispatcher sends
|
|
9
|
-
* them with retries and revokes a gone token. Audit, retries, scheduling.
|
|
10
|
-
* - **directly** — {@link pushToUsers}, for a product whose own table is the outbox
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* them with retries and revokes a gone token. Audit, retries, scheduling. One push provider.
|
|
10
|
+
* - **directly** — {@link pushToUsers}, for a product whose own table is the outbox, or for a
|
|
11
|
+
* message that is only worth sending now; {@link sendPushToDevices} when the product has
|
|
12
|
+
* already read the devices itself.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* ### Providers
|
|
15
|
+
*
|
|
16
|
+
* A device row names its provider (`vk_push_devices.provider`):
|
|
17
|
+
*
|
|
18
|
+
* - `expo` — Expo's push service (`providers/push-expo.ts`), many tokens per request. Its
|
|
19
|
+
* answer is a *ticket*; whether APNs / FCM took the message is in a receipt minutes later
|
|
20
|
+
* ({@link reconcilePushTickets}).
|
|
21
|
+
* - `fcm` — Firebase Cloud Messaging directly (`providers/push-fcm.ts`): an Android app's
|
|
22
|
+
* native token (`getDevicePushTokenAsync`). Final answer per token.
|
|
23
|
+
* - `apns` — Apple's push service directly (`providers/push-apns.ts`): an iOS app's native
|
|
24
|
+
* token, sent to the app's bundle id ({@link PushConfig.apns} `topics`). Final answer per token.
|
|
25
|
+
*
|
|
26
|
+
* A provider the config does not set up is not a failure of the others: its devices come back
|
|
27
|
+
* refused with `not_configured`, kept, not revoked. {@link nativePushProvider} is which native
|
|
28
|
+
* provider a platform's token is for, at registration.
|
|
29
|
+
*
|
|
30
|
+
* Neither kind of answer says the person saw the message.
|
|
17
31
|
*/
|
|
18
|
-
import { fetchExpoPushReceipts, isDeviceGone, sendExpoPush
|
|
32
|
+
import { fetchExpoPushReceipts, isDeviceGone, sendExpoPush } from '../providers/push-expo.js';
|
|
33
|
+
import { prepareFcmPush } from '../providers/push-fcm.js';
|
|
34
|
+
import { prepareApnsPush } from '../providers/push-apns.js';
|
|
19
35
|
import { listPushDevices, revokePushTokens } from './devices.js';
|
|
36
|
+
/** The native provider a platform's own token belongs to: Apple's on iOS, Firebase's elsewhere. */
|
|
37
|
+
export function nativePushProvider(platform) {
|
|
38
|
+
return platform === 'ios' ? 'apns' : 'fcm';
|
|
39
|
+
}
|
|
40
|
+
const refused = (target, error) => ({
|
|
41
|
+
token: target.token,
|
|
42
|
+
provider: target.provider,
|
|
43
|
+
messageId: null,
|
|
44
|
+
ticketId: null,
|
|
45
|
+
error,
|
|
46
|
+
gone: false,
|
|
47
|
+
retryable: false,
|
|
48
|
+
});
|
|
49
|
+
const fromNative = (target, outcome) => outcome
|
|
50
|
+
? { token: target.token, provider: target.provider, messageId: outcome.messageId, ticketId: null, error: outcome.error, gone: outcome.gone, retryable: outcome.retryable }
|
|
51
|
+
: { ...refused(target, 'no answer'), retryable: true };
|
|
52
|
+
/**
|
|
53
|
+
* Send one message to these devices, each through its provider; one outcome per device, in
|
|
54
|
+
* order. Revokes nothing — the caller decides what to do with `gone`.
|
|
55
|
+
*
|
|
56
|
+
* Everything that can fail for a whole provider is done first (FCM's access token, APNs'
|
|
57
|
+
* provider token), so a throw leaves nothing sent: {@link ProviderHardError} for credentials
|
|
58
|
+
* that cannot work, {@link ProviderSendError} for an outage worth retrying — and Expo's
|
|
59
|
+
* transport failure, as `sendExpoPush` throws it, which is sent first for the same reason.
|
|
60
|
+
* After that, a refusal is data.
|
|
61
|
+
*/
|
|
62
|
+
export async function sendPushToDevices(targets, message, config = {}) {
|
|
63
|
+
const out = new Map();
|
|
64
|
+
const expo = targets.filter((t) => t.provider === 'expo');
|
|
65
|
+
const fcm = targets.filter((t) => t.provider === 'fcm');
|
|
66
|
+
const apns = targets.filter((t) => t.provider === 'apns');
|
|
67
|
+
for (const t of targets) {
|
|
68
|
+
if (t.provider !== 'expo' && t.provider !== 'fcm' && t.provider !== 'apns')
|
|
69
|
+
out.set(t, refused(t, 'unsupported_provider'));
|
|
70
|
+
}
|
|
71
|
+
const sendFcm = fcm.length > 0 && config.fcm ? await prepareFcmPush(config.fcm) : null;
|
|
72
|
+
const sendApns = apns.length > 0 && config.apns ? prepareApnsPush(config.apns) : null;
|
|
73
|
+
if (expo.length > 0) {
|
|
74
|
+
const tickets = await sendExpoPush(expo.map((t) => ({ ...message, to: t.token })), config);
|
|
75
|
+
expo.forEach((t, i) => {
|
|
76
|
+
const ticket = tickets[i]?.ticket;
|
|
77
|
+
const ok = ticket?.status === 'ok' && Boolean(ticket.id);
|
|
78
|
+
out.set(t, {
|
|
79
|
+
token: t.token,
|
|
80
|
+
provider: 'expo',
|
|
81
|
+
messageId: ok ? ticket.id : null,
|
|
82
|
+
ticketId: ok ? ticket.id : null,
|
|
83
|
+
error: ok ? null : (ticket?.details?.error ?? ticket?.message ?? 'unknown error'),
|
|
84
|
+
gone: isDeviceGone(ticket),
|
|
85
|
+
retryable: false,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (fcm.length > 0) {
|
|
90
|
+
if (!sendFcm)
|
|
91
|
+
fcm.forEach((t) => out.set(t, refused(t, 'not_configured')));
|
|
92
|
+
else {
|
|
93
|
+
const answers = await sendFcm(fcm.map((t) => ({ ...message, to: t.token })));
|
|
94
|
+
fcm.forEach((t, i) => out.set(t, fromNative(t, answers[i])));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (apns.length > 0) {
|
|
98
|
+
if (!sendApns)
|
|
99
|
+
apns.forEach((t) => out.set(t, refused(t, 'not_configured')));
|
|
100
|
+
else {
|
|
101
|
+
const topics = config.apns?.topics ?? {};
|
|
102
|
+
const answers = await sendApns(apns.map((t) => ({ ...message, to: t.token, ...(t.app && topics[t.app] ? { topic: topics[t.app] } : {}) })));
|
|
103
|
+
apns.forEach((t, i) => out.set(t, fromNative(t, answers[i])));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return targets.map((t) => out.get(t) ?? refused(t, 'unsupported_provider'));
|
|
107
|
+
}
|
|
20
108
|
/**
|
|
21
|
-
* Send one message to every live device of these people.
|
|
109
|
+
* Send one message to every live device of these people, through each device's provider.
|
|
22
110
|
*
|
|
23
|
-
* Throws what
|
|
24
|
-
*
|
|
25
|
-
* refusal is data, in `tickets`.
|
|
111
|
+
* Throws what {@link sendPushToDevices} throws — credentials that cannot work, an outage before
|
|
112
|
+
* the first send, Expo's transport failure — having sent nothing and revoked nothing. A
|
|
113
|
+
* per-device refusal is data, in `tickets`.
|
|
26
114
|
*/
|
|
27
115
|
export async function pushToUsers(querier, input, config = {}) {
|
|
28
|
-
const devices =
|
|
29
|
-
const result = { devices: devices.length, sent: 0, failed: 0, revoked: 0, tickets: [] };
|
|
116
|
+
const devices = await listPushDevices(querier, { userIds: input.userIds, tenantId: input.tenantId, app: input.app });
|
|
117
|
+
const result = { devices: devices.length, sent: 0, failed: 0, retryable: 0, revoked: 0, tickets: [] };
|
|
30
118
|
if (devices.length === 0)
|
|
31
119
|
return result;
|
|
32
|
-
const
|
|
33
|
-
const answers = await sendExpoPush(devices.map((d) => ({ ...input.message, to: d.token })), config);
|
|
120
|
+
const outcomes = await sendPushToDevices(devices.map((d) => ({ token: d.token, provider: d.provider, app: d.app })), input.message, config);
|
|
34
121
|
const gone = [];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (ok)
|
|
122
|
+
outcomes.forEach((o, i) => {
|
|
123
|
+
if (o.messageId)
|
|
38
124
|
result.sent += 1;
|
|
39
|
-
else
|
|
125
|
+
else {
|
|
40
126
|
result.failed += 1;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
token
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
}
|
|
127
|
+
if (o.retryable)
|
|
128
|
+
result.retryable += 1;
|
|
129
|
+
}
|
|
130
|
+
if (o.gone)
|
|
131
|
+
gone.push(o.token);
|
|
132
|
+
result.tickets.push({ userId: devices[i].userId, token: o.token, provider: o.provider, messageId: o.messageId, ticketId: o.ticketId, error: o.error });
|
|
133
|
+
});
|
|
50
134
|
if (gone.length > 0)
|
|
51
135
|
result.revoked = await revokePushTokens(querier, { tokens: gone, tenantId: input.tenantId, reason: 'device_gone' });
|
|
52
136
|
return result;
|
|
53
137
|
}
|
|
54
138
|
/**
|
|
55
|
-
* The second half of a direct send: Expo's receipts for tickets {@link pushToUsers}
|
|
56
|
-
* (and the caller kept), a gone device revoked. Ask from a couple of minutes after the
|
|
57
|
-
* Expo's advice — until about a day after it.
|
|
139
|
+
* The second half of a direct send to Expo: Expo's receipts for tickets {@link pushToUsers}
|
|
140
|
+
* returned (and the caller kept), a gone device revoked. Ask from a couple of minutes after the
|
|
141
|
+
* send — Expo's advice — until about a day after it. FCM and APNs answer finally at the send;
|
|
142
|
+
* they have no tickets to reconcile.
|
|
58
143
|
*/
|
|
59
144
|
export async function reconcilePushTickets(querier, input, config = {}) {
|
|
60
145
|
const summary = { ok: 0, failed: 0, gone: 0, pending: 0, receipts: {} };
|