Compare commits
No commits in common. "master" and "prod" have entirely different histories.
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@erp/plugin-sdk",
|
"name": "@erp/plugin-sdk",
|
||||||
"version": "1.11.0",
|
"version": "1.10.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@erp/plugin-sdk",
|
"name": "@erp/plugin-sdk",
|
||||||
"version": "1.11.0",
|
"version": "1.10.1",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@erp/plugin-sdk",
|
"name": "@erp/plugin-sdk",
|
||||||
"version": "1.11.3",
|
"version": "1.10.2",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|
|
||||||
|
|
@ -162,17 +162,10 @@ export class CoreService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async callPluginApi<T = any>(pluginId: string, path: string, body?: any): Promise<T> {
|
async callPluginApi<T = any>(pluginId: string, path: string, body?: any): Promise<T> {
|
||||||
const res = await this.fetchCore(`/api/plugins/rpc/${pluginId}/${path.replace(/^\//, '')}`, {
|
return this.fetchCore(`/api/plugins/rpc/${pluginId}/${path.replace(/^\//, '')}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||||
});
|
});
|
||||||
if (res && typeof res === 'object' && res.success === true) {
|
|
||||||
if (res.data && typeof res.data === 'object' && res.data.success === true) {
|
|
||||||
return res.data.data as T;
|
|
||||||
}
|
|
||||||
return res.data as T;
|
|
||||||
}
|
|
||||||
return res as T;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async callAsService<T = any>(pluginId: string, path: string, body?: any): Promise<T> {
|
async callAsService<T = any>(pluginId: string, path: string, body?: any): Promise<T> {
|
||||||
|
|
@ -331,19 +324,9 @@ export class CoreService {
|
||||||
source: this.serviceName,
|
source: this.serviceName,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
try {
|
this.client.emit(pattern, event).subscribe({
|
||||||
const conn = await amqp.connect(this.getRMQUrl());
|
error: (err) => this.logger.error(`Failed to emit event ${pattern}:`, err),
|
||||||
const ch = await conn.createChannel();
|
});
|
||||||
await ch.assertExchange('system_events', 'topic', { durable: true });
|
|
||||||
ch.publish('system_events', pattern, Buffer.from(JSON.stringify({
|
|
||||||
pattern,
|
|
||||||
data: event,
|
|
||||||
})));
|
|
||||||
await ch.close();
|
|
||||||
await conn.close();
|
|
||||||
} catch (err: any) {
|
|
||||||
this.logger.error(`Failed to emit event ${pattern}: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async auditLog(action: string, resource: string, details?: any): Promise<void> {
|
async auditLog(action: string, resource: string, details?: any): Promise<void> {
|
||||||
|
|
@ -416,26 +399,14 @@ export class CoreService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendNotification(payload: { userId: number | null; title: string; message: string; icon?: string; image?: string; details?: any }): Promise<void> {
|
async sendNotification(payload: { userId: number | null; title: string; message: string; icon?: string; image?: string; details?: any }): Promise<void> {
|
||||||
try {
|
await this.emit('system.notification.send', {
|
||||||
const conn = await amqp.connect(this.getRMQUrl());
|
userId: payload.userId,
|
||||||
const ch = await conn.createChannel();
|
title: payload.title,
|
||||||
await ch.assertExchange('system_events', 'topic', { durable: true });
|
message: payload.message,
|
||||||
ch.publish('system_events', 'system.notification.send', Buffer.from(JSON.stringify({
|
icon: payload.icon,
|
||||||
pattern: 'system.notification.send',
|
image: payload.image,
|
||||||
data: {
|
details: payload.details,
|
||||||
userId: payload.userId,
|
});
|
||||||
title: payload.title,
|
|
||||||
message: payload.message,
|
|
||||||
icon: payload.icon,
|
|
||||||
image: payload.image,
|
|
||||||
details: payload.details,
|
|
||||||
},
|
|
||||||
})));
|
|
||||||
await ch.close();
|
|
||||||
await conn.close();
|
|
||||||
} catch (err: any) {
|
|
||||||
this.logger.error(`[sendNotification] Failed: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDbName(): string {
|
getDbName(): string {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue