@arkstack/notifications 0.17.13 → 0.17.15
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 +11 -1
- package/dist/index.js +20 -6
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -431,8 +431,18 @@ declare class PusherRealtimeDriver implements RealtimeDriver {
|
|
|
431
431
|
*
|
|
432
432
|
* @param authEndpoint
|
|
433
433
|
* @param middleware
|
|
434
|
+
* @param config
|
|
435
|
+
* @param channelPrefix
|
|
434
436
|
*/
|
|
435
|
-
registerAuthRoute(authEndpoint?: string, middleware?: unknown | unknown[]): Promise<void>;
|
|
437
|
+
static registerAuthRoute(authEndpoint?: string, middleware?: unknown | unknown[], channelPrefix?: string, config?: PusherTransportConfig): Promise<void>;
|
|
438
|
+
/**
|
|
439
|
+
* Register a realtime autorization route
|
|
440
|
+
*
|
|
441
|
+
* @param authEndpoint
|
|
442
|
+
* @param middleware
|
|
443
|
+
* @param channelPrefix
|
|
444
|
+
*/
|
|
445
|
+
registerAuthRoute(authEndpoint?: string, middleware?: unknown | unknown[], channelPrefix?: string): Promise<void>;
|
|
436
446
|
}
|
|
437
447
|
//#endregion
|
|
438
448
|
//#region src/Contracts/RealtimeDriver.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { config, env, getModel } from "@arkstack/common";
|
|
1
|
+
import { RequestException, config as config$1, env, getModel } from "@arkstack/common";
|
|
2
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
3
|
import path, { join } from "node:path";
|
|
4
4
|
import nodemailer from "nodemailer";
|
|
@@ -192,7 +192,7 @@ var DbNotification = class extends NotificationContract {
|
|
|
192
192
|
//#region src/config.ts
|
|
193
193
|
const configure = (key, defaultValue) => {
|
|
194
194
|
try {
|
|
195
|
-
return config(`notifications.${key}`, defaultValue);
|
|
195
|
+
return config$1(`notifications.${key}`, defaultValue);
|
|
196
196
|
} catch {
|
|
197
197
|
return defaultValue;
|
|
198
198
|
}
|
|
@@ -366,7 +366,7 @@ var MailNotification = class extends NotificationContract {
|
|
|
366
366
|
*/
|
|
367
367
|
async send(message, subject, recipient, data) {
|
|
368
368
|
const mergedData = {
|
|
369
|
-
app_name: config("app.name", "Arkstack"),
|
|
369
|
+
app_name: config$1("app.name", "Arkstack"),
|
|
370
370
|
...this.mergeData(data)
|
|
371
371
|
};
|
|
372
372
|
const resolvedSubject = interpolate(subject ?? this.subjectLine ?? "", mergedData);
|
|
@@ -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 = {}) {
|
|
@@ -575,8 +575,20 @@ var PusherRealtimeDriver = class {
|
|
|
575
575
|
*
|
|
576
576
|
* @param authEndpoint
|
|
577
577
|
* @param middleware
|
|
578
|
+
* @param config
|
|
579
|
+
* @param channelPrefix
|
|
578
580
|
*/
|
|
579
|
-
async registerAuthRoute(authEndpoint = "/realtime/auth", middleware) {
|
|
581
|
+
static async registerAuthRoute(authEndpoint = "/realtime/auth", middleware, channelPrefix, config = {}) {
|
|
582
|
+
return new PusherRealtimeDriver(config).registerAuthRoute(authEndpoint, middleware, channelPrefix);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Register a realtime autorization route
|
|
586
|
+
*
|
|
587
|
+
* @param authEndpoint
|
|
588
|
+
* @param middleware
|
|
589
|
+
* @param channelPrefix
|
|
590
|
+
*/
|
|
591
|
+
async registerAuthRoute(authEndpoint = "/realtime/auth", middleware, channelPrefix) {
|
|
580
592
|
const client = await this.client();
|
|
581
593
|
for (const [name, path] of Object.entries({
|
|
582
594
|
express: "@arkstack/driver-express",
|
|
@@ -587,9 +599,11 @@ var PusherRealtimeDriver = class {
|
|
|
587
599
|
const { Router } = await import(path);
|
|
588
600
|
const { auth } = await import(midsPath);
|
|
589
601
|
const middlewares = new Set(Array.isArray(middleware) ? middleware.concat(auth) : [middleware, auth]);
|
|
590
|
-
Router.post(authEndpoint, ({ clearRequest }) => {
|
|
602
|
+
Router.post(authEndpoint, ({ clearRequest, req }) => {
|
|
591
603
|
const channel = clearRequest.input("channel_name");
|
|
592
604
|
const socketId = clearRequest.input("socket_id");
|
|
605
|
+
const expected = channelPrefix ?? `${config("notifications.drivers.realtime.channel_prefix", "user.")}${req.user?.id ?? clearRequest.user?.id}`;
|
|
606
|
+
RequestException.abortIf(channel !== expected, "Channel access denied", 403);
|
|
593
607
|
return client.authorizeChannel(socketId, channel);
|
|
594
608
|
}).middleware(Array.from(middlewares));
|
|
595
609
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/notifications",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.15",
|
|
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,16 @@
|
|
|
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.15"
|
|
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/contract": "^0.17.
|
|
44
|
-
"@arkstack/database": "^0.17.
|
|
45
|
-
"@arkstack/driver-express": "^0.17.
|
|
46
|
-
"@arkstack/driver-h3": "^0.17.
|
|
43
|
+
"@arkstack/contract": "^0.17.15",
|
|
44
|
+
"@arkstack/database": "^0.17.15",
|
|
45
|
+
"@arkstack/driver-express": "^0.17.15",
|
|
46
|
+
"@arkstack/driver-h3": "^0.17.15"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@arkstack/driver-express": {
|