erp-plugin-sdk/dist/backend/services/core-client.service.js

55 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreClientService = void 0;
const common_1 = require("@nestjs/common");
const microservices_1 = require("@nestjs/microservices");
const rxjs_1 = require("rxjs");
const uuid_1 = require("uuid");
let CoreClientService = class CoreClientService {
constructor(client) {
this.client = client;
}
/**
* Запитати у Ядра дані користувача (Синхронно через RabbitMQ RPC)
*/
async getUserInfo(userId) {
try {
return await (0, rxjs_1.firstValueFrom)(this.client.send({ cmd: 'get_user_info' }, { userId }));
}
catch (error) {
return null;
}
}
/**
* Повідомити Ядро про подію в плагіні (Асинхронно)
*/
async notifyCore(pattern, payload) {
const event = {
eventId: (0, uuid_1.v4)(),
pattern,
payload,
source: process.env.SERVICE_NAME || 'plugin',
timestamp: Date.now(),
};
this.client.emit(pattern, event);
}
};
exports.CoreClientService = CoreClientService;
exports.CoreClientService = CoreClientService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, common_1.Inject)('CORE_SERVICE')),
__metadata("design:paramtypes", [microservices_1.ClientProxy])
], CoreClientService);