Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@silenteer/natsu

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@silenteer/natsu - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

36

dist/nats-client.js

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

const message = subcription_1_1.value;
const data = message.data
let data = message.data
? requestCodec.decode(message.data)

@@ -38,6 +38,9 @@ : undefined;

message,
data: responseCodec.encode(Object.assign(Object.assign({}, data), { code: 400 })),
data: responseCodec.encode(Object.assign(Object.assign({}, data), { body: undefined, code: 400 })),
});
continue;
}
if (data.body) {
data = Object.assign(Object.assign({}, data), { body: decodeBody(data.body) });
}
const injection = Object.assign(Object.assign({}, params.injections), { message, natsService: client });

@@ -48,3 +51,3 @@ const validationResult = yield handler.validate(data, injection);

message,
data: responseCodec.encode(Object.assign(Object.assign({}, data), { code: validationResult.code, body: validationResult.errors })),
data: responseCodec.encode(Object.assign(Object.assign({}, data), { code: validationResult.code, body: encodeBody(validationResult.errors) })),
});

@@ -57,19 +60,26 @@ continue;

message,
data: responseCodec.encode(Object.assign(Object.assign({}, data), { code: authorizationResult.code, body: authorizationResult.message })),
data: responseCodec.encode(Object.assign(Object.assign({}, data), { code: authorizationResult.code, body: encodeBody(authorizationResult.message) })),
});
continue;
}
const result = yield handler.handle(data, injection);
const handleResult = yield handler.handle(data, injection);
if (handleResult.code !== 200) {
respond({
message,
data: responseCodec.encode(Object.assign(Object.assign({}, data), { code: handleResult.code, body: encodeBody(handleResult.errors) })),
});
continue;
}
respond({
message,
data: responseCodec.encode(Object.assign(Object.assign({}, data), { headers: result.headers
? Object.assign(Object.assign({}, data.headers), result.headers) : data.headers, code: result.code, body: result.body })),
data: responseCodec.encode(Object.assign(Object.assign({}, data), { headers: handleResult.headers
? Object.assign(Object.assign({}, data.headers), handleResult.headers) : data.headers, code: handleResult.code, body: encodeBody(handleResult.body) })),
});
}
catch (error) {
console.error(error);
respond({
message,
data: responseCodec.encode(Object.assign(Object.assign({}, data), { code: 500 })),
data: responseCodec.encode(Object.assign(Object.assign({}, data), { body: data === null || data === void 0 ? void 0 : data.body, code: 500 })),
});
console.error(error);
}

@@ -128,2 +138,10 @@ }

}
function encodeBody(body) {
return body
? Buffer.from((0, nats_1.JSONCodec)().encode(body)).toString('base64')
: undefined;
}
function decodeBody(body) {
return body ? (0, nats_1.JSONCodec)().decode(Buffer.from(body, 'base64')) : undefined;
}
exports.default = {

@@ -130,0 +148,0 @@ setup: (params) => {

@@ -8,3 +8,3 @@ import type { Msg, NatsConnection } from 'nats';

declare type NatsHandleResult<TBody> = {
code: 200;
code: number;
headers?: {

@@ -14,2 +14,3 @@ [key: string]: unknown;

body?: TBody;
errors?: unknown;
};

@@ -16,0 +17,0 @@ declare type NatsAuthorizationResult = {

@@ -15,3 +15,7 @@ import type { NatsAuthorizationResult, NatsHandleResult, NatsValidationResult } from './type';

}) => NatsHandleResult<T>;
error: (params: {
code: number;
errors?: unknown;
}) => NatsHandleResult<unknown>;
};
export { NatsValidationResultUtil, NatsAuthorizationResultUtil, NatsHandleResultUtil, };

@@ -20,4 +20,5 @@ "use strict";

ok: (body, headers) => ({ code: 200, headers, body }),
error: (params) => params,
};
exports.NatsHandleResultUtil = NatsHandleResultUtil;
//# sourceMappingURL=utility.js.map
{
"name": "@silenteer/natsu",
"version": "1.0.4",
"version": "1.0.5",
"license": "MIT",

@@ -18,3 +18,3 @@ "private": false,

"dependencies": {
"@silenteer/natsu-type": "0.0.4",
"@silenteer/natsu-type": "0.0.5",
"nats": "^2.2.0"

@@ -21,0 +21,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc