@arkstack/notifications 0.17.12 → 0.17.14
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 +37 -0
- package/dist/index.js +48 -1
- package/package.json +12 -4
package/dist/index.d.ts
CHANGED
|
@@ -392,6 +392,20 @@ declare class FirebaseRealtimeDriver implements RealtimeDriver {
|
|
|
392
392
|
}
|
|
393
393
|
//#endregion
|
|
394
394
|
//#region src/drivers/realtime/PusherRealtimeDriver.d.ts
|
|
395
|
+
/** The slice of the `pusher` server SDK this driver uses. */
|
|
396
|
+
interface PusherClient {
|
|
397
|
+
trigger(channel: string | string[], event: string, data: unknown): Promise<unknown>;
|
|
398
|
+
authorizeChannel(socketId: string, channel: string, data?: {
|
|
399
|
+
user_id: string;
|
|
400
|
+
user_info?: {
|
|
401
|
+
[key: string]: any;
|
|
402
|
+
};
|
|
403
|
+
}): {
|
|
404
|
+
auth: string;
|
|
405
|
+
channel_data?: string;
|
|
406
|
+
shared_secret?: string;
|
|
407
|
+
};
|
|
408
|
+
}
|
|
395
409
|
/**
|
|
396
410
|
* Broadcasts notifications over [Pusher Channels](https://pusher.com/channels).
|
|
397
411
|
*
|
|
@@ -404,6 +418,28 @@ declare class PusherRealtimeDriver implements RealtimeDriver {
|
|
|
404
418
|
constructor(options?: PusherTransportConfig);
|
|
405
419
|
private client;
|
|
406
420
|
broadcast(channel: string | string[], event: string, payload: RealtimeNotificationPayload): Promise<unknown>;
|
|
421
|
+
/**
|
|
422
|
+
* Authourize a pusher channel
|
|
423
|
+
*
|
|
424
|
+
* @param socketId
|
|
425
|
+
* @param channel
|
|
426
|
+
* @returns
|
|
427
|
+
*/
|
|
428
|
+
auth(socketId: string, channel: string, data?: Parameters<PusherClient['authorizeChannel']>[2]): Promise<ReturnType<PusherClient['authorizeChannel']>>;
|
|
429
|
+
/**
|
|
430
|
+
* Register a realtime autorization route
|
|
431
|
+
*
|
|
432
|
+
* @param authEndpoint
|
|
433
|
+
* @param middleware
|
|
434
|
+
*/
|
|
435
|
+
static registerAuthRoute(authEndpoint?: string, middleware?: unknown | unknown[], config?: PusherTransportConfig): Promise<void>;
|
|
436
|
+
/**
|
|
437
|
+
* Register a realtime autorization route
|
|
438
|
+
*
|
|
439
|
+
* @param authEndpoint
|
|
440
|
+
* @param middleware
|
|
441
|
+
*/
|
|
442
|
+
registerAuthRoute(authEndpoint?: string, middleware?: unknown | unknown[]): Promise<void>;
|
|
407
443
|
}
|
|
408
444
|
//#endregion
|
|
409
445
|
//#region src/Contracts/RealtimeDriver.d.ts
|
|
@@ -417,6 +453,7 @@ declare class PusherRealtimeDriver implements RealtimeDriver {
|
|
|
417
453
|
*/
|
|
418
454
|
interface RealtimeDriver {
|
|
419
455
|
broadcast(channel: string | string[], event: string, payload: RealtimeNotificationPayload): Promise<unknown>;
|
|
456
|
+
auth?(socketId: string, channel: string, data?: unknown): unknown | Promise<unknown>;
|
|
420
457
|
}
|
|
421
458
|
type RealtimeNotificationDriver<T extends RealtimeDriverName> = T extends 'firebase' ? FirebaseRealtimeDriver : T extends 'firebase' ? PusherRealtimeDriver : RealtimeDriver;
|
|
422
459
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -535,7 +535,7 @@ var FirebaseRealtimeDriver = class {
|
|
|
535
535
|
* The `pusher` server SDK is an optional peer dependency, imported lazily so the
|
|
536
536
|
* package installs without it; it is only required when this transport is used.
|
|
537
537
|
*/
|
|
538
|
-
var PusherRealtimeDriver = class {
|
|
538
|
+
var PusherRealtimeDriver = class PusherRealtimeDriver {
|
|
539
539
|
options;
|
|
540
540
|
clientPromise;
|
|
541
541
|
constructor(options = {}) {
|
|
@@ -560,6 +560,53 @@ var PusherRealtimeDriver = class {
|
|
|
560
560
|
async broadcast(channel, event, payload) {
|
|
561
561
|
return await (await this.client()).trigger(channel, event, payload);
|
|
562
562
|
}
|
|
563
|
+
/**
|
|
564
|
+
* Authourize a pusher channel
|
|
565
|
+
*
|
|
566
|
+
* @param socketId
|
|
567
|
+
* @param channel
|
|
568
|
+
* @returns
|
|
569
|
+
*/
|
|
570
|
+
async auth(socketId, channel, data) {
|
|
571
|
+
return (await this.client()).authorizeChannel(socketId, channel, data);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Register a realtime autorization route
|
|
575
|
+
*
|
|
576
|
+
* @param authEndpoint
|
|
577
|
+
* @param middleware
|
|
578
|
+
*/
|
|
579
|
+
static async registerAuthRoute(authEndpoint = "/realtime/auth", middleware, config = {}) {
|
|
580
|
+
return new PusherRealtimeDriver(config).registerAuthRoute(authEndpoint, middleware);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Register a realtime autorization route
|
|
584
|
+
*
|
|
585
|
+
* @param authEndpoint
|
|
586
|
+
* @param middleware
|
|
587
|
+
*/
|
|
588
|
+
async registerAuthRoute(authEndpoint = "/realtime/auth", middleware) {
|
|
589
|
+
const client = await this.client();
|
|
590
|
+
for (const [name, path] of Object.entries({
|
|
591
|
+
express: "@arkstack/driver-express",
|
|
592
|
+
h3: "@arkstack/driver-express"
|
|
593
|
+
})) {
|
|
594
|
+
const midsPath = `${path}/middlewares`;
|
|
595
|
+
try {
|
|
596
|
+
const { Router } = await import(path);
|
|
597
|
+
const { auth } = await import(midsPath);
|
|
598
|
+
const middlewares = new Set(Array.isArray(middleware) ? middleware.concat(auth) : [middleware, auth]);
|
|
599
|
+
Router.post(authEndpoint, ({ clearRequest }) => {
|
|
600
|
+
const channel = clearRequest.input("channel_name");
|
|
601
|
+
const socketId = clearRequest.input("socket_id");
|
|
602
|
+
return client.authorizeChannel(socketId, channel);
|
|
603
|
+
}).middleware(Array.from(middlewares));
|
|
604
|
+
break;
|
|
605
|
+
} catch (e) {
|
|
606
|
+
console.error(`Failed to register auth route for ${name}: ${e instanceof Error ? e.message : e}`);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
563
610
|
};
|
|
564
611
|
//#endregion
|
|
565
612
|
//#region src/drivers/RealtimeNotification.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/notifications",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Framework-agnostic notification module for Arkstack and Nodejs, providing support for multi-channel notification delivery.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net/guide/notifications",
|
|
@@ -34,16 +34,24 @@
|
|
|
34
34
|
"africastalking": "^0.8.0",
|
|
35
35
|
"nodemailer": "^9.0.3",
|
|
36
36
|
"twilio": "^6.0.2",
|
|
37
|
-
"@arkstack/common": "^0.17.
|
|
37
|
+
"@arkstack/common": "^0.17.14"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@kanun-hq/plugin-phone": "^0.1.8",
|
|
41
41
|
"firebase-admin": "^13.0.0",
|
|
42
42
|
"pusher": "^5.2.0",
|
|
43
|
-
"@arkstack/
|
|
44
|
-
"@arkstack/
|
|
43
|
+
"@arkstack/contract": "^0.17.14",
|
|
44
|
+
"@arkstack/database": "^0.17.14",
|
|
45
|
+
"@arkstack/driver-h3": "^0.17.14",
|
|
46
|
+
"@arkstack/driver-express": "^0.17.14"
|
|
45
47
|
},
|
|
46
48
|
"peerDependenciesMeta": {
|
|
49
|
+
"@arkstack/driver-express": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@arkstack/driver-h3": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
47
55
|
"pusher": {
|
|
48
56
|
"optional": true
|
|
49
57
|
},
|