@arkstack/notifications 0.18.12 → 0.19.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/dist/index.d.ts +424 -8
- package/dist/index.js +626 -76
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,83 @@ import { User as User$1 } from "@arkstack/auth";
|
|
|
8
8
|
import { Attachment } from "nodemailer/lib/mailer/index.js";
|
|
9
9
|
import { PhoneNumber } from "@kanun-hq/plugin-phone";
|
|
10
10
|
import { ArkormCollection, LengthAwarePaginator } from "arkormx";
|
|
11
|
+
//#region src/drivers/realtime/FirebaseDatabaseRealtimeDriver.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Encode a channel name into a single Realtime Database key.
|
|
14
|
+
*
|
|
15
|
+
* @param channel
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
declare const firebaseChannelKey: (channel: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Broadcasts over [Firebase Realtime Database](https://firebase.google.com/docs/database).
|
|
21
|
+
*
|
|
22
|
+
* Each event is written to `{root}/{channel}/{key}` as `{ event, payload, at }`,
|
|
23
|
+
* and indexed under `{index_root}/{key}` so {@link prune} can clear old events in
|
|
24
|
+
* bounded batches. Clients sign in with a custom token from {@link auth}, which
|
|
25
|
+
* also writes a time-limited grant to `{grants_root}/{uid}/{channel}` that the
|
|
26
|
+
* database security rules check before allowing a read.
|
|
27
|
+
*
|
|
28
|
+
* `firebase-admin` is an optional peer dependency, imported lazily.
|
|
29
|
+
*/
|
|
30
|
+
declare class FirebaseDatabaseRealtimeDriver implements RealtimeDriver {
|
|
31
|
+
private options;
|
|
32
|
+
private servicesPromise?;
|
|
33
|
+
constructor(options?: FirebaseDatabaseTransportConfig);
|
|
34
|
+
private get root();
|
|
35
|
+
private get indexRoot();
|
|
36
|
+
private get grantsRoot();
|
|
37
|
+
private get databaseURL();
|
|
38
|
+
private services;
|
|
39
|
+
/**
|
|
40
|
+
* Write the event to every channel in one multi-path update.
|
|
41
|
+
*
|
|
42
|
+
* `delivery` is accepted for contract parity and ignored.
|
|
43
|
+
*
|
|
44
|
+
* @param channel
|
|
45
|
+
* @param event
|
|
46
|
+
* @param payload
|
|
47
|
+
* @param _delivery
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
broadcast(channel: string | string[], event: string, payload: RealtimeBroadcastPayload, _delivery?: RealtimeDeliveryOptions): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Grant `uid` read access to an already authorized channel and mint the
|
|
53
|
+
* custom token the client signs in with.
|
|
54
|
+
*
|
|
55
|
+
* @param uid
|
|
56
|
+
* @param channel
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
auth(uid: string, channel: string): Promise<{
|
|
60
|
+
token: string;
|
|
61
|
+
expires_at: number;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Delete events older than `maxAgeSeconds`, at most `limit` per call. Call it
|
|
65
|
+
* from a scheduled job until it returns 0.
|
|
66
|
+
*
|
|
67
|
+
* @param maxAgeSeconds
|
|
68
|
+
* @param limit
|
|
69
|
+
* @returns The number of events deleted.
|
|
70
|
+
*/
|
|
71
|
+
prune(maxAgeSeconds: number, limit?: number): Promise<number>;
|
|
72
|
+
/**
|
|
73
|
+
* Public settings a browser client needs to read channels.
|
|
74
|
+
*
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
clientConfig(): Record<string, unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* Use `Broadcast.routes()`, which authorizes channels through the registry.
|
|
80
|
+
*
|
|
81
|
+
* @param _authEndpoint
|
|
82
|
+
* @param _middleware
|
|
83
|
+
* @param _channelPrefix
|
|
84
|
+
*/
|
|
85
|
+
registerAuthRoute(_authEndpoint?: string, _middleware?: unknown | unknown[], _channelPrefix?: string): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
11
88
|
//#region src/drivers/realtime/FirebaseRealtimeDriver.d.ts
|
|
12
89
|
/**
|
|
13
90
|
* The outcome of a token multicast: totals plus the tokens FCM rejected as dead.
|
|
@@ -88,6 +165,13 @@ declare class FirebaseRealtimeDriver implements RealtimeDriver {
|
|
|
88
165
|
* @returns
|
|
89
166
|
*/
|
|
90
167
|
private headerBlock;
|
|
168
|
+
/**
|
|
169
|
+
* Public Firebase web settings for clients that receive messages or register
|
|
170
|
+
* device tokens.
|
|
171
|
+
*
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
clientConfig(): Record<string, unknown>;
|
|
91
175
|
/**
|
|
92
176
|
* Firebase channels do not require server-side authorization.
|
|
93
177
|
*
|
|
@@ -120,6 +204,53 @@ declare class FirebaseRealtimeDriver implements RealtimeDriver {
|
|
|
120
204
|
private multicast;
|
|
121
205
|
}
|
|
122
206
|
//#endregion
|
|
207
|
+
//#region src/drivers/realtime/MemoryRealtimeDriver.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* A broadcast recorded by {@link MemoryRealtimeDriver}.
|
|
210
|
+
*/
|
|
211
|
+
interface RecordedBroadcast {
|
|
212
|
+
channel: string | string[];
|
|
213
|
+
event: string;
|
|
214
|
+
payload: RealtimeBroadcastPayload;
|
|
215
|
+
delivery?: RealtimeDeliveryOptions;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Records every broadcast in process instead of sending it, for tests and local
|
|
219
|
+
* development. Read them with {@link MemoryRealtimeDriver.broadcasts}.
|
|
220
|
+
*/
|
|
221
|
+
declare class MemoryRealtimeDriver implements RealtimeDriver {
|
|
222
|
+
/**
|
|
223
|
+
* Every broadcast recorded since the last {@link clear}.
|
|
224
|
+
*
|
|
225
|
+
* @returns
|
|
226
|
+
*/
|
|
227
|
+
static broadcasts(): RecordedBroadcast[];
|
|
228
|
+
/**
|
|
229
|
+
* Forget all recorded broadcasts.
|
|
230
|
+
*/
|
|
231
|
+
static clear(): void;
|
|
232
|
+
broadcast(channel: string | string[], event: string, payload: RealtimeBroadcastPayload, delivery?: RealtimeDeliveryOptions): Promise<void>;
|
|
233
|
+
auth(_socketId: string, channel: string): Promise<{
|
|
234
|
+
auth: string;
|
|
235
|
+
}>;
|
|
236
|
+
registerAuthRoute(): Promise<void>;
|
|
237
|
+
clientConfig(): Record<string, unknown>;
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/drivers/realtime/PollingRealtimeDriver.d.ts
|
|
241
|
+
/**
|
|
242
|
+
* A transport that pushes nothing. Clients are told to poll on an interval
|
|
243
|
+
* instead, so an app works without realtime infrastructure.
|
|
244
|
+
*/
|
|
245
|
+
declare class PollingRealtimeDriver implements RealtimeDriver {
|
|
246
|
+
private options;
|
|
247
|
+
constructor(options?: PollingTransportConfig);
|
|
248
|
+
broadcast(_channel: string | string[], _event: string, _payload: RealtimeBroadcastPayload, _delivery?: RealtimeDeliveryOptions): Promise<void>;
|
|
249
|
+
auth(): Promise<Record<string, never>>;
|
|
250
|
+
registerAuthRoute(): Promise<void>;
|
|
251
|
+
clientConfig(): Record<string, unknown>;
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
123
254
|
//#region src/drivers/realtime/PusherRealtimeDriver.d.ts
|
|
124
255
|
/** The slice of the `pusher` server SDK this driver uses. */
|
|
125
256
|
interface PusherClient {
|
|
@@ -146,6 +277,17 @@ declare class PusherRealtimeDriver implements RealtimeDriver {
|
|
|
146
277
|
private clientPromise?;
|
|
147
278
|
constructor(options?: PusherTransportConfig);
|
|
148
279
|
private client;
|
|
280
|
+
private key;
|
|
281
|
+
private cluster;
|
|
282
|
+
private useTLS;
|
|
283
|
+
private server;
|
|
284
|
+
/**
|
|
285
|
+
* Public settings a `pusher-js` client needs, including the self-hosted
|
|
286
|
+
* server address when `host` is set.
|
|
287
|
+
*
|
|
288
|
+
* @returns
|
|
289
|
+
*/
|
|
290
|
+
clientConfig(): Record<string, unknown>;
|
|
149
291
|
/**
|
|
150
292
|
* `delivery` is accepted for contract parity and ignored: Pusher pushes over a
|
|
151
293
|
* connection the client already holds open, so there is no dozing radio to
|
|
@@ -200,10 +342,18 @@ declare class PusherRealtimeDriver implements RealtimeDriver {
|
|
|
200
342
|
*/
|
|
201
343
|
interface RealtimeDriver {
|
|
202
344
|
broadcast(channel: string | string[], event: string, payload: RealtimeBroadcastPayload, delivery?: RealtimeDeliveryOptions): Promise<unknown>;
|
|
345
|
+
/**
|
|
346
|
+
* Sign or grant access to an already authorized channel. `socketId` is the
|
|
347
|
+
* Pusher socket id, or the subscriber's uid for transports without sockets.
|
|
348
|
+
*/
|
|
203
349
|
auth(socketId: string, channel: string, data?: unknown): unknown | Promise<unknown>;
|
|
204
350
|
registerAuthRoute(authEndpoint?: string, middleware?: unknown | unknown[], channelPrefix?: string): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* Public connection settings a browser client needs. Must never include secrets.
|
|
353
|
+
*/
|
|
354
|
+
clientConfig?(): Record<string, unknown>;
|
|
205
355
|
}
|
|
206
|
-
type RealtimeNotificationDriver<T extends RealtimeDriverName> = T extends 'firebase' ? FirebaseRealtimeDriver : T extends 'pusher' ? PusherRealtimeDriver : RealtimeDriver;
|
|
356
|
+
type RealtimeNotificationDriver<T extends RealtimeDriverName> = T extends 'firebase' ? FirebaseRealtimeDriver : T extends 'firebase-database' ? FirebaseDatabaseRealtimeDriver : T extends 'polling' ? PollingRealtimeDriver : T extends 'memory' ? MemoryRealtimeDriver : T extends 'pusher' ? PusherRealtimeDriver : RealtimeDriver;
|
|
207
357
|
//#endregion
|
|
208
358
|
//#region src/Contracts/UserNotification.d.ts
|
|
209
359
|
declare abstract class UserNotification extends Model {
|
|
@@ -229,7 +379,20 @@ type MailRecipientAddress = Record<string, string>;
|
|
|
229
379
|
type MailRecipient = string | MailRecipientAddress | Array<string | MailRecipientAddress>;
|
|
230
380
|
type NotificationData = Record<string, unknown>;
|
|
231
381
|
type SmsDriverName = 'africastalking' | 'twilio';
|
|
232
|
-
|
|
382
|
+
/**
|
|
383
|
+
* Realtime transports.
|
|
384
|
+
*
|
|
385
|
+
* - `pusher`: Pusher Channels, or any Pusher-protocol server such as soketi.
|
|
386
|
+
* - `firebase`: Firebase Cloud Messaging; delivers to devices, not channels.
|
|
387
|
+
* - `firebase-database`: Firebase Realtime Database channels.
|
|
388
|
+
* - `polling`: no push; clients are told to poll on an interval.
|
|
389
|
+
* - `memory`: records broadcasts in process, for tests.
|
|
390
|
+
*/
|
|
391
|
+
type RealtimeDriverName = 'pusher' | 'firebase' | 'firebase-database' | 'polling' | 'memory';
|
|
392
|
+
/**
|
|
393
|
+
* Transports that can deliver to device registration tokens.
|
|
394
|
+
*/
|
|
395
|
+
type PushDriverName = 'firebase';
|
|
233
396
|
type NotificationChannel = 'mail' | 'sms' | 'db' | 'realtime';
|
|
234
397
|
interface Transport<T = any, D extends TransportOptions = TransportOptions> {
|
|
235
398
|
mailer?: Transporter<T, D> | undefined;
|
|
@@ -282,6 +445,11 @@ type PusherTransportConfig = {
|
|
|
282
445
|
secret?: string;
|
|
283
446
|
cluster?: string;
|
|
284
447
|
use_tls?: boolean;
|
|
448
|
+
/**
|
|
449
|
+
* A self-hosted Pusher-protocol server (e.g. soketi). Overrides `cluster` addressing.
|
|
450
|
+
*/
|
|
451
|
+
host?: string;
|
|
452
|
+
port?: number;
|
|
285
453
|
};
|
|
286
454
|
type FirebaseTransportConfig = {
|
|
287
455
|
project_id?: string;
|
|
@@ -291,6 +459,40 @@ type FirebaseTransportConfig = {
|
|
|
291
459
|
admin_sdk_path?: string;
|
|
292
460
|
/** Delivery options applied to every send on this transport. */
|
|
293
461
|
delivery?: RealtimeDeliveryOptions;
|
|
462
|
+
web?: FirebaseWebConfig;
|
|
463
|
+
};
|
|
464
|
+
/**
|
|
465
|
+
* Public Firebase web app settings handed to browser clients. Never secret.
|
|
466
|
+
*/
|
|
467
|
+
type FirebaseWebConfig = {
|
|
468
|
+
api_key?: string;
|
|
469
|
+
auth_domain?: string;
|
|
470
|
+
app_id?: string;
|
|
471
|
+
messaging_sender_id?: string;
|
|
472
|
+
/** Web push VAPID key clients use to request a messaging token. */
|
|
473
|
+
vapid_key?: string;
|
|
474
|
+
};
|
|
475
|
+
type FirebaseDatabaseTransportConfig = Omit<FirebaseTransportConfig, 'delivery'> & {
|
|
476
|
+
database_url?: string;
|
|
477
|
+
/**
|
|
478
|
+
* Database path that holds channel events (default `arkstack/channels`).
|
|
479
|
+
*/
|
|
480
|
+
root?: string;
|
|
481
|
+
/**
|
|
482
|
+
* Database path that holds per-user channel grants (default `arkstack/grants`).
|
|
483
|
+
*/
|
|
484
|
+
grants_root?: string;
|
|
485
|
+
/**
|
|
486
|
+
* How long, in seconds, a channel grant stays valid (default 3600).
|
|
487
|
+
*/
|
|
488
|
+
grant_ttl?: number;
|
|
489
|
+
web?: FirebaseWebConfig;
|
|
490
|
+
};
|
|
491
|
+
type PollingTransportConfig = {
|
|
492
|
+
/**
|
|
493
|
+
* How often, in milliseconds, clients should poll (default 5000).
|
|
494
|
+
*/
|
|
495
|
+
interval?: number;
|
|
294
496
|
};
|
|
295
497
|
/**
|
|
296
498
|
* Per-send delivery hints for push transports.
|
|
@@ -358,6 +560,9 @@ type RealtimeDriverOptions<T extends RealtimeDriverName = RealtimeDriverName> =
|
|
|
358
560
|
driverFactory?: () => RealtimeDriver;
|
|
359
561
|
pusher?: PusherTransportConfig;
|
|
360
562
|
firebase?: FirebaseTransportConfig;
|
|
563
|
+
'firebase-database'?: FirebaseDatabaseTransportConfig;
|
|
564
|
+
polling?: PollingTransportConfig;
|
|
565
|
+
memory?: Record<string, never>;
|
|
361
566
|
};
|
|
362
567
|
/** The notification payload delivered to realtime clients. */
|
|
363
568
|
type RealtimeNotificationPayload = {
|
|
@@ -395,12 +600,52 @@ type RealtimeNotificationPayload = {
|
|
|
395
600
|
* `listen()`, which has always accepted arbitrary events.
|
|
396
601
|
*/
|
|
397
602
|
type RealtimeBroadcastPayload = RealtimeNotificationPayload | Record<string, unknown>;
|
|
603
|
+
/**
|
|
604
|
+
* The outcome of a device push: totals plus the tokens to prune.
|
|
605
|
+
*/
|
|
606
|
+
type PushResult = {
|
|
607
|
+
successCount: number;
|
|
608
|
+
failureCount: number;
|
|
609
|
+
invalidTokens: string[];
|
|
610
|
+
};
|
|
398
611
|
/** The result of a realtime broadcast (plus the stored record when `store` is on). */
|
|
399
612
|
type RealtimeBroadcastResult = {
|
|
400
613
|
channel: string | string[];
|
|
401
614
|
event: string;
|
|
402
615
|
payload: RealtimeNotificationPayload;
|
|
403
616
|
stored?: UserNotification;
|
|
617
|
+
/** Present when the notification was also pushed to the recipient's devices. */
|
|
618
|
+
push?: PushResult;
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
A device registration token, or a record carrying one.
|
|
622
|
+
*/
|
|
623
|
+
type PushTokenLike = string | {
|
|
624
|
+
token: string;
|
|
625
|
+
};
|
|
626
|
+
/**
|
|
627
|
+
Decides whether a subject (usually the authenticated user) may join a channel.
|
|
628
|
+
*/
|
|
629
|
+
type ChannelAuthorizer<Subject = any> = (subject: Subject, params: Record<string, string>) => boolean | Promise<boolean>;
|
|
630
|
+
/**
|
|
631
|
+
* The body a realtime client posts to the channel auth endpoint.
|
|
632
|
+
*/
|
|
633
|
+
type ChannelAuthRequest = {
|
|
634
|
+
socket_id?: string;
|
|
635
|
+
channel_name?: string;
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* Public connection settings a `@arkstack/realtime` client is created from.
|
|
639
|
+
*/
|
|
640
|
+
type RealtimeClientConfig = {
|
|
641
|
+
transport: RealtimeDriverName;
|
|
642
|
+
event: string;
|
|
643
|
+
channelPrefix: string;
|
|
644
|
+
pusher?: Record<string, unknown>;
|
|
645
|
+
firebase?: Record<string, unknown>;
|
|
646
|
+
'firebase-database'?: Record<string, unknown>;
|
|
647
|
+
polling?: Record<string, unknown>;
|
|
648
|
+
memory?: Record<string, unknown>;
|
|
404
649
|
};
|
|
405
650
|
type DbNotificationType = 'transaction' | 'pocket' | 'family' | 'security' | 'promo' | 'bill' | 'goal' | string;
|
|
406
651
|
type DbNotificationPayload = {
|
|
@@ -438,6 +683,17 @@ interface NotificationConfig<T = any> {
|
|
|
438
683
|
};
|
|
439
684
|
realtime?: {
|
|
440
685
|
transport?: RealtimeDriverName;
|
|
686
|
+
/**
|
|
687
|
+
* Also push notifications sent to a user to their registered devices
|
|
688
|
+
* over this transport. When unset, on only if `transport` is `firebase`;
|
|
689
|
+
* `false` turns it off.
|
|
690
|
+
*/
|
|
691
|
+
push?: PushDriverName | false;
|
|
692
|
+
/**
|
|
693
|
+
* Resolve a user's device tokens for `push`. Defaults to reading
|
|
694
|
+
* `user.pushTokens`.
|
|
695
|
+
*/
|
|
696
|
+
push_tokens?: (user: any) => PushTokenLike[] | Promise<PushTokenLike[]>;
|
|
441
697
|
/** Prefix for the per-user channel/topic (default `user.`). */
|
|
442
698
|
channel_prefix?: string;
|
|
443
699
|
/** Event name clients subscribe to (default `notification`). */
|
|
@@ -509,8 +765,10 @@ interface NotificationConfig<T = any> {
|
|
|
509
765
|
secret: string;
|
|
510
766
|
cluster: string;
|
|
511
767
|
use_tls?: boolean;
|
|
768
|
+
host?: string;
|
|
769
|
+
port?: number;
|
|
512
770
|
};
|
|
513
|
-
firebase?: {
|
|
771
|
+
firebase?: ({
|
|
514
772
|
project_id: string;
|
|
515
773
|
client_email: string;
|
|
516
774
|
private_key: string;
|
|
@@ -518,7 +776,12 @@ interface NotificationConfig<T = any> {
|
|
|
518
776
|
} | {
|
|
519
777
|
app_name?: string;
|
|
520
778
|
admin_sdk_path: string;
|
|
779
|
+
}) & {
|
|
780
|
+
delivery?: RealtimeDeliveryOptions;
|
|
781
|
+
web?: FirebaseWebConfig;
|
|
521
782
|
};
|
|
783
|
+
'firebase-database'?: FirebaseDatabaseTransportConfig;
|
|
784
|
+
polling?: PollingTransportConfig;
|
|
522
785
|
};
|
|
523
786
|
queue?: {
|
|
524
787
|
name?: string;
|
|
@@ -576,8 +839,9 @@ declare class DbNotification extends NotificationContract<UserNotification> {
|
|
|
576
839
|
* Broadcast the notification using the default realtime driver.
|
|
577
840
|
*
|
|
578
841
|
* @param realtime Set to false to disable realtime broadcast
|
|
842
|
+
* @returns
|
|
579
843
|
*/
|
|
580
|
-
broadcast(realtime?: boolean):
|
|
844
|
+
broadcast(realtime?: boolean): this;
|
|
581
845
|
create(user: User, payload: DbNotificationPayload): Promise<UserNotification>;
|
|
582
846
|
/**
|
|
583
847
|
* Send the database notification
|
|
@@ -700,6 +964,8 @@ declare class RealtimeNotification<T extends RealtimeDriverName = RealtimeDriver
|
|
|
700
964
|
private shouldStore;
|
|
701
965
|
private tagName?;
|
|
702
966
|
private isRetraction;
|
|
967
|
+
private shouldPush?;
|
|
968
|
+
private deviceTokens?;
|
|
703
969
|
private deliveryOptions;
|
|
704
970
|
private payload;
|
|
705
971
|
constructor(options?: RealtimeDriverOptions<T>);
|
|
@@ -824,6 +1090,23 @@ declare class RealtimeNotification<T extends RealtimeDriverName = RealtimeDriver
|
|
|
824
1090
|
* @returns
|
|
825
1091
|
*/
|
|
826
1092
|
retract(retract?: boolean): this;
|
|
1093
|
+
/**
|
|
1094
|
+
* Also push this notification to the recipient's devices over the
|
|
1095
|
+
* `drivers.realtime.push` transport. On by default for a `User` recipient
|
|
1096
|
+
* when push is configured; pass `false` to skip it for this send.
|
|
1097
|
+
*
|
|
1098
|
+
* @param push
|
|
1099
|
+
* @returns
|
|
1100
|
+
*/
|
|
1101
|
+
push(push?: boolean): this;
|
|
1102
|
+
/**
|
|
1103
|
+
* Push to these device tokens instead of the recipient's own.
|
|
1104
|
+
*
|
|
1105
|
+
* @param tokens
|
|
1106
|
+
* @returns
|
|
1107
|
+
*/
|
|
1108
|
+
devices(tokens: string[]): this;
|
|
1109
|
+
private resolveDevices;
|
|
827
1110
|
private resolveChannel;
|
|
828
1111
|
/**
|
|
829
1112
|
* Send a realtime notification using the default realtime driver
|
|
@@ -941,17 +1224,150 @@ declare class Notification<D extends keyof DriverMap = keyof DriverMap> {
|
|
|
941
1224
|
private static createDriver;
|
|
942
1225
|
}
|
|
943
1226
|
//#endregion
|
|
1227
|
+
//#region src/Broadcast.d.ts
|
|
1228
|
+
type BroadcastRouteOptions = {
|
|
1229
|
+
/** Route prefix (default `/realtime`). */
|
|
1230
|
+
prefix?: string;
|
|
1231
|
+
/** Extra middleware run before the framework `auth` middleware. */
|
|
1232
|
+
middleware?: unknown | unknown[];
|
|
1233
|
+
};
|
|
1234
|
+
/**
|
|
1235
|
+
* The server side of realtime: builds transports from config, broadcasts
|
|
1236
|
+
* arbitrary events, and authorizes channel subscriptions against registered
|
|
1237
|
+
* channel rules for every transport.
|
|
1238
|
+
*/
|
|
1239
|
+
declare class Broadcast {
|
|
1240
|
+
private static rules;
|
|
1241
|
+
private static settings;
|
|
1242
|
+
/**
|
|
1243
|
+
* The configured streaming transport name.
|
|
1244
|
+
*
|
|
1245
|
+
* @returns
|
|
1246
|
+
*/
|
|
1247
|
+
static transport(): RealtimeDriverName;
|
|
1248
|
+
/**
|
|
1249
|
+
* The prefix of the per-user notification channel.
|
|
1250
|
+
*
|
|
1251
|
+
* @returns
|
|
1252
|
+
*/
|
|
1253
|
+
static channelPrefix(): string;
|
|
1254
|
+
/**
|
|
1255
|
+
* Register who may subscribe to channels matching `pattern`. `{name}`
|
|
1256
|
+
* placeholders match one dot-free segment and are passed to the authorizer.
|
|
1257
|
+
* A later registration of the same pattern replaces the earlier one.
|
|
1258
|
+
*
|
|
1259
|
+
* @param pattern e.g. `private-team.{teamId}`
|
|
1260
|
+
* @param authorizer
|
|
1261
|
+
* @returns
|
|
1262
|
+
*/
|
|
1263
|
+
static channel<Subject = any>(pattern: string, authorizer: ChannelAuthorizer<Subject>): typeof Broadcast;
|
|
1264
|
+
/**
|
|
1265
|
+
* Remove every registered channel rule.
|
|
1266
|
+
*/
|
|
1267
|
+
static forgetChannels(): void;
|
|
1268
|
+
/**
|
|
1269
|
+
* Whether `subject` may subscribe to `channel`. The first matching rule
|
|
1270
|
+
* decides. The per-user notification channel is allowed for its own user
|
|
1271
|
+
* unless a rule overrides it. Unmatched channels are denied.
|
|
1272
|
+
*
|
|
1273
|
+
* @param subject
|
|
1274
|
+
* @param channel
|
|
1275
|
+
* @returns
|
|
1276
|
+
*/
|
|
1277
|
+
static authorize(subject: unknown, channel: string): Promise<boolean>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Build a transport. Uses the configured `driverFactory` when there is one,
|
|
1280
|
+
* otherwise the named or configured built-in.
|
|
1281
|
+
*
|
|
1282
|
+
* @param options
|
|
1283
|
+
* @returns
|
|
1284
|
+
*/
|
|
1285
|
+
static driver(options?: RealtimeDriverOptions): RealtimeDriver;
|
|
1286
|
+
/**
|
|
1287
|
+
* Build a named built-in transport from its `transports.*` config.
|
|
1288
|
+
*
|
|
1289
|
+
* @param transport
|
|
1290
|
+
* @param overrides
|
|
1291
|
+
* @returns
|
|
1292
|
+
*/
|
|
1293
|
+
static make(transport: RealtimeDriverName, overrides?: Record<string, unknown>): RealtimeDriver;
|
|
1294
|
+
/**
|
|
1295
|
+
* Broadcast an arbitrary event on one or more channels over the configured
|
|
1296
|
+
* transport.
|
|
1297
|
+
*
|
|
1298
|
+
* @param channel
|
|
1299
|
+
* @param event
|
|
1300
|
+
* @param payload
|
|
1301
|
+
* @param delivery
|
|
1302
|
+
* @returns
|
|
1303
|
+
*/
|
|
1304
|
+
static broadcast(channel: string | string[], event: string, payload: RealtimeBroadcastPayload, delivery?: RealtimeDeliveryOptions): Promise<unknown>;
|
|
1305
|
+
/**
|
|
1306
|
+
* The device push transport, or null when push is off. When `push` is unset,
|
|
1307
|
+
* apps streaming over `firebase` keep pushing to devices as they always have.
|
|
1308
|
+
*
|
|
1309
|
+
* @returns
|
|
1310
|
+
*/
|
|
1311
|
+
static pushDriver(): FirebaseRealtimeDriver | null;
|
|
1312
|
+
/**
|
|
1313
|
+
* A user's device tokens, from the configured `push_tokens` resolver or the
|
|
1314
|
+
* user's `pushTokens` property.
|
|
1315
|
+
*
|
|
1316
|
+
* @param user
|
|
1317
|
+
* @returns
|
|
1318
|
+
*/
|
|
1319
|
+
static pushTokens(user: unknown): Promise<string[]>;
|
|
1320
|
+
/**
|
|
1321
|
+
* Push an event to device tokens over the push transport. Returns null when
|
|
1322
|
+
* push is off or there are no tokens.
|
|
1323
|
+
*
|
|
1324
|
+
* @param tokens
|
|
1325
|
+
* @param event
|
|
1326
|
+
* @param payload
|
|
1327
|
+
* @param delivery
|
|
1328
|
+
* @returns
|
|
1329
|
+
*/
|
|
1330
|
+
static push(tokens: string[], event: string, payload: RealtimeBroadcastPayload, delivery?: RealtimeDeliveryOptions): Promise<PushResult | null>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Authorize `subject` for the requested channel and return what the active
|
|
1333
|
+
* transport needs: a Pusher signature, a Firebase custom token, or nothing.
|
|
1334
|
+
*
|
|
1335
|
+
* @param subject Usually the authenticated user.
|
|
1336
|
+
* @param request The client's `socket_id` and `channel_name`.
|
|
1337
|
+
* @param options `uid` overrides the Firebase uid (defaults to `subject.id`).
|
|
1338
|
+
* @returns
|
|
1339
|
+
*/
|
|
1340
|
+
static handleAuth(subject: unknown, request: ChannelAuthRequest, options?: {
|
|
1341
|
+
uid?: string;
|
|
1342
|
+
driver?: RealtimeDriver;
|
|
1343
|
+
}): Promise<unknown>;
|
|
1344
|
+
/**
|
|
1345
|
+
* Public settings a `@arkstack/realtime` client is created from.
|
|
1346
|
+
*
|
|
1347
|
+
* @returns
|
|
1348
|
+
*/
|
|
1349
|
+
static clientConfig(): RealtimeClientConfig;
|
|
1350
|
+
/**
|
|
1351
|
+
* Register `POST {prefix}/auth` and `GET {prefix}/config`, both behind the
|
|
1352
|
+
* framework `auth` middleware.
|
|
1353
|
+
*
|
|
1354
|
+
* @param options
|
|
1355
|
+
*/
|
|
1356
|
+
static routes(options?: BroadcastRouteOptions): Promise<void>;
|
|
1357
|
+
}
|
|
1358
|
+
//#endregion
|
|
944
1359
|
//#region src/UserNotificationCenter.d.ts
|
|
945
1360
|
declare class UserNotificationCenter {
|
|
946
1361
|
private static getModel;
|
|
947
1362
|
/**
|
|
948
|
-
*
|
|
1363
|
+
* Store a notification, broadcast it on the user's channel, and push it to
|
|
1364
|
+
* their devices when `drivers.realtime.push` is configured.
|
|
949
1365
|
*
|
|
950
1366
|
* @param user
|
|
951
1367
|
* @param payload
|
|
1368
|
+
* @param devices Push to these tokens instead of the user's own.
|
|
952
1369
|
*/
|
|
953
|
-
static send(user: User, payload: DbNotificationPayload,
|
|
954
|
-
private static resolvePushTokens;
|
|
1370
|
+
static send(user: User, payload: DbNotificationPayload, devices?: string[]): Promise<RealtimeBroadcastResult>;
|
|
955
1371
|
/**
|
|
956
1372
|
* Create a database notification
|
|
957
1373
|
*
|
|
@@ -999,4 +1415,4 @@ declare const configure: <T extends DotPath<NotificationConfig>>(key: T, default
|
|
|
999
1415
|
//#region src/utils/template.d.ts
|
|
1000
1416
|
declare const interpolate: (value: string, data?: NotificationData) => string;
|
|
1001
1417
|
//#endregion
|
|
1002
|
-
export { AfricasTalkingSmsDriver, DbNotification, DbNotificationPayload, DbNotificationType, DriverResult, FirebaseMulticastResult, FirebaseRealtimeDriver, FirebaseTransportConfig, MailDriverOptions, MailNotification, MailNotificationOptions, MailRecipient, MailRecipientAddress, MergedTransportConfig, Notification, NotificationChannel, NotificationConfig, NotificationContract, NotificationData, NotificationDriverMap, NotificationRecipient, PusherRealtimeDriver, PusherTransportConfig, RealtimeBroadcastPayload, RealtimeBroadcastResult, RealtimeDeliveryOptions, RealtimeDriver, RealtimeDriverName, RealtimeDriverOptions, RealtimeNotification, RealtimeNotificationDriver, RealtimeNotificationPayload, SmsDriverName, SmsDriverOptions, SmsNotification, Transport, TwilioSmsDriver, UserNotification, UserNotificationCenter, configure, interpolate };
|
|
1418
|
+
export { AfricasTalkingSmsDriver, Broadcast, BroadcastRouteOptions, ChannelAuthRequest, ChannelAuthorizer, DbNotification, DbNotificationPayload, DbNotificationType, DriverResult, FirebaseDatabaseRealtimeDriver, FirebaseDatabaseTransportConfig, FirebaseMulticastResult, FirebaseRealtimeDriver, FirebaseTransportConfig, FirebaseWebConfig, MailDriverOptions, MailNotification, MailNotificationOptions, MailRecipient, MailRecipientAddress, MemoryRealtimeDriver, MergedTransportConfig, Notification, NotificationChannel, NotificationConfig, NotificationContract, NotificationData, NotificationDriverMap, NotificationRecipient, PollingRealtimeDriver, PollingTransportConfig, PushDriverName, PushResult, PushTokenLike, PusherRealtimeDriver, PusherTransportConfig, RealtimeBroadcastPayload, RealtimeBroadcastResult, RealtimeClientConfig, RealtimeDeliveryOptions, RealtimeDriver, RealtimeDriverName, RealtimeDriverOptions, RealtimeNotification, RealtimeNotificationDriver, RealtimeNotificationPayload, RecordedBroadcast, SmsDriverName, SmsDriverOptions, SmsNotification, Transport, TwilioSmsDriver, UserNotification, UserNotificationCenter, configure, firebaseChannelKey, interpolate };
|