@experts_hub/shared 1.0.611 → 1.0.614

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import { DiscordAlertOptions, DiscordEmbed } from './discord-alert.interface';
2
+ export declare class AlertBuilder {
3
+ private static readonly COLORS;
4
+ private static readonly SEVERITY_EMOJIS;
5
+ static buildEmbed(options: DiscordAlertOptions): DiscordEmbed;
6
+ private static formatTitle;
7
+ private static formatEnvironment;
8
+ private static formatTimestamp;
9
+ private static formatValue;
10
+ private static shouldBeInline;
11
+ private static looksLikeCode;
12
+ private static truncateStack;
13
+ private static truncateDescription;
14
+ private static buildFooter;
15
+ static validateEmbed(embed: DiscordEmbed): string[];
16
+ }
@@ -0,0 +1,84 @@
1
+ export declare enum AlertSeverity {
2
+ CRITICAL = "CRITICAL",
3
+ ERROR = "ERROR",
4
+ WARNING = "WARNING",
5
+ SECURITY = "SECURITY",
6
+ INFO = "INFO",
7
+ SUCCESS = "SUCCESS"
8
+ }
9
+ export declare enum AlertCategory {
10
+ CRITICAL_ERROR = "CRITICAL_ERROR",
11
+ DATABASE = "DATABASE",
12
+ PAYMENT = "PAYMENT",
13
+ SECURITY = "SECURITY",
14
+ PERFORMANCE = "PERFORMANCE",
15
+ BUSINESS_EVENT = "BUSINESS_EVENT"
16
+ }
17
+ export interface DiscordAlertOptions {
18
+ severity: AlertSeverity;
19
+ category: AlertCategory;
20
+ title: string;
21
+ description: string;
22
+ fields?: Record<string, string | number | boolean>;
23
+ metadata?: {
24
+ microservice?: string;
25
+ environment?: string;
26
+ correlationId?: string;
27
+ userId?: string;
28
+ requestPath?: string;
29
+ requestMethod?: string;
30
+ errorStack?: string;
31
+ hostname?: string;
32
+ [key: string]: any;
33
+ };
34
+ }
35
+ export interface DiscordWebhookConfig {
36
+ errorWebhookUrl?: string;
37
+ securityWebhookUrl?: string;
38
+ businessWebhookUrl?: string;
39
+ performanceWebhookUrl?: string;
40
+ enabled?: boolean;
41
+ rateLimitPerMinute?: number;
42
+ environment?: string;
43
+ microserviceName?: string;
44
+ }
45
+ export interface DiscordEmbedField {
46
+ name: string;
47
+ value: string;
48
+ inline?: boolean;
49
+ }
50
+ export interface DiscordEmbedFooter {
51
+ text: string;
52
+ icon_url?: string;
53
+ }
54
+ export interface DiscordEmbed {
55
+ title: string;
56
+ description: string;
57
+ color: number;
58
+ fields: DiscordEmbedField[];
59
+ footer?: DiscordEmbedFooter;
60
+ timestamp: string;
61
+ thumbnail?: {
62
+ url: string;
63
+ };
64
+ author?: {
65
+ name: string;
66
+ icon_url?: string;
67
+ };
68
+ }
69
+ export interface DiscordWebhookPayload {
70
+ content?: string;
71
+ embeds: DiscordEmbed[];
72
+ username?: string;
73
+ avatar_url?: string;
74
+ }
75
+ export interface RateLimitState {
76
+ webhookUrl: string;
77
+ timestamps: number[];
78
+ }
79
+ export interface AlertKeyComponents {
80
+ severity: AlertSeverity;
81
+ category: AlertCategory;
82
+ title: string;
83
+ microservice?: string;
84
+ }
@@ -0,0 +1,39 @@
1
+ import { DiscordAlertOptions, DiscordWebhookConfig } from './discord-alert.interface';
2
+ import { RateLimiter } from './rate-limiter';
3
+ export declare class DiscordAlertService {
4
+ private readonly rateLimiter;
5
+ private readonly config;
6
+ private alertsSent;
7
+ private alertsFailed;
8
+ constructor(config: DiscordWebhookConfig);
9
+ sendAlert(options: DiscordAlertOptions): Promise<void>;
10
+ sendCriticalError(error: Error, context?: Record<string, any>): Promise<void>;
11
+ sendDatabaseError(message: string, context?: Record<string, any>): Promise<void>;
12
+ sendSecurityAlert(title: string, description: string, context?: Record<string, any>): Promise<void>;
13
+ sendPaymentError(message: string, context?: Record<string, any>): Promise<void>;
14
+ sendBusinessEvent(title: string, description: string, context?: Record<string, any>): Promise<void>;
15
+ sendPerformanceWarning(title: string, description: string, metrics?: Record<string, any>): Promise<void>;
16
+ private getWebhookUrl;
17
+ private sendToWebhook;
18
+ private httpPost;
19
+ private getHostname;
20
+ private log;
21
+ private logError;
22
+ getStats(): {
23
+ alertsSent: number;
24
+ alertsFailed: number;
25
+ successRate: number;
26
+ rateLimiterStats: ReturnType<RateLimiter['getStats']>;
27
+ };
28
+ resetStats(): void;
29
+ isConfigured(): boolean;
30
+ getConfig(): Omit<Required<DiscordWebhookConfig>, 'errorWebhookUrl' | 'securityWebhookUrl' | 'businessWebhookUrl' | 'performanceWebhookUrl'> & {
31
+ webhooksConfigured: {
32
+ error: boolean;
33
+ security: boolean;
34
+ business: boolean;
35
+ performance: boolean;
36
+ };
37
+ };
38
+ destroy(): void;
39
+ }
@@ -0,0 +1,5 @@
1
+ export { DiscordAlertService } from './discord-alert.service';
2
+ export { DiscordTransport, createDiscordTransport, DiscordTransportOptions } from './winston-discord.transport';
3
+ export { AlertBuilder } from './alert-builder';
4
+ export { RateLimiter } from './rate-limiter';
5
+ export { AlertSeverity, AlertCategory, DiscordAlertOptions, DiscordWebhookConfig, DiscordEmbed, DiscordEmbedField, DiscordEmbedFooter, DiscordWebhookPayload, RateLimitState, AlertKeyComponents, } from './discord-alert.interface';
@@ -0,0 +1,32 @@
1
+ import { AlertKeyComponents } from './discord-alert.interface';
2
+ export declare class RateLimiter {
3
+ private readonly maxAlertsPerMinute;
4
+ private alertCounts;
5
+ private recentAlerts;
6
+ private readonly deduplicationWindow;
7
+ private readonly cleanupInterval;
8
+ private cleanupTimer?;
9
+ constructor(maxAlertsPerMinute?: number);
10
+ canSendAlert(webhookUrl: string): boolean;
11
+ recordAlert(webhookUrl: string): void;
12
+ isDuplicate(alertKey: string): boolean;
13
+ generateAlertKey(components: AlertKeyComponents): string;
14
+ getStats(): {
15
+ totalWebhooks: number;
16
+ totalUniqueAlerts: number;
17
+ webhookStats: Array<{
18
+ webhook: string;
19
+ alertsInLastMinute: number;
20
+ remainingCapacity: number;
21
+ }>;
22
+ };
23
+ private maskWebhookUrl;
24
+ clear(): void;
25
+ private startCleanup;
26
+ private cleanup;
27
+ destroy(): void;
28
+ getDeduplicationWindow(): number;
29
+ getMaxAlertsPerMinute(): number;
30
+ isRateLimited(webhookUrl: string): boolean;
31
+ getRemainingCapacity(webhookUrl: string): number;
32
+ }
@@ -0,0 +1,40 @@
1
+ import Transport from 'winston-transport';
2
+ import { DiscordAlertService } from './discord-alert.service';
3
+ import { AlertSeverity, AlertCategory } from './discord-alert.interface';
4
+ export interface DiscordTransportOptions {
5
+ level?: string;
6
+ webhookUrl: string;
7
+ microserviceName: string;
8
+ environment: string;
9
+ enabled?: boolean;
10
+ category?: AlertCategory;
11
+ severity?: AlertSeverity;
12
+ }
13
+ interface WinstonLogInfo {
14
+ level: string;
15
+ message: string;
16
+ timestamp?: string;
17
+ stack?: string;
18
+ correlationId?: string;
19
+ context?: string;
20
+ error?: string;
21
+ [key: string]: any;
22
+ }
23
+ export declare class DiscordTransport extends Transport {
24
+ private readonly discordService;
25
+ private readonly transportOptions;
26
+ private logsSent;
27
+ constructor(options: DiscordTransportOptions);
28
+ log(info: WinstonLogInfo, callback: () => void): void;
29
+ private shouldLog;
30
+ private sendLogToDiscord;
31
+ private mapLogLevelToSeverity;
32
+ private buildTitle;
33
+ getStats(): {
34
+ logsSent: number;
35
+ discordStats: ReturnType<DiscordAlertService['getStats']>;
36
+ };
37
+ close(): void;
38
+ }
39
+ export declare function createDiscordTransport(options: DiscordTransportOptions): DiscordTransport;
40
+ export {};
@@ -43,3 +43,4 @@ export * from './llm';
43
43
  export * from './skill';
44
44
  export * from './user/signature';
45
45
  export * from './wallet';
46
+ export * from './discord';
@@ -1,3 +1,3 @@
1
1
  export declare class RejectF2FInterviewRescheduleRequestDto {
2
- reason?: string;
2
+ clientRejectReason?: string;
3
3
  }
@@ -1,3 +1,3 @@
1
1
  export declare class ClientServiceAgreementUploadDto {
2
- agreementType?: string;
2
+ serviceAgreementSignedOn?: string;
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experts_hub/shared",
3
- "version": "1.0.611",
3
+ "version": "1.0.614",
4
4
  "description": "Shared DTOs, interfaces, and utilities for experts hub applications",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -46,7 +46,8 @@
46
46
  "peerDependencies": {
47
47
  "@nestjs/common": "^10.0.0 || ^11.0.0",
48
48
  "class-transformer": "^0.5.1",
49
- "class-validator": "^0.14.0"
49
+ "class-validator": "^0.14.0",
50
+ "winston-transport": "^4.0.0"
50
51
  },
51
52
  "dependencies": {
52
53
  "@nestjs/microservices": "^11.0.19",