New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nclabs/nestjs-rpc-module

Package Overview
Dependencies
Maintainers
0
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nclabs/nestjs-rpc-module - npm Package Compare versions

Comparing version 0.0.27 to 0.0.28

14

lib/nclabs-cacher/nclabs-cacher.service.js

@@ -17,17 +17,17 @@ "use strict";

const common_1 = require("@nestjs/common");
const load_env_1 = require("../common/lib/load-env");
const cache_manager_1 = require("@nestjs/cache-manager");
const nclabs_config_1 = require("../common/lib/nclabs-config");
let NclabsCacherService = class NclabsCacherService {
constructor(cacheManager) {
this.cacheManager = cacheManager;
(0, load_env_1.loadEnv)();
this.config = nclabs_config_1.NclabsConfig.load();
}
_prefixKey() {
const prefix = process.env.CACHE_PREFIX || 'CACHE_PREFIX';
const serviceName = process.env.SERVICE_NAME || 'no-service-name';
return `${prefix}:${serviceName}`;
const prefix = this.config.cache.prefix;
const service = this.config.service;
return `${prefix}:${service}`;
}
async get(keyId) {
const key = `${this._prefixKey()}:${keyId}`;
const CACHE_HIT_LOG = process.env.CACHE_HIT_LOG || false;
const CACHE_HIT_LOG = this.config.cache.logCacheHit;
const data = await this.cacheManager.get(key);

@@ -42,3 +42,3 @@ if (data && CACHE_HIT_LOG) {

const key = `${this._prefixKey()}:${keyId}`;
const cacheTtl = process.env.CACHE_TTL || 60;
const cacheTtl = this.config.cache.ttl;
return this.cacheManager.set(key, value, { ttl: ttl || cacheTtl });

@@ -45,0 +45,0 @@ }

@@ -13,12 +13,13 @@ "use strict";

const rpc_client_service_1 = require("./rpc-client.service");
const nclabs_config_1 = require("../common/lib/nclabs-config");
const natsClientProvider = {
provide: 'SERVICES',
useFactory: () => {
const service = process.env.SERVICE_NAME || 'no-service-name';
const natsHost = process.env.NATS_HOST || 'localhost';
const natsPort = parseInt(process.env.NATS_PORT, 10) || 4222;
const config = nclabs_config_1.NclabsConfig.load();
const { service } = config;
const { host, port } = config.nats;
return microservices_1.ClientProxyFactory.create({
transport: microservices_1.Transport.NATS,
options: {
servers: [`nats://${natsHost}:${natsPort}`],
servers: [`nats://${host}:${port}`],
queue: service,

@@ -25,0 +26,0 @@ },

@@ -21,7 +21,5 @@ "use strict";

const nclabs_exeption_1 = require("../common/lib/nclabs-exeption");
const load_env_1 = require("../common/lib/load-env");
let NclabsRpcClientService = class NclabsRpcClientService {
constructor(client) {
this.client = client;
(0, load_env_1.loadEnv)();
}

@@ -28,0 +26,0 @@ call(service, data, context) {

@@ -6,12 +6,12 @@ "use strict";

const microservices_1 = require("@nestjs/microservices");
const load_env_1 = require("../../common/lib/load-env");
const register_refletor_decorator_1 = require("../../common/decorators/register-refletor.decorator");
const services_list_store_1 = require("../lib/services-list.store");
(0, load_env_1.loadEnv)();
const nclabs_config_1 = require("../../common/lib/nclabs-config");
function NclabsAction({ name, rest, cache }) {
const serviceName = process.env.SERVICE_NAME || 'no-service-name';
const actionPattern = _getActionPattern(serviceName, name, cache);
const restPattern = _getRestPattern(serviceName, rest, cache);
const config = nclabs_config_1.NclabsConfig.load();
const { service } = config;
const actionPattern = _getActionPattern(service, name, cache);
const restPattern = _getRestPattern(service, rest, cache);
const rpcConfig = {
service: serviceName,
service: service,
type: 'action',

@@ -18,0 +18,0 @@ action: {

@@ -6,9 +6,10 @@ "use strict";

const microservices_1 = require("@nestjs/microservices");
const load_env_1 = require("../../common/lib/load-env");
const register_refletor_decorator_1 = require("../../common/decorators/register-refletor.decorator");
const services_list_store_1 = require("../lib/services-list.store");
(0, load_env_1.loadEnv)();
const nclabs_config_1 = require("../../common/lib/nclabs-config");
function NclabsEvent({ listen }) {
const config = nclabs_config_1.NclabsConfig.load();
const { service } = config;
const rpcConfig = {
service: process.env.SERVICE_NAME || 'no-service-name',
service,
type: 'event',

@@ -15,0 +16,0 @@ event: {

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

const uuid_1 = require("uuid");
const load_env_1 = require("../../common/lib/load-env");
const nclabs_config_1 = require("../../common/lib/nclabs-config");
class ServicesListStore {

@@ -13,4 +13,6 @@ constructor() { }

setTimeout(() => {
const { service } = ServicesListStore._config;
const { prefix } = ServicesListStore._config.register;
const uuid = (0, uuid_1.v4)();
const key = `${ServicesListStore._rpcListPrefix}:${ServicesListStore._serviceName}:${uuid}`;
const key = `${prefix}:${service}:${uuid}`;
redisClient.set(key, JSON.stringify(rpcConfig)).catch(console.log);

@@ -26,6 +28,4 @@ }, 500);

if (!ServicesListStore._instance) {
(0, load_env_1.loadEnv)();
ServicesListStore._config = nclabs_config_1.NclabsConfig.load();
ServicesListStore._instance = ServicesListStore._createInstance();
ServicesListStore._rpcListPrefix = process.env.RPC_LIST_PREFIX || 'RPC-LIST';
ServicesListStore._serviceName = process.env.SERVICE_NAME || 'no-service-name';
ServicesListStore._clear();

@@ -36,7 +36,8 @@ }

static _createInstance() {
const { host, port, password, database } = ServicesListStore._config.redis;
const redis = new ioredis_1.Redis({
host: process.env.REDIS_HOST,
port: parseInt(process.env.REDIS_PORT, 10),
password: process.env.REDIS_PASSWORD,
db: parseInt(process.env.REDIS_CACHE_DB, 10) || parseInt(process.env.REDIS_DB, 10) || 0,
host,
port,
password,
db: database,
});

@@ -46,5 +47,5 @@ return redis;

static _clear() {
ServicesListStore._instance
.keys(`${ServicesListStore._rpcListPrefix}:${ServicesListStore._serviceName}:*`)
.then((keys) => {
const { service } = ServicesListStore._config;
const { prefix } = ServicesListStore._config.register;
ServicesListStore._instance.keys(`${prefix}:${service}:*`).then((keys) => {
for (const key of keys) {

@@ -51,0 +52,0 @@ ServicesListStore._instance.del(key);

{
"name": "@nclabs/nestjs-rpc-module",
"version": "0.0.27",
"version": "0.0.28",
"description": "Utilitário NestJS para configuração de rotas e cache em microsserviços. Utilizado especificamente para projetos nclabs",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

import { Cache } from 'cache-manager';
export declare class NclabsCacherService {
private cacheManager;
private config;
constructor(cacheManager: Cache);

@@ -5,0 +6,0 @@ private _prefixKey;

@@ -5,4 +5,3 @@ import { IRegisterConfig } from '../../common/interfaces/register-reflector-config';

private static _instance;
private static _rpcListPrefix;
private static _serviceName;
private static _config;
static setService(rpcConfig: IRegisterConfig): void;

@@ -9,0 +8,0 @@ static close(): void;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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