@erento/nestjs-module-google-pubsub
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -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 |
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": { |
12
21
419
26602
+ Added@google-cloud/paginator@5.0.0(transitive)
+ Added@google-cloud/precise-date@4.0.0(transitive)
+ Added@google-cloud/projectify@4.0.0(transitive)
+ Added@google-cloud/promisify@4.0.0(transitive)
+ Added@google-cloud/pubsub@4.3.2(transitive)
+ Added@grpc/grpc-js@1.10.6(transitive)
+ Added@grpc/proto-loader@0.7.12(transitive)
+ Added@js-sdsl/ordered-map@4.4.2(transitive)
+ Added@opentelemetry/semantic-conventions@1.21.0(transitive)
+ Added@tootallnate/once@2.0.0(transitive)
+ Added@types/caseless@0.12.5(transitive)
+ Added@types/node@20.12.7(transitive)
+ Added@types/request@2.48.12(transitive)
+ Added@types/tough-cookie@4.0.5(transitive)
+ Addedagent-base@7.1.1(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@2.5.1(transitive)
+ Addedgaxios@6.5.0(transitive)
+ Addedgcp-metadata@6.1.0(transitive)
+ Addedgoogle-auth-library@9.9.0(transitive)
+ Addedgoogle-gax@4.3.2(transitive)
+ Addedgtoken@7.1.0(transitive)
+ Addedheap-js@2.5.0(transitive)
+ Addedhttp-proxy-agent@5.0.0(transitive)
+ Addedhttps-proxy-agent@7.0.4(transitive)
+ Addedlong@5.2.3(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedobject-hash@3.0.0(transitive)
+ Addedproto3-json-serializer@2.0.1(transitive)
+ Addedprotobufjs@7.2.6(transitive)
+ Addedretry-request@7.0.2(transitive)
+ Addedstream-events@1.0.5(transitive)
+ Addedstubs@3.0.0(transitive)
+ Addedteeny-request@9.0.0(transitive)
+ Addeduuid@9.0.1(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removed@google-cloud/paginator@3.0.7(transitive)
- Removed@google-cloud/precise-date@2.0.4(transitive)
- Removed@google-cloud/projectify@2.1.1(transitive)
- Removed@google-cloud/promisify@2.0.4(transitive)
- Removed@google-cloud/pubsub@2.18.5(transitive)
- Removed@grpc/grpc-js@1.5.10(transitive)
- Removed@grpc/proto-loader@0.6.13(transitive)
- Removed@opentelemetry/semantic-conventions@1.24.0(transitive)
- Removed@types/node@20.12.8(transitive)
- Removedcliui@7.0.4(transitive)
- Removedfast-text-encoding@1.0.6(transitive)
- Removedgaxios@4.3.3(transitive)
- Removedgcp-metadata@4.3.1(transitive)
- Removedgoogle-auth-library@7.14.1(transitive)
- Removedgoogle-gax@2.29.4(transitive)
- Removedgoogle-p12-pem@3.1.4(transitive)
- Removedgtoken@5.3.2(transitive)
- Removedlong@4.0.0(transitive)
- Removedlru-cache@6.0.0(transitive)
- Removednode-forge@1.3.1(transitive)
- Removedobject-hash@2.2.0(transitive)
- Removedproto3-json-serializer@0.1.9(transitive)
- Removedprotobufjs@6.11.26.11.4(transitive)
- Removedretry-request@4.2.2(transitive)
- Removedyallist@4.0.0(transitive)
- Removedyargs@16.2.0(transitive)
- Removedyargs-parser@20.2.9(transitive)
Updated@google-cloud/pubsub@4.3.2
Updatedobject-hash@3.0.0