Socket
Socket
Sign inDemoInstall

@erento/nestjs-module-google-pubsub

Package Overview
Dependencies
117
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 4.0.0

dist/parse-pubsub-message.pipe.test.d.ts

6

CHANGELOG.md

@@ -0,3 +1,7 @@

<a name="3.1.0"></a>
# 3.1.0 (2022-07-20)
- added flag to pubsub service to be able to use publish without encryption
<a name="3.0.0"></a>
# 3.0.0 (2022-03-7)
# 3.0.0 (2022-03-07)
- updated dependencies to latest possible versions

@@ -4,0 +8,0 @@ - raised required node to >=16.0.0 & npm to >=8.0.0

8

dist/domain.d.ts
import { Message as gMessage, Subscription as gSubscription } from '@google-cloud/pubsub';
import { PublishOptions as gPublishOptions } from '@google-cloud/pubsub/build/src/publisher';
import { SubscriptionOptions as gSubscriptionOptions } from '@google-cloud/pubsub/build/src/subscription';
export declare type PublishOptions = gPublishOptions;
export declare type Subscription = gSubscription;
export declare type SubscriptionOptions = gSubscriptionOptions;
export declare type EncodedMessage = gMessage;
export type PublishOptions = gPublishOptions;
export type Subscription = gSubscription;
export type SubscriptionOptions = gSubscriptionOptions;
export type EncodedMessage = gMessage;
export interface PubsubMessage<T = any> {

@@ -9,0 +9,0 @@ meta: PubsubMessageMeta;

@@ -11,11 +11,2 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -26,28 +17,27 @@ exports.ParsePubsubMessagePipe = void 0;

let ParsePubsubMessagePipe = class ParsePubsubMessagePipe {
pubsubService;
constructor(pubsubService) {
this.pubsubService = pubsubService;
}
transform(pushMessage) {
return __awaiter(this, void 0, void 0, function* () {
try {
const verification = yield this.pubsubService.verifyMessage(pushMessage.message);
if (!verification) {
throw new common_1.HttpException('Not able to parse the message, acking with 2xx status code.', common_1.HttpStatus.OK);
}
const decryptedMessage = yield this.pubsubService.decryptMessage(pushMessage.message);
return JSON.parse(decryptedMessage);
async transform(pushMessage) {
try {
const verification = await this.pubsubService.verifyMessage(pushMessage.message);
if (!verification) {
throw new common_1.HttpException('Not able to parse the message, acking with 2xx status code.', common_1.HttpStatus.OK);
}
catch (err) {
if (err instanceof common_1.HttpException) {
throw err;
}
throw new common_1.BadRequestException(`Unable to decode pubsub message. Original message: ${err && err.message}`);
const decryptedMessage = await this.pubsubService.decryptMessage(pushMessage.message);
return JSON.parse(decryptedMessage);
}
catch (err) {
if (err instanceof common_1.HttpException) {
throw err;
}
});
throw new common_1.BadRequestException(`Unable to decode pubsub message. Original message: ${err && err.message}`);
}
}
};
ParsePubsubMessagePipe = __decorate([
exports.ParsePubsubMessagePipe = ParsePubsubMessagePipe;
exports.ParsePubsubMessagePipe = ParsePubsubMessagePipe = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [pubsub_service_1.PubsubService])
], ParsePubsubMessagePipe);
exports.ParsePubsubMessagePipe = ParsePubsubMessagePipe;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -10,3 +10,3 @@ "use strict";

exports.PubsubHelper = void 0;
const os = require("os");
const os = require("node:os");
const common_1 = require("@nestjs/common");

@@ -28,5 +28,5 @@ const hash = require("object-hash");

};
PubsubHelper = __decorate([
exports.PubsubHelper = PubsubHelper;
exports.PubsubHelper = PubsubHelper = __decorate([
(0, common_1.Injectable)()
], PubsubHelper);
exports.PubsubHelper = PubsubHelper;

@@ -33,5 +33,5 @@ "use strict";

};
PubsubModule = PubsubModule_1 = __decorate([
exports.PubsubModule = PubsubModule;
exports.PubsubModule = PubsubModule = PubsubModule_1 = __decorate([
(0, common_1.Module)({})
], PubsubModule);
exports.PubsubModule = PubsubModule;

@@ -11,11 +11,2 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var PubsubService_1;

@@ -29,2 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });

let PubsubService = PubsubService_1 = class PubsubService {
cryptoEncryptionKey;
cryptoSignKey;
pubsubHelper;
serviceIdentifier;
pubSubLibrary;
constructor(cryptoEncryptionKey, cryptoSignKey, pubsubHelper, serviceIdentifier) {

@@ -51,31 +47,30 @@ this.cryptoEncryptionKey = cryptoEncryptionKey;

decryptMessage(body, encrypted = true) {
const message = body && body.data || undefined;
const message = (body && body.data) || undefined;
return encrypted ? MessageCrypto.decrypt(message, this.cryptoEncryptionKey) : this.parseMessage(message);
}
verifyMessage(body) {
return __awaiter(this, void 0, void 0, function* () {
try {
const signature = body.attributes.signature || undefined;
let message = body.data || undefined;
if (message instanceof Buffer) {
message = message.toString('base64');
}
return true === (yield MessageCrypto.verifySignature(message, this.cryptoSignKey, signature));
async verifyMessage(body) {
try {
const signature = body.attributes.signature || undefined;
let message = body.data || undefined;
if (message instanceof Buffer) {
message = message.toString('base64');
}
catch (_a) {
throw new Error('Message signature check failed.');
}
});
return true === await MessageCrypto.verifySignature(message, this.cryptoSignKey, signature);
}
catch {
throw new Error('Message signature check failed.');
}
}
publishMessage(topicName, message, attributes = {}, encrypted = true, publishOptions) {
return __awaiter(this, void 0, void 0, function* () {
if (!message) {
throw new Error('Message can\'t be empty.');
}
const messageWithMetadata = JSON.stringify(this.pubsubHelper.prepareForPubsub(topicName, message, this.serviceIdentifier));
const messageBody = encrypted ?
yield this.encryptMessage(messageWithMetadata) :
Buffer.from(messageWithMetadata).toString('base64');
const signature = yield this.createSignature(messageBody);
yield this.getTopic(topicName, publishOptions).publish(Buffer.from(messageBody, 'base64'), Object.assign({ signature }, attributes));
async publishMessage(topicName, message, attributes = {}, encrypted = true, publishOptions) {
if (!message) {
throw new Error('Message can\'t be empty.');
}
const messageWithMetadata = JSON.stringify(this.pubsubHelper.prepareForPubsub(topicName, message, this.serviceIdentifier));
const messageBody = encrypted ?
await this.encryptMessage(messageWithMetadata) :
Buffer.from(messageWithMetadata).toString('base64');
const signature = await this.createSignature(messageBody);
await this.getTopic(topicName, publishOptions).publish(Buffer.from(messageBody, 'base64'), {
signature,
...attributes,
});

@@ -101,3 +96,3 @@ }

}
catch (_a) {
catch {
throw new Error('Cannot get a publisher.');

@@ -111,6 +106,6 @@ }

};
PubsubService = PubsubService_1 = __decorate([
exports.PubsubService = PubsubService;
exports.PubsubService = PubsubService = PubsubService_1 = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [String, String, pubsub_helper_1.PubsubHelper, String])
], PubsubService);
exports.PubsubService = PubsubService;
{
"name": "@erento/nestjs-module-google-pubsub",
"version": "3.1.0",
"version": "4.0.0",
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0"
"node": ">=20.0.0",
"npm": ">=10.0.0"
},

@@ -28,29 +28,23 @@ "engineStrict": true,

"peerDependencies": {
"@nestjs/common": ">=8.0.0",
"typescript": ">=4.0.0"
"@nestjs/common": ">=10.3.1",
"typescript": ">=5.2.2"
},
"dependencies": {
"@google-cloud/pubsub": "2.18.5",
"@google-cloud/pubsub": "4.3.2",
"message-crypto": "1.0.0",
"object-hash": "2.2.0"
"object-hash": "3.0.0"
},
"devDependencies": {
"@erento/eslint-plugin-erento-rules": "1.0.0",
"@nestjs/common": "8.3.0",
"@types/jest": "27.4.0",
"@types/node": "16.11.25",
"@typescript-eslint/eslint-plugin": "5.9.0",
"@typescript-eslint/parser": "5.9.0",
"eslint": "8.6.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-jsdoc": "37.5.1",
"eslint-plugin-prefer-arrow": "1.2.3",
"eslint-plugin-unicorn": "40.0.0",
"jest": "27.5.1",
"lint-staged": "12.3.4",
"@erento/eslint-plugin-erento-rules": "3.0.0",
"@nestjs/common": "10.3.1",
"@types/jest": "29.5.12",
"@types/node": "20.10.8",
"eslint": "8.56.0",
"jest": "29.7.0",
"lint-staged": "15.2.2",
"prettier": "2.5.1",
"reflect-metadata": "0.1.13",
"rxjs": "7.5.4",
"ts-jest": "27.1.3",
"typescript": "4.5.5"
"rxjs": "7.8.1",
"ts-jest": "29.1.2",
"typescript": "5.2.2"
},

@@ -57,0 +51,0 @@ "jest": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc