@rawnodes/logger 2.7.2 → 2.8.0

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.
package/dist/index.mjs CHANGED
@@ -494,6 +494,112 @@ var TelegramTransport = class extends BaseHttpTransport {
494
494
  return text.replace(/[&<>"']/g, (c) => entities[c] || c);
495
495
  }
496
496
  };
497
+
498
+ // src/transports/zoho-cliq.ts
499
+ var LEVEL_EMOJI3 = {
500
+ off: "",
501
+ error: "\u{1F534}",
502
+ warn: "\u{1F7E1}",
503
+ info: "\u{1F7E2}",
504
+ http: "\u{1F535}",
505
+ verbose: "\u{1F7E3}",
506
+ debug: "\u26AA",
507
+ silly: "\u26AB"
508
+ };
509
+ var DEFAULT_REQUEST_TIMEOUT_MS3 = 1e4;
510
+ var MAX_MESSAGE_LENGTH = 9500;
511
+ var ZohoCliqTransport = class extends BaseHttpTransport {
512
+ config;
513
+ endpoint;
514
+ requestTimeout;
515
+ constructor(config) {
516
+ super({
517
+ batchSize: config.batchSize ?? 20,
518
+ flushInterval: config.flushInterval ?? 2e3,
519
+ maxRetries: config.maxRetries,
520
+ retryDelay: config.retryDelay,
521
+ maxQueueSize: config.maxQueueSize,
522
+ dropPolicy: config.dropPolicy,
523
+ onDrop: config.onDrop,
524
+ onError: config.onError
525
+ });
526
+ this.config = config;
527
+ this.requestTimeout = config.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS3;
528
+ this.endpoint = this.buildEndpoint();
529
+ }
530
+ buildEndpoint() {
531
+ if (this.config.webhookUrl) {
532
+ return this.config.webhookUrl;
533
+ }
534
+ const region = this.config.region ?? "eu";
535
+ const companyId = this.config.companyId;
536
+ const channel = encodeURIComponent(this.config.channel);
537
+ return `https://cliq.zoho.${region}/company/${companyId}/api/v2/channelsbyname/${channel}/message`;
538
+ }
539
+ async sendBatch(messages) {
540
+ const text = messages.map((msg) => this.formatMessage(msg)).join("\n\n---\n\n");
541
+ for (const chunk of this.splitContent(text, MAX_MESSAGE_LENGTH)) {
542
+ await this.post(chunk);
543
+ }
544
+ }
545
+ formatMessage(msg) {
546
+ const emoji = LEVEL_EMOJI3[msg.level];
547
+ const level = msg.level.toUpperCase();
548
+ const context = msg.context || "APP";
549
+ const timestamp = this.config.includeTimestamp !== false ? ` ${msg.timestamp.toISOString()}` : "";
550
+ let text = `${emoji} *${level}* [${context}]${timestamp}
551
+ ${msg.message}`;
552
+ if (this.config.includeMeta !== false && msg.meta && Object.keys(msg.meta).length > 0) {
553
+ text += "\n```\n" + JSON.stringify(msg.meta, null, 2) + "\n```";
554
+ }
555
+ return text;
556
+ }
557
+ splitContent(content, maxLength) {
558
+ if (content.length <= maxLength) return [content];
559
+ const chunks = [];
560
+ let current = content;
561
+ while (current.length > 0) {
562
+ if (current.length <= maxLength) {
563
+ chunks.push(current);
564
+ break;
565
+ }
566
+ let splitAt = current.lastIndexOf("\n", maxLength);
567
+ if (splitAt === -1 || splitAt < maxLength / 2) {
568
+ splitAt = current.lastIndexOf(" ", maxLength);
569
+ }
570
+ if (splitAt === -1 || splitAt < maxLength / 2) {
571
+ splitAt = maxLength;
572
+ }
573
+ chunks.push(current.slice(0, splitAt));
574
+ current = current.slice(splitAt).trimStart();
575
+ }
576
+ return chunks;
577
+ }
578
+ async post(text) {
579
+ const url = new URL(this.endpoint);
580
+ url.searchParams.set("zapikey", this.config.apiKey);
581
+ if (this.config.bot?.name) {
582
+ url.searchParams.set("bot_unique_name", this.config.bot.name);
583
+ }
584
+ const body = {
585
+ text,
586
+ broadcast: this.config.broadcast ?? true
587
+ };
588
+ if (this.config.bot) {
589
+ body.bot = this.config.bot;
590
+ }
591
+ const response = await fetch(url.toString(), {
592
+ method: "POST",
593
+ headers: { "Content-Type": "application/json" },
594
+ body: JSON.stringify(body),
595
+ signal: AbortSignal.timeout(this.requestTimeout)
596
+ });
597
+ if (!response.ok && response.status !== 204) {
598
+ const respText = await response.text().catch(() => "");
599
+ throw new Error(`Zoho Cliq API failed: ${response.status} ${respText}`);
600
+ }
601
+ }
602
+ };
497
603
  var instanceUuid = randomUUID().slice(0, 8);
498
604
  function formatDate() {
499
605
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
@@ -851,6 +957,15 @@ function createStreams(config, state) {
851
957
  stream: telegramStream
852
958
  });
853
959
  }
960
+ for (const zohoCliqConfig of toArray(config.zohoCliq)) {
961
+ const transport = new ZohoCliqTransport(zohoCliqConfig);
962
+ transports.push(transport);
963
+ const zohoStream = createHttpTransportStream(transport, zohoCliqConfig.level, zohoCliqConfig.rules, state);
964
+ streams.push({
965
+ level: "trace",
966
+ stream: zohoStream
967
+ });
968
+ }
854
969
  for (const cloudwatchConfig of toArray(config.cloudwatch)) {
855
970
  const transport = new CloudWatchTransport(cloudwatchConfig, config.hostname);
856
971
  transports.push(transport);
@@ -1156,6 +1271,35 @@ var CloudWatchConfigSchema = z.object({
1156
1271
  createLogGroup: z.boolean().optional(),
1157
1272
  createLogStream: z.boolean().optional()
1158
1273
  });
1274
+ var ZohoCliqConfigBaseSchema = z.object({
1275
+ level: LogLevelSchema.optional(),
1276
+ rules: z.array(LevelRuleSchema).optional(),
1277
+ batchSize: z.number().int().positive().optional(),
1278
+ flushInterval: z.number().int().positive().optional(),
1279
+ maxRetries: z.number().int().nonnegative().optional(),
1280
+ retryDelay: z.number().int().positive().optional(),
1281
+ onError: z.function().optional(),
1282
+ onDrop: z.function().optional(),
1283
+ maxQueueSize: z.number().int().positive().optional(),
1284
+ dropPolicy: z.enum(["drop-oldest", "drop-newest"]).optional(),
1285
+ requestTimeout: z.number().int().positive().optional(),
1286
+ webhookUrl: z.string().url().optional(),
1287
+ companyId: z.string().min(1).optional(),
1288
+ channel: z.string().min(1).optional(),
1289
+ region: z.string().min(1).optional(),
1290
+ apiKey: z.string().min(1, "apiKey is required"),
1291
+ broadcast: z.boolean().optional(),
1292
+ bot: z.object({
1293
+ name: z.string().min(1),
1294
+ image: z.string().url().optional()
1295
+ }).optional(),
1296
+ includeTimestamp: z.boolean().optional(),
1297
+ includeMeta: z.boolean().optional()
1298
+ });
1299
+ var ZohoCliqConfigSchema = ZohoCliqConfigBaseSchema.refine(
1300
+ (cfg) => Boolean(cfg.webhookUrl) || Boolean(cfg.companyId) && Boolean(cfg.channel),
1301
+ { message: "Either webhookUrl or both companyId and channel must be provided" }
1302
+ );
1159
1303
  var RelayConfigSchema = z.object({
1160
1304
  apiUrl: z.string().url("apiUrl must be a valid URL"),
1161
1305
  token: z.string().min(1, "token is required"),
@@ -1187,6 +1331,7 @@ var LoggerConfigSchema = z.object({
1187
1331
  discord: z.union([DiscordConfigSchema, z.array(DiscordConfigSchema)]).optional(),
1188
1332
  telegram: z.union([TelegramConfigSchema, z.array(TelegramConfigSchema)]).optional(),
1189
1333
  cloudwatch: z.union([CloudWatchConfigSchema, z.array(CloudWatchConfigSchema)]).optional(),
1334
+ zohoCliq: z.union([ZohoCliqConfigSchema, z.array(ZohoCliqConfigSchema)]).optional(),
1190
1335
  relay: RelayConfigSchema.optional(),
1191
1336
  caller: z.union([z.boolean(), CallerConfigSchema]).optional(),
1192
1337
  hostname: z.string().optional(),
@@ -1848,6 +1993,6 @@ function formatLogfmt(data) {
1848
1993
  return Object.entries(flattened).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}=${formatLogfmtValue(value)}`).join(" ");
1849
1994
  }
1850
1995
 
1851
- export { AutoShutdownConfigSchema, BaseHttpTransport, CallerConfigSchema, CloudWatchConfigSchema, CloudWatchTransport, ConsoleConfigSchema, DiscordConfigSchema, DiscordTransport, FileConfigSchema, HttpTransportBaseConfigSchema, LOG_LEVELS, LevelConfigObjectSchema, LevelConfigSchema, LevelRuleSchema, LogFormatSchema, LogLevelSchema, LogStreamNameSchema, LogStreamPatternConfigSchema, LogStreamPatternSchema, LogStreamTemplateConfigSchema, Logger, LoggerConfigSchema, LoggerStore, MessageBuffer, TelegramConfigSchema, TelegramTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
1996
+ export { AutoShutdownConfigSchema, BaseHttpTransport, CallerConfigSchema, CloudWatchConfigSchema, CloudWatchTransport, ConsoleConfigSchema, DiscordConfigSchema, DiscordTransport, FileConfigSchema, HttpTransportBaseConfigSchema, LOG_LEVELS, LevelConfigObjectSchema, LevelConfigSchema, LevelRuleSchema, LogFormatSchema, LogLevelSchema, LogStreamNameSchema, LogStreamPatternConfigSchema, LogStreamPatternSchema, LogStreamTemplateConfigSchema, Logger, LoggerConfigSchema, LoggerStore, MessageBuffer, RelayConfigSchema, TelegramConfigSchema, TelegramTransport, ZohoCliqConfigSchema, ZohoCliqTransport, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatCallerInfo, formatLogfmt, formatLogfmtValue, generateRequestId, getCallerInfo, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, registerShutdown, safeValidateConfig, serializeError, validateConfig };
1852
1997
  //# sourceMappingURL=index.mjs.map
1853
1998
  //# sourceMappingURL=index.mjs.map