plutin 1.8.3 → 1.8.5

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.cjs CHANGED
@@ -495,36 +495,12 @@ var DependencyContainer = class {
495
495
  }
496
496
  static registry = /* @__PURE__ */ new Map();
497
497
  static singletons = /* @__PURE__ */ new Map();
498
- static isClass(value) {
499
- return typeof value === "function" && value.prototype !== void 0 && value.prototype.constructor === value;
500
- }
501
- /**
502
- * Registra uma classe ou instância no container
503
- * @param token - Identificador único do registro
504
- * @param classOrInstance - Classe (será instanciada) ou instância já criada
505
- * @param options - Opções de registro
506
- * @note Para instâncias: sempre retorna a mesma referência, mas apenas armazena
507
- * no cache de singletons se `singleton: true` (para consistência)
508
- */
509
- static register(token, classOrInstance, options = {
510
- singleton: true
511
- }) {
512
- if (this.isClass(classOrInstance)) {
513
- this.registry.set(token, {
514
- type: "class",
515
- myClass: classOrInstance,
516
- singleton: options.singleton
517
- });
518
- } else {
519
- this.registry.set(token, {
520
- type: "instance",
521
- instance: classOrInstance,
522
- singleton: options.singleton
523
- });
524
- if (options.singleton) {
525
- this.singletons.set(token, classOrInstance);
526
- }
527
- }
498
+ static register(token, myClass, options) {
499
+ this.registry.set(token, {
500
+ type: "class",
501
+ myClass,
502
+ singleton: options.singleton
503
+ });
528
504
  }
529
505
  static registerValue(token, value) {
530
506
  this.registry.set(token, {
@@ -554,12 +530,6 @@ var DependencyContainer = class {
554
530
  if (registration.type === "value") {
555
531
  return registration.value;
556
532
  }
557
- if (registration.type === "instance") {
558
- if (registration.singleton) {
559
- return this.singletons.get(token);
560
- }
561
- return registration.instance;
562
- }
563
533
  const { myClass, singleton } = registration;
564
534
  if (singleton) {
565
535
  if (!this.singletons.has(token)) {
@@ -1455,10 +1425,8 @@ var PinoLogger = class {
1455
1425
  static {
1456
1426
  __name(this, "PinoLogger");
1457
1427
  }
1458
- env;
1459
1428
  pinoLogger;
1460
- constructor(env) {
1461
- this.env = env;
1429
+ constructor() {
1462
1430
  const pinoConfig = {
1463
1431
  level: "debug",
1464
1432
  formatters: {
@@ -1470,7 +1438,7 @@ var PinoLogger = class {
1470
1438
  },
1471
1439
  timestamp: import_pino.default.stdTimeFunctions.isoTime
1472
1440
  };
1473
- if (this.env.ENVIRONMENT === "development") {
1441
+ if (process.env.ENVIRONMENT === "development") {
1474
1442
  this.pinoLogger = (0, import_pino.default)(pinoConfig, import_pino.default.transport({
1475
1443
  target: "pino-pretty",
1476
1444
  options: {
@@ -1523,13 +1491,11 @@ var DiscordLogger = class {
1523
1491
  static {
1524
1492
  __name(this, "DiscordLogger");
1525
1493
  }
1526
- env;
1527
1494
  webhook;
1528
1495
  pinoLogger;
1529
- constructor(env) {
1530
- this.env = env;
1531
- this.webhook = new import_discord_webhook_node.Webhook(this.env.DISCORD_WEBHOOK_URL || "");
1532
- this.pinoLogger = new PinoLogger(this.env);
1496
+ constructor() {
1497
+ this.webhook = new import_discord_webhook_node.Webhook(process.env.DISCORD_WEBHOOK_URL || "");
1498
+ this.pinoLogger = new PinoLogger();
1533
1499
  }
1534
1500
  async buildStructuredLog(embed, { msg, data, error }) {
1535
1501
  const traceId = getContext().traceId;
@@ -1547,35 +1513,35 @@ var DiscordLogger = class {
1547
1513
  }
1548
1514
  info(params) {
1549
1515
  this.pinoLogger.info(params);
1550
- const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u2139\uFE0F Info - ${this.env.ENVIRONMENT}`).setColor(3447003);
1516
+ const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u2139\uFE0F Info - ${process.env.ENVIRONMENT}`).setColor(3447003);
1551
1517
  this.buildStructuredLog(embed, params).catch(() => this.pinoLogger.info({
1552
1518
  msg: "Error to send log to Discord"
1553
1519
  }));
1554
1520
  }
1555
1521
  error(params) {
1556
1522
  this.pinoLogger.error(params);
1557
- const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u26D4 Error - ${this.env.ENVIRONMENT}`).setColor(15158332);
1523
+ const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u26D4 Error - ${process.env.ENVIRONMENT}`).setColor(15158332);
1558
1524
  this.buildStructuredLog(embed, params).catch(() => this.pinoLogger.info({
1559
1525
  msg: "Error to send log to Discord"
1560
1526
  }));
1561
1527
  }
1562
1528
  debug(params) {
1563
1529
  this.pinoLogger.debug(params);
1564
- const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u{1F41B} Degub - ${this.env.ENVIRONMENT}`).setColor(10181046);
1530
+ const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u{1F41B} Degub - ${process.env.ENVIRONMENT}`).setColor(10181046);
1565
1531
  this.buildStructuredLog(embed, params).catch(() => this.pinoLogger.info({
1566
1532
  msg: "Error to send log to Discord"
1567
1533
  }));
1568
1534
  }
1569
1535
  fatal(params) {
1570
1536
  this.pinoLogger.fatal(params);
1571
- const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u{1F480} Fatal - ${this.env.ENVIRONMENT}`).setColor(12597547);
1537
+ const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u{1F480} Fatal - ${process.env.ENVIRONMENT}`).setColor(12597547);
1572
1538
  this.buildStructuredLog(embed, params).catch(() => this.pinoLogger.info({
1573
1539
  msg: "Error to send log to Discord"
1574
1540
  }));
1575
1541
  }
1576
1542
  warn(params) {
1577
1543
  this.pinoLogger.warn(params);
1578
- const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u26A0\uFE0F Warn - ${this.env.ENVIRONMENT}`).setColor(15844367);
1544
+ const embed = new import_discord_webhook_node.MessageBuilder().setTitle(`\u26A0\uFE0F Warn - ${process.env.ENVIRONMENT}`).setColor(15844367);
1579
1545
  this.buildStructuredLog(embed, params).catch(() => this.pinoLogger.info({
1580
1546
  msg: "Error to send log to Discord"
1581
1547
  }));
@@ -1588,13 +1554,11 @@ var OtelLogger = class {
1588
1554
  static {
1589
1555
  __name(this, "OtelLogger");
1590
1556
  }
1591
- env;
1592
1557
  otelLogger;
1593
1558
  pinoLogger;
1594
- constructor(env) {
1595
- this.env = env;
1596
- this.otelLogger = import_api_logs.logs.getLogger(this.env.OTEL_SERVICE_NAME || "plutin-boilerplate-common", this.env.OTEL_SERVICE_VERSION || "1.0.0");
1597
- this.pinoLogger = new PinoLogger(this.env);
1559
+ constructor() {
1560
+ this.otelLogger = import_api_logs.logs.getLogger(process.env.OTEL_SERVICE_NAME || "plutin-boilerplate-common", process.env.OTEL_SERVICE_VERSION || "1.0.0");
1561
+ this.pinoLogger = new PinoLogger();
1598
1562
  }
1599
1563
  emitOtelLog(severityNumber, severityText, params) {
1600
1564
  const { msg, data, error } = params;
@@ -1659,11 +1623,11 @@ var Logger = class {
1659
1623
  static defineProvider(env, provider) {
1660
1624
  switch (provider) {
1661
1625
  case "console":
1662
- return new PinoLogger(env);
1626
+ return PinoLogger;
1663
1627
  case "discord":
1664
- return new DiscordLogger(env);
1628
+ return DiscordLogger;
1665
1629
  case "otel":
1666
- return env.OTEL_ENABLE === false ? new DiscordLogger(env) : new OtelLogger(env);
1630
+ return env.OTEL_ENABLE === false ? DiscordLogger : OtelLogger;
1667
1631
  default:
1668
1632
  return PinoLogger;
1669
1633
  }
@@ -1679,11 +1643,9 @@ var MetricsManager = class {
1679
1643
  static {
1680
1644
  __name(this, "MetricsManager");
1681
1645
  }
1682
- env;
1683
1646
  meter = null;
1684
- constructor(env) {
1685
- this.env = env;
1686
- this.meter = this.env.OTEL_ENABLE ? import_api.metrics.getMeter(this.env.OTEL_SERVICE_NAME || "plutin-boilerplate-common", this.env.OTEL_SERVICE_VERSION || "1.0.0") : null;
1647
+ constructor() {
1648
+ this.meter = process.env.OTEL_ENABLE === "true" ? import_api.metrics.getMeter(process.env.OTEL_SERVICE_NAME || "plutin-boilerplate-common", process.env.OTEL_SERVICE_VERSION || "1.0.0") : null;
1687
1649
  }
1688
1650
  httpRequestsTotal = this.meter?.createCounter("http_requests_total", {
1689
1651
  description: "Total de requisi\xE7\xF5es HTTP",
@@ -1796,7 +1758,7 @@ var MetricsManager = class {
1796
1758
  collectionInterval;
1797
1759
  gcObserver;
1798
1760
  recordHttpRequest(params) {
1799
- if (!this.env.OTEL_ENABLE) {
1761
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1800
1762
  return;
1801
1763
  }
1802
1764
  const { method, route, statusCode, durationSeconds, responseSizeBytes } = params;
@@ -1820,7 +1782,7 @@ var MetricsManager = class {
1820
1782
  }
1821
1783
  }
1822
1784
  recordDbQueryError(params) {
1823
- if (!this.env.OTEL_ENABLE) {
1785
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1824
1786
  return;
1825
1787
  }
1826
1788
  if (!this.isValidDbQueryErrorParams(params)) {
@@ -1835,7 +1797,7 @@ var MetricsManager = class {
1835
1797
  });
1836
1798
  }
1837
1799
  recordDbQuery(params) {
1838
- if (!this.env.OTEL_ENABLE) {
1800
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1839
1801
  return;
1840
1802
  }
1841
1803
  if (!this.isValidDbQueryParams(params)) {
@@ -1869,7 +1831,7 @@ var MetricsManager = class {
1869
1831
  return true;
1870
1832
  }
1871
1833
  recordDbTransaction(params) {
1872
- if (!this.env.OTEL_ENABLE) {
1834
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1873
1835
  return;
1874
1836
  }
1875
1837
  const { operation, repository, durationSeconds } = params;
@@ -1885,7 +1847,7 @@ var MetricsManager = class {
1885
1847
  });
1886
1848
  }
1887
1849
  recordDbDeadlock(params) {
1888
- if (!this.env.OTEL_ENABLE) {
1850
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1889
1851
  return;
1890
1852
  }
1891
1853
  const { operation, repository, errorMessage } = params;
@@ -1897,7 +1859,7 @@ var MetricsManager = class {
1897
1859
  });
1898
1860
  }
1899
1861
  recordHttpRequestBytes(bytes, attributes) {
1900
- if (!this.env.OTEL_ENABLE) {
1862
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1901
1863
  return;
1902
1864
  }
1903
1865
  this.httpRequestBytesTotal?.add(bytes, {
@@ -1907,7 +1869,7 @@ var MetricsManager = class {
1907
1869
  });
1908
1870
  }
1909
1871
  recordProcessingDuration(params) {
1910
- if (!this.env.OTEL_ENABLE) {
1872
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1911
1873
  return;
1912
1874
  }
1913
1875
  const { operation, durationSeconds } = params;
@@ -1917,7 +1879,7 @@ var MetricsManager = class {
1917
1879
  });
1918
1880
  }
1919
1881
  recordProcessingError(params) {
1920
- if (!this.env.OTEL_ENABLE) {
1882
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1921
1883
  return;
1922
1884
  }
1923
1885
  const { operation, errorType } = params;
@@ -1928,7 +1890,7 @@ var MetricsManager = class {
1928
1890
  });
1929
1891
  }
1930
1892
  recordHttpClientRequest(params) {
1931
- if (!this.env.OTEL_ENABLE) {
1893
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1932
1894
  return;
1933
1895
  }
1934
1896
  const { method, url, statusCode, durationSeconds, error, timeout } = params;
@@ -1952,7 +1914,7 @@ var MetricsManager = class {
1952
1914
  }
1953
1915
  }
1954
1916
  recordValidationError(params) {
1955
- if (!this.env.OTEL_ENABLE) {
1917
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
1956
1918
  return;
1957
1919
  }
1958
1920
  const { field, errorType } = params;
@@ -1963,7 +1925,7 @@ var MetricsManager = class {
1963
1925
  });
1964
1926
  }
1965
1927
  startSystemMetricsCollection(intervalMs = 5e3) {
1966
- if (!this.env.OTEL_ENABLE || !this.meter) {
1928
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE || !this.meter) {
1967
1929
  return;
1968
1930
  }
1969
1931
  this.eventLoopMonitor.enable();
@@ -1985,7 +1947,7 @@ var MetricsManager = class {
1985
1947
  this.collectPeriodicMetrics();
1986
1948
  }
1987
1949
  stopSystemMetricsCollection() {
1988
- if (!this.env.OTEL_ENABLE || !this.meter) {
1950
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE || !this.meter) {
1989
1951
  return;
1990
1952
  }
1991
1953
  if (this.collectionInterval) {
@@ -1999,7 +1961,7 @@ var MetricsManager = class {
1999
1961
  }
2000
1962
  }
2001
1963
  collectSystemMetrics(observableResult) {
2002
- if (!this.env.OTEL_ENABLE) {
1964
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
2003
1965
  return;
2004
1966
  }
2005
1967
  const attributes = {
@@ -2040,7 +2002,7 @@ var MetricsManager = class {
2040
2002
  observableResult.observe(this.processUptimeSeconds, process.uptime(), attributes);
2041
2003
  }
2042
2004
  collectPeriodicMetrics() {
2043
- if (!this.env.OTEL_ENABLE) {
2005
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
2044
2006
  return;
2045
2007
  }
2046
2008
  const attributes = {
@@ -2064,7 +2026,7 @@ var MetricsManager = class {
2064
2026
  }
2065
2027
  }
2066
2028
  setupGCObserver() {
2067
- if (!this.env.OTEL_ENABLE) {
2029
+ if (process.env.OTEL_ENABLE === "false" || !process.env.OTEL_ENABLE) {
2068
2030
  return;
2069
2031
  }
2070
2032
  try {
@@ -2137,7 +2099,6 @@ var OtelManager = class {
2137
2099
  static {
2138
2100
  __name(this, "OtelManager");
2139
2101
  }
2140
- env;
2141
2102
  resource;
2142
2103
  loggerProvider;
2143
2104
  sdk;
@@ -2146,8 +2107,7 @@ var OtelManager = class {
2146
2107
  metricExporter;
2147
2108
  metricReader;
2148
2109
  sampler;
2149
- constructor(env) {
2150
- this.env = env;
2110
+ constructor() {
2151
2111
  this.resource = this.createResource();
2152
2112
  this.otlpLogExporter = this.createOtlpLogExporter();
2153
2113
  this.loggerProvider = this.createLoggerProvider();
@@ -2159,14 +2119,14 @@ var OtelManager = class {
2159
2119
  }
2160
2120
  createResource() {
2161
2121
  return new import_resources.Resource({
2162
- [import_semantic_conventions.ATTR_SERVICE_NAME]: this.env.OTEL_SERVICE_NAME || "plutin-boilerplate-common",
2163
- [import_semantic_conventions.ATTR_SERVICE_VERSION]: this.env.OTEL_SERVICE_VERSION || "1.0.0",
2164
- [import_semantic_conventions.SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: this.env.ENVIRONMENT
2122
+ [import_semantic_conventions.ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || "plutin-boilerplate-common",
2123
+ [import_semantic_conventions.ATTR_SERVICE_VERSION]: process.env.OTEL_SERVICE_VERSION || "1.0.0",
2124
+ [import_semantic_conventions.SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: process.env.ENVIRONMENT
2165
2125
  });
2166
2126
  }
2167
2127
  createOtlpLogExporter() {
2168
2128
  return new import_exporter_logs_otlp_http.OTLPLogExporter({
2169
- url: `${this.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/logs`,
2129
+ url: `${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/logs`,
2170
2130
  compression: import_otlp_exporter_base.CompressionAlgorithm.GZIP
2171
2131
  });
2172
2132
  }
@@ -2183,19 +2143,19 @@ var OtelManager = class {
2183
2143
  }
2184
2144
  createTraceExporter() {
2185
2145
  return new import_exporter_trace_otlp_http.OTLPTraceExporter({
2186
- url: `${this.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,
2146
+ url: `${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,
2187
2147
  compression: import_otlp_exporter_base.CompressionAlgorithm.GZIP
2188
2148
  });
2189
2149
  }
2190
2150
  createSampler() {
2191
2151
  const DEVELOPMENT_SAMPLE_RATE = 1;
2192
2152
  const PRODUCTION_SAMPLE_RATE = 0.01;
2193
- const sampleRate = this.env.ENVIRONMENT === "development" ? DEVELOPMENT_SAMPLE_RATE : PRODUCTION_SAMPLE_RATE;
2153
+ const sampleRate = process.env.ENVIRONMENT === "development" ? DEVELOPMENT_SAMPLE_RATE : PRODUCTION_SAMPLE_RATE;
2194
2154
  return new import_sdk_trace_node.TraceIdRatioBasedSampler(sampleRate);
2195
2155
  }
2196
2156
  createMetricExporter() {
2197
2157
  return new import_exporter_metrics_otlp_http.OTLPMetricExporter({
2198
- url: `${this.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics`,
2158
+ url: `${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics`,
2199
2159
  compression: import_otlp_exporter_base.CompressionAlgorithm.GZIP
2200
2160
  });
2201
2161
  }
@@ -2519,7 +2479,7 @@ function resolveLogger() {
2519
2479
  try {
2520
2480
  return DependencyContainer.resolveToken("Logger");
2521
2481
  } catch {
2522
- return new PinoLogger(process.env);
2482
+ return new PinoLogger();
2523
2483
  }
2524
2484
  }
2525
2485
  __name(resolveLogger, "resolveLogger");