@lucaapp/service-utils 1.45.0 → 1.46.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.
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { KafkaClient } from '../kafka';
|
|
2
2
|
declare const generateSubscriptionId: () => string;
|
|
3
3
|
declare const emitWebsocketEvent: (kafkaClient: KafkaClient, subId: string, type: string, data: any) => Promise<void>;
|
|
4
|
-
|
|
4
|
+
declare const derivePublicSubId: (method: string, path: string) => string;
|
|
5
|
+
declare const deriveSubId: (method: string, path: string, secret: string) => string;
|
|
6
|
+
export { generateSubscriptionId, emitWebsocketEvent, deriveSubId, derivePublicSubId, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.emitWebsocketEvent = exports.generateSubscriptionId = void 0;
|
|
3
|
+
exports.derivePublicSubId = exports.deriveSubId = exports.emitWebsocketEvent = exports.generateSubscriptionId = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const generateSubscriptionId = () => {
|
|
@@ -25,3 +25,15 @@ data) => {
|
|
|
25
25
|
await kafkaClient.produce(topic, subId, message);
|
|
26
26
|
};
|
|
27
27
|
exports.emitWebsocketEvent = emitWebsocketEvent;
|
|
28
|
+
const derivePublicSubId = (method, path) => {
|
|
29
|
+
return deriveSubId(method, path, 'public');
|
|
30
|
+
};
|
|
31
|
+
exports.derivePublicSubId = derivePublicSubId;
|
|
32
|
+
const deriveSubId = (method, path, secret) => {
|
|
33
|
+
const data = `${method.toLowerCase()}:${path.toLowerCase()}`;
|
|
34
|
+
const hmac = (0, crypto_1.createHmac)('sha256', secret);
|
|
35
|
+
hmac.update(data);
|
|
36
|
+
const subscriptionId = hmac.digest('base64');
|
|
37
|
+
return subscriptionId;
|
|
38
|
+
};
|
|
39
|
+
exports.deriveSubId = deriveSubId;
|