@nicollasfrazao/liguelead-log-service 1.1.0 → 1.1.2

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/README.md CHANGED
@@ -62,16 +62,33 @@ process.env.LOG_AWS_ACCESS_KEY_ID = 'test';
62
62
  process.env.LOG_AWS_SECRET_ACCESS_KEY = 'test';
63
63
  ```
64
64
 
65
- #### Usando ARN do Firehose (recomendado)
65
+ #### Usando IAM Role (recomendado)
66
66
  ```typescript
67
- // Configuração com ARN - extrai automaticamente região e nome do stream
67
+ // Configuração com IAM Role
68
68
  process.env.LOG_USE_S3_STORAGE = 'true';
69
- process.env.LOG_FIREHOSE_STREAM_ARN = 'arn:aws:firehose:us-east-1:123456789012:deliverystream/my-app-logs-firehose';
69
+ process.env.LOG_AWS_ROLE_ARN = 'arn:aws:iam::0000000000:role/my-firehose-delivery-role';
70
70
 
71
71
  // As variáveis LOG_AWS_REGION e LOG_FIREHOSE_STREAM_NAME são opcionais quando usar ARN
72
72
  // A região e nome do stream são extraídos automaticamente do ARN
73
73
  ```
74
74
 
75
+ #### Autenticação via IAM Role ARN (Nova Funcionalidade!)
76
+ ```typescript
77
+ // Configuração para usar IAM Role com AssumeRole
78
+ process.env.LOG_USE_S3_STORAGE = 'true';
79
+ process.env.LOG_FIREHOSE_STREAM_NAME = 'my-app-logs-firehose';
80
+ process.env.LOG_AWS_REGION = 'us-east-1';
81
+ process.env.LOG_AWS_ROLE_ARN = 'arn:aws:iam::0000000000:role/my-firehose-delivery-role';
82
+
83
+ // O serviço automaticamente:
84
+ // ✅ Assume a role usando STS
85
+ // ✅ Obtém credenciais temporárias
86
+ // ✅ Renova automaticamente antes da expiração
87
+ // ✅ Cache inteligente para performance
88
+ ```
89
+
90
+ 📖 **Documentação Completa**: [AWS IAM Role Support](./docs/aws-iam-role-support.md)
91
+
75
92
  ### 3. Logging Manual
76
93
 
77
94
  ```typescript
@@ -129,6 +146,7 @@ app.post('/api/process', async (req, res) => {
129
146
  - ✅ **Armazenamento via Kinesis Firehose** para S3 com buffering e compressão
130
147
  - ✅ **Fallback para armazenamento local** em caso de falha do S3
131
148
  - ✅ **Padrão de serviço estático** - sem necessidade de instanciação
149
+ - ✅ **Autenticação via IAM Role ARN** (AssumeRole automático, cache, renovação, cross-account)
132
150
 
133
151
  ## Estrutura dos Arquivos de Log
134
152
 
@@ -220,8 +238,8 @@ NODE_ENV=development # development|production|homologation|tes
220
238
  # S3 via Kinesis Firehose
221
239
  LOG_USE_S3_STORAGE=true # Ativa envio para S3 via Firehose
222
240
 
223
- # Opção 1: Usar ARN do Firehose (recomendado)
224
- LOG_FIREHOSE_STREAM_ARN=arn:aws:firehose:us-east-1:123456789012:deliverystream/my-app-logs-firehose
241
+ # Opção 1: Usar IAM Role (recomendado)
242
+ LOG_AWS_ROLE_ARN=arn:aws:iam::0000000000:role/my-firehose-delivery-role
225
243
 
226
244
  # Opção 2: Usar nome e região separadamente
227
245
  LOG_FIREHOSE_STREAM_NAME=my-app-logs # Nome do stream Kinesis Firehose
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.config.d.ts","sourceRoot":"","sources":["../../src/configs/log.storage.external.s3.config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0CAA0C,EAAE,MAAM,gEAAgE,CAAC;AAM5H;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QAAO,0CAmChD,CAAA"}
1
+ {"version":3,"file":"log.storage.external.s3.config.d.ts","sourceRoot":"","sources":["../../src/configs/log.storage.external.s3.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0CAA0C,EAAE,MAAM,gEAAgE,CAAC;AAE5H;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QAAO,0CA4BhD,CAAA"}
@@ -1,39 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLogStorageExternalS3Config = void 0;
4
- const log_error_1 = require("../errors/log.error");
5
- const arn_helper_1 = require("../helpers/arn.helper");
6
4
  /**
7
5
  * Get Log Storage External S3 Configuration
8
6
  *
9
7
  * @returns {LogStorageExternalS3ServiceConfigInterface} Log Storage External S3 Configuration
10
8
  */
11
9
  const getLogStorageExternalS3Config = () => {
12
- const firehoseArn = process.env.LOG_FIREHOSE_STREAM_ARN;
13
- let firehoseStreamName = process.env.LOG_FIREHOSE_STREAM_NAME || 'log-service-firehose';
14
- let region = process.env.LOG_AWS_REGION || 'us-east-1';
15
- if (firehoseArn) {
16
- if (!arn_helper_1.ArnHelper.isFirehoseDeliveryStreamARN(firehoseArn)) {
17
- throw new log_error_1.LogError(`Invalid Kinesis Firehose delivery stream ARN: ${firehoseArn}`);
18
- }
19
- firehoseStreamName = arn_helper_1.ArnHelper.getFirehoseStreamNameFromARN(firehoseArn);
20
- region = arn_helper_1.ArnHelper.getRegionFromARN(firehoseArn);
21
- }
22
10
  let config = {
23
- firehoseStreamName,
24
- firehoseStreamArn: firehoseArn,
25
- region,
11
+ firehoseStreamName: process.env.LOG_FIREHOSE_STREAM_NAME || 'log-service-firehose',
12
+ region: process.env.LOG_AWS_REGION || 'us-east-1',
26
13
  version: 'latest',
27
14
  };
15
+ if (process.env.LOG_AWS_ROLE_ARN) {
16
+ config.roleArn = process.env.LOG_AWS_ROLE_ARN;
17
+ }
28
18
  if (process.env.LOG_AWS_ACCESS_KEY_ID
29
19
  && process.env.LOG_AWS_SECRET_ACCESS_KEY) {
30
20
  config = {
31
21
  ...config,
32
- endpoint: process.env.LOG_AWS_ENDPOINT || 'http://localhost:4566',
33
22
  accessKeyId: process.env.LOG_AWS_ACCESS_KEY_ID,
34
23
  secretAccessKey: process.env.LOG_AWS_SECRET_ACCESS_KEY,
35
24
  };
36
25
  }
26
+ if (process.env.LOG_AWS_ENDPOINT) {
27
+ config.endpoint = process.env.LOG_AWS_ENDPOINT;
28
+ }
37
29
  return config;
38
30
  };
39
31
  exports.getLogStorageExternalS3Config = getLogStorageExternalS3Config;
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.config.js","sourceRoot":"","sources":["../../src/configs/log.storage.external.s3.config.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,sDAG+B;AAE/B;;;;GAIG;AACI,MAAM,6BAA6B,GAAG,GAA+C,EAAE;IAE5F,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACxD,IAAI,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,sBAAsB,CAAC;IACxF,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,WAAW,CAAC;IAEvD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,CAAC,sBAAS,CAAC,2BAA2B,CAAC,WAAW,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,oBAAQ,CAAC,iDAAiD,WAAW,EAAE,CAAC,CAAC;QACrF,CAAC;QAED,kBAAkB,GAAG,sBAAS,CAAC,4BAA4B,CAAC,WAAW,CAAC,CAAC;QACzE,MAAM,GAAG,sBAAS,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,MAAM,GAA+C;QACvD,kBAAkB;QAClB,iBAAiB,EAAE,WAAW;QAC9B,MAAM;QACN,OAAO,EAAE,QAAQ;KAClB,CAAC;IAEF,IACE,OAAO,CAAC,GAAG,CAAC,qBAAqB;WAC9B,OAAO,CAAC,GAAG,CAAC,yBAAyB,EACxC,CAAC;QACD,MAAM,GAAG;YACP,GAAG,MAAM;YACT,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,uBAAuB;YACjE,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC9C,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;SACvD,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAA;AAnCY,QAAA,6BAA6B,iCAmCzC"}
1
+ {"version":3,"file":"log.storage.external.s3.config.js","sourceRoot":"","sources":["../../src/configs/log.storage.external.s3.config.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACI,MAAM,6BAA6B,GAAG,GAA+C,EAAE;IAE5F,IAAI,MAAM,GAA+C;QACvD,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,sBAAsB;QAClF,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,WAAW;QACjD,OAAO,EAAE,QAAQ;KAClB,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAChD,CAAC;IAED,IACE,OAAO,CAAC,GAAG,CAAC,qBAAqB;WAC9B,OAAO,CAAC,GAAG,CAAC,yBAAyB,EACxC,CAAC;QACD,MAAM,GAAG;YACP,GAAG,MAAM;YACT,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC9C,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;SACvD,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjC,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IACjD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAA;AA5BY,QAAA,6BAA6B,iCA4BzC"}
package/dist/index.d.ts CHANGED
@@ -19,6 +19,4 @@ export { LogStorageLocalService } from './services/log.storage.local.service';
19
19
  export { LogStorageExternalS3Service } from './services/log.storage.external.s3.service';
20
20
  export { LogStorageExternalService } from './services/log.storage.external.service';
21
21
  export type { LogStorageBaseServiceInterface } from './interfaces/log.storage.base.service.interface';
22
- export { ArnHelper } from './helpers/arn.helper';
23
- export type { ArnInterface } from './helpers/arn.helper';
24
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG9C,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,YAAY,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC3F,YAAY,EAAE,0CAA0C,EAAE,MAAM,+DAA+D,CAAC;AAGhI,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAGzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAGpF,YAAY,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AAGtG,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG9C,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,YAAY,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC3F,YAAY,EAAE,0CAA0C,EAAE,MAAM,+DAA+D,CAAC;AAGhI,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAGzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAGpF,YAAY,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC"}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * (local files + S3 via Kinesis Firehose) and comprehensive request tracking.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ArnHelper = exports.LogStorageExternalService = exports.LogStorageExternalS3Service = exports.LogStorageLocalService = exports.LogStorageBaseService = exports.LogStorageService = exports.getLogStorageExternalS3Config = exports.getLogServiceConfig = exports.LogError = exports.logMiddleware = exports.LogService = void 0;
9
+ exports.LogStorageExternalService = exports.LogStorageExternalS3Service = exports.LogStorageLocalService = exports.LogStorageBaseService = exports.LogStorageService = exports.getLogStorageExternalS3Config = exports.getLogServiceConfig = exports.LogError = exports.logMiddleware = exports.LogService = void 0;
10
10
  // Main service exports
11
11
  var log_service_1 = require("./services/log.service");
12
12
  Object.defineProperty(exports, "LogService", { enumerable: true, get: function () { return log_service_1.LogService; } });
@@ -32,7 +32,4 @@ var log_storage_external_s3_service_1 = require("./services/log.storage.external
32
32
  Object.defineProperty(exports, "LogStorageExternalS3Service", { enumerable: true, get: function () { return log_storage_external_s3_service_1.LogStorageExternalS3Service; } });
33
33
  var log_storage_external_service_1 = require("./services/log.storage.external.service");
34
34
  Object.defineProperty(exports, "LogStorageExternalService", { enumerable: true, get: function () { return log_storage_external_service_1.LogStorageExternalService; } });
35
- // ARN utilities export
36
- var arn_helper_1 = require("./helpers/arn.helper");
37
- Object.defineProperty(exports, "ArnHelper", { enumerable: true, get: function () { return arn_helper_1.ArnHelper; } });
38
35
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uBAAuB;AACvB,sDAAoD;AAA3C,yGAAA,UAAU,OAAA;AAEnB,uBAAuB;AACvB,+DAA6D;AAApD,+GAAA,aAAa,OAAA;AAEtB,yBAAyB;AACzB,gDAA8C;AAArC,qGAAA,QAAQ,OAAA;AAUjB,wBAAwB;AACxB,mEAAmE;AAA1D,yHAAA,mBAAmB,OAAA;AAC5B,2FAAyF;AAAhF,+IAAA,6BAA6B,OAAA;AAEtC,+CAA+C;AAC/C,sEAAmE;AAA1D,wHAAA,iBAAiB,OAAA;AAC1B,gFAA4E;AAAnE,iIAAA,qBAAqB,OAAA;AAC9B,kFAA8E;AAArE,mIAAA,sBAAsB,OAAA;AAC/B,8FAAyF;AAAhF,8IAAA,2BAA2B,OAAA;AACpC,wFAAoF;AAA3E,yIAAA,yBAAyB,OAAA;AAKlC,uBAAuB;AACvB,mDAAiD;AAAxC,uGAAA,SAAS,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uBAAuB;AACvB,sDAAoD;AAA3C,yGAAA,UAAU,OAAA;AAEnB,uBAAuB;AACvB,+DAA6D;AAApD,+GAAA,aAAa,OAAA;AAEtB,yBAAyB;AACzB,gDAA8C;AAArC,qGAAA,QAAQ,OAAA;AAUjB,wBAAwB;AACxB,mEAAmE;AAA1D,yHAAA,mBAAmB,OAAA;AAC5B,2FAAyF;AAAhF,+IAAA,6BAA6B,OAAA;AAEtC,+CAA+C;AAC/C,sEAAmE;AAA1D,wHAAA,iBAAiB,OAAA;AAC1B,gFAA4E;AAAnE,iIAAA,qBAAqB,OAAA;AAC9B,kFAA8E;AAArE,mIAAA,sBAAsB,OAAA;AAC/B,8FAAyF;AAAhF,8IAAA,2BAA2B,OAAA;AACpC,wFAAoF;AAA3E,yIAAA,yBAAyB,OAAA"}
@@ -6,10 +6,10 @@
6
6
  * @property {string} region - AWS region for S3/Firebase
7
7
  * @property {string} version - AWS SDK version
8
8
  * @property {string} firehoseStreamName - Kinesis Firehose stream name
9
- * @property {string} firehoseStreamArn - Kinesis Firehose stream ARN (alternative to firehoseStreamName)
10
9
  * @property {string} endpoint - Custom S3 endpoint (optional)
11
10
  * @property {string} accessKeyId - AWS access key ID (optional)
12
11
  * @property {string} secretAccessKey - AWS secret access key (optional)
12
+ * @property {string} roleArn - AWS IAM role ARN for assume role authentication (optional)
13
13
  */
14
14
  export interface LogStorageExternalS3ServiceConfigInterface {
15
15
  /**
@@ -24,10 +24,6 @@ export interface LogStorageExternalS3ServiceConfigInterface {
24
24
  * @var {string}
25
25
  */
26
26
  firehoseStreamName: string;
27
- /**
28
- * @var {string} - Kinesis Firehose stream ARN (optional, alternative to firehoseStreamName)
29
- */
30
- firehoseStreamArn?: string;
31
27
  /**
32
28
  * @var {string}
33
29
  */
@@ -40,5 +36,9 @@ export interface LogStorageExternalS3ServiceConfigInterface {
40
36
  * @var {string}
41
37
  */
42
38
  secretAccessKey?: string;
39
+ /**
40
+ * @var {string}
41
+ */
42
+ roleArn?: string;
43
43
  }
44
44
  //# sourceMappingURL=log.storage.external.s3.service.config.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.service.config.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/log.storage.external.s3.service.config.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,0CAA0C;IAEzD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B"}
1
+ {"version":3,"file":"log.storage.external.s3.service.config.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/log.storage.external.s3.service.config.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,0CAA0C;IAEzD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
@@ -9,6 +9,7 @@ import { LogType } from '../types/log.type';
9
9
  * @property {FirehoseClient} firehose
10
10
  * @property {LogStorageExternalS3ServiceConfigInterface} config
11
11
  * @property {Map<string, Promise<void>>} writeQueue
12
+ * @property {Promise<any> | null} credentialsCache
12
13
  */
13
14
  export declare class LogStorageExternalS3Service extends LogStorageExternalService {
14
15
  /**
@@ -23,6 +24,10 @@ export declare class LogStorageExternalS3Service extends LogStorageExternalServi
23
24
  * @var {Map<string, Promise<void>>}
24
25
  */
25
26
  private writeQueue;
27
+ /**
28
+ * @var {Promise<any> | null}
29
+ */
30
+ private credentialsCache;
26
31
  /**
27
32
  * Constructor of the LogStorageS3Service
28
33
  *
@@ -35,6 +40,18 @@ export declare class LogStorageExternalS3Service extends LogStorageExternalServi
35
40
  * @returns {boolean} True if the storage target should be used, false otherwise
36
41
  */
37
42
  shouldUse(): boolean;
43
+ /**
44
+ * Gets temporary credentials using STS AssumeRole
45
+ *
46
+ * @returns {Promise<any>} Credentials object for AWS SDK
47
+ */
48
+ private getAssumeRoleCredentials;
49
+ /**
50
+ * Refreshes temporary credentials using STS AssumeRole
51
+ *
52
+ * @returns {Promise<any>} Fresh credentials object for AWS SDK
53
+ */
54
+ private refreshAssumeRoleCredentials;
38
55
  /**
39
56
  * Upload log content to Firehose (which delivers to S3)
40
57
  *
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,yBAAyB;IAExE;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAiB;IAEjC;;OAEG;IACH,OAAO,CAAC,MAAM,CAA6C;IAE3D;;OAEG;IACH,OAAO,CAAC,UAAU,CAAyC;IAE3D;;;;OAIG;gBACU,gBAAgB,EAAE,yBAAyB;IA4BxD;;;;OAIG;IACI,SAAS,IAAI,OAAO;IAK3B;;;;;;;OAOG;YACW,SAAS;IAmBvB;;;;;;;;OAQG;YACW,SAAS;IAgCvB;;;;;;OAMG;IACU,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAoBjD"}
1
+ {"version":3,"file":"log.storage.external.s3.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C;;;;;;;;;GASG;AACH,qBAAa,2BAA4B,SAAQ,yBAAyB;IAExE;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAiB;IAEjC;;OAEG;IACH,OAAO,CAAC,MAAM,CAA6C;IAE3D;;OAEG;IACH,OAAO,CAAC,UAAU,CAAyC;IAE3D;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAA6B;IAErD;;;;OAIG;gBACU,gBAAgB,EAAE,yBAAyB;IA6BxD;;;;OAIG;IACI,SAAS,IAAI,OAAO;IAK3B;;;;OAIG;YACW,wBAAwB;IAqCtC;;;;OAIG;YACW,4BAA4B;IAsC1C;;;;;;;OAOG;YACW,SAAS;IAmBvB;;;;;;;;OAQG;YACW,SAAS;IAgCvB;;;;;;OAMG;IACU,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAoBjD"}
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LogStorageExternalS3Service = void 0;
4
4
  const client_firehose_1 = require("@aws-sdk/client-firehose");
5
+ const client_sts_1 = require("@aws-sdk/client-sts");
5
6
  const log_storage_external_service_1 = require("./log.storage.external.service");
6
7
  const log_service_1 = require("./log.service");
7
8
  const log_storage_external_s3_config_1 = require("../configs/log.storage.external.s3.config");
9
+ const log_error_1 = require("../errors/log.error");
8
10
  /**
9
11
  * Class LogStorageExternalS3Service
10
12
  *
@@ -13,6 +15,7 @@ const log_storage_external_s3_config_1 = require("../configs/log.storage.externa
13
15
  * @property {FirehoseClient} firehose
14
16
  * @property {LogStorageExternalS3ServiceConfigInterface} config
15
17
  * @property {Map<string, Promise<void>>} writeQueue
18
+ * @property {Promise<any> | null} credentialsCache
16
19
  */
17
20
  class LogStorageExternalS3Service extends log_storage_external_service_1.LogStorageExternalService {
18
21
  /**
@@ -26,22 +29,27 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
26
29
  * @var {Map<string, Promise<void>>}
27
30
  */
28
31
  this.writeQueue = new Map();
32
+ /**
33
+ * @var {Promise<any> | null}
34
+ */
35
+ this.credentialsCache = null;
29
36
  this.config = (0, log_storage_external_s3_config_1.getLogStorageExternalS3Config)();
30
- let firehoseConfig = {
37
+ const firehoseConfig = {
31
38
  region: this.config.region,
32
- endpoint: this.config.endpoint,
33
39
  };
34
- if (this.config.accessKeyId
40
+ if (this.config.roleArn) {
41
+ firehoseConfig.credentials = () => this.getAssumeRoleCredentials();
42
+ }
43
+ else if (this.config.accessKeyId
35
44
  && this.config.secretAccessKey) {
36
- firehoseConfig = {
37
- region: this.config.region,
38
- endpoint: this.config.endpoint,
39
- credentials: {
40
- accessKeyId: this.config.accessKeyId,
41
- secretAccessKey: this.config.secretAccessKey,
42
- },
45
+ firehoseConfig.credentials = {
46
+ accessKeyId: this.config.accessKeyId,
47
+ secretAccessKey: this.config.secretAccessKey,
43
48
  };
44
49
  }
50
+ if (this.config.endpoint) {
51
+ firehoseConfig.endpoint = this.config.endpoint;
52
+ }
45
53
  this.firehose = new client_firehose_1.FirehoseClient(firehoseConfig);
46
54
  }
47
55
  /**
@@ -52,6 +60,72 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
52
60
  shouldUse() {
53
61
  return this.logServiceConfig.useS3Storage;
54
62
  }
63
+ /**
64
+ * Gets temporary credentials using STS AssumeRole
65
+ *
66
+ * @returns {Promise<any>} Credentials object for AWS SDK
67
+ */
68
+ async getAssumeRoleCredentials() {
69
+ if (!this.config.roleArn) {
70
+ throw new Error('Role ARN is required for AssumeRole authentication');
71
+ }
72
+ if (this.credentialsCache) {
73
+ try {
74
+ const credentials = await this.credentialsCache;
75
+ let expirationTime;
76
+ if (credentials.expiration instanceof Date) {
77
+ expirationTime = credentials.expiration;
78
+ }
79
+ else {
80
+ expirationTime = new Date(credentials.expiration);
81
+ credentials.expiration = expirationTime;
82
+ }
83
+ const now = new Date();
84
+ const bufferTime = 5 * 60 * 1000;
85
+ if (expirationTime.getTime() - now.getTime() > bufferTime) {
86
+ return credentials;
87
+ }
88
+ }
89
+ catch (error) {
90
+ console.warn('Cached credentials failed, refreshing:', error);
91
+ }
92
+ }
93
+ this.credentialsCache = this.refreshAssumeRoleCredentials();
94
+ return this.credentialsCache;
95
+ }
96
+ /**
97
+ * Refreshes temporary credentials using STS AssumeRole
98
+ *
99
+ * @returns {Promise<any>} Fresh credentials object for AWS SDK
100
+ */
101
+ async refreshAssumeRoleCredentials() {
102
+ const stsClient = new client_sts_1.STSClient({
103
+ region: this.config.region,
104
+ endpoint: this.config.endpoint
105
+ });
106
+ const command = new client_sts_1.AssumeRoleCommand({
107
+ RoleArn: this.config.roleArn,
108
+ RoleSessionName: `log-service-session-${Date.now()}`,
109
+ DurationSeconds: 3600, // 1 hour
110
+ });
111
+ try {
112
+ const response = await stsClient.send(command);
113
+ if (!response.Credentials) {
114
+ throw new log_error_1.LogError('Failed to retrieve credentials from STS AssumeRole');
115
+ }
116
+ return {
117
+ accessKeyId: response.Credentials.AccessKeyId,
118
+ secretAccessKey: response.Credentials.SecretAccessKey,
119
+ sessionToken: response.Credentials.SessionToken,
120
+ expiration: response.Credentials.Expiration,
121
+ };
122
+ }
123
+ catch (error) {
124
+ console.error('Failed to assume role:', error);
125
+ this.credentialsCache = null;
126
+ throw error;
127
+ }
128
+ }
55
129
  /**
56
130
  * Upload log content to Firehose (which delivers to S3)
57
131
  *
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.service.js","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":";;;AAAA,8DAA4E;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KAAK,CACX,6CAA6C,EAC7C,KAAK,CACN,CAAC;YAEF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA3JD,kEA2JC"}
1
+ {"version":3,"file":"log.storage.external.s3.service.js","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":";;;AAAA,8DAA4E;AAC5E,oDAAmE;AACnE,iFAA2E;AAG3E,+CAA2C;AAE3C,8FAA0F;AAC1F,mDAA+C;AAE/C;;;;;;;;;GASG;AACH,MAAa,2BAA4B,SAAQ,wDAAyB;IAsBxE;;;;OAIG;IACH,YAAa,gBAA2C;QAEtD,KAAK,CAAE,gBAAgB,CAAC,CAAC;QAjB3B;;WAEG;QACK,eAAU,GAA+B,IAAI,GAAG,EAAE,CAAC;QAE3D;;WAEG;QACK,qBAAgB,GAAwB,IAAI,CAAC;QAWnD,IAAI,CAAC,MAAM,GAAG,IAAA,8DAA6B,GAAE,CAAC;QAE9C,MAAM,cAAc,GAAQ;YAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;SAC3B,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,cAAc,CAAC,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QACrE,CAAC;aAAM,IACL,IAAI,CAAC,MAAM,CAAC,WAAW;eACpB,IAAI,CAAC,MAAM,CAAC,eAAe,EAC9B,CAAC;YACD,cAAc,CAAC,WAAW,GAAG;gBAC3B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;gBACpC,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,eAAe;aAC7C,CAAC;QACJ,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACzB,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,QAAQ,GA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K,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,6CAA6C,EAC7C,KAAK,CACN,CAAC;YAEF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAtPD,kEAsPC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicollasfrazao/liguelead-log-service",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A standalone logging service for Express applications with multi-destination storage (local files + S3 via Kinesis Firehose) and comprehensive request tracking using strategy pattern.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,6 +49,7 @@
49
49
  "dependencies": {
50
50
  "@aws-sdk/client-firehose": "^3.658.1",
51
51
  "@aws-sdk/client-s3": "^3.658.1",
52
+ "@aws-sdk/client-sts": "^3.921.0",
52
53
  "uuid": "^9.0.1"
53
54
  },
54
55
  "devDependencies": {
@@ -1,79 +0,0 @@
1
- /**
2
- * Utilities for working with AWS ARNs
3
- */
4
- /**
5
- * Interface ArnInterface
6
- *
7
- * Represents the components of a parsed AWS ARN.
8
- *
9
- * @property {string} service - The AWS service (e.g., 'firehose')
10
- * @property {string} region - The AWS region (e.g., 'us-east-1')
11
- * @property {string} accountId - The AWS account ID
12
- * @property {string} resourceType - The type of resource (e.g., 'deliverystream')
13
- * @property {string} resourceName - The name of the resource
14
- * @property {string} fullArn - The full ARN string
15
- */
16
- export interface ArnInterface {
17
- service: string;
18
- region: string;
19
- accountId: string;
20
- resourceType: string;
21
- resourceName: string;
22
- fullArn: string;
23
- }
24
- /**
25
- * Class ArnHelper
26
- *
27
- * Provides utility functions for parsing and validating AWS ARNs.
28
- */
29
- export declare class ArnHelper {
30
- /**
31
- * Parses an AWS ARN and extracts its components
32
- *
33
- * @param {string} arn - The AWS ARN to parse
34
- *
35
- * @throws {LogError} if ARN format is invalid
36
- *
37
- * @returns {ArnInterface} Parsed ARN components
38
- *
39
- * @example
40
- * const parsed = parseARN('arn:aws:firehose:us-east-1:123456789012:deliverystream/my-app-logs-firehose');
41
- * // Returns:
42
- * // {
43
- * // service: 'firehose',
44
- * // region: 'us-east-1',
45
- * // accountId: '123456789012',
46
- * // resourceType: 'deliverystream',
47
- * // resourceName: 'my-app-logs-firehose',
48
- * // fullArn: 'arn:aws:firehose:us-east-1:123456789012:deliverystream/my-app-logs-firehose'
49
- * // }
50
- */
51
- private static parseARN;
52
- /**
53
- * Validates if an ARN is for a Kinesis Firehose delivery stream
54
- *
55
- * @param {string} arn - The AWS ARN to validate
56
- *
57
- * @returns {boolean} true if it's a valid Firehose delivery stream ARN
58
- */
59
- static isFirehoseDeliveryStreamARN(arn: string): boolean;
60
- /**
61
- * Extracts Firehose delivery stream name from ARN
62
- *
63
- * @param {string} arn - The Kinesis Firehose ARN
64
- *
65
- * @throws {Error} if ARN is not a valid Firehose delivery stream ARN
66
- *
67
- * @returns {string} The delivery stream name
68
- */
69
- static getFirehoseStreamNameFromARN(arn: string): string;
70
- /**
71
- * Extracts AWS region from ARN
72
- *
73
- * @param {string} arn - The AWS ARN
74
- *
75
- * @returns {string} The AWS region
76
- */
77
- static getRegionFromARN(arn: string): string;
78
- }
79
- //# sourceMappingURL=arn.helper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arn.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/arn.helper.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACpB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;IA2CvB;;;;;;OAMG;WACW,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAY/D;;;;;;;;OAQG;WACW,4BAA4B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAW/D;;;;;;OAMG;WACW,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAMpD"}
@@ -1,107 +0,0 @@
1
- "use strict";
2
- /**
3
- * Utilities for working with AWS ARNs
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ArnHelper = void 0;
7
- const log_error_1 = require("../errors/log.error");
8
- /**
9
- * Class ArnHelper
10
- *
11
- * Provides utility functions for parsing and validating AWS ARNs.
12
- */
13
- class ArnHelper {
14
- /**
15
- * Parses an AWS ARN and extracts its components
16
- *
17
- * @param {string} arn - The AWS ARN to parse
18
- *
19
- * @throws {LogError} if ARN format is invalid
20
- *
21
- * @returns {ArnInterface} Parsed ARN components
22
- *
23
- * @example
24
- * const parsed = parseARN('arn:aws:firehose:us-east-1:123456789012:deliverystream/my-app-logs-firehose');
25
- * // Returns:
26
- * // {
27
- * // service: 'firehose',
28
- * // region: 'us-east-1',
29
- * // accountId: '123456789012',
30
- * // resourceType: 'deliverystream',
31
- * // resourceName: 'my-app-logs-firehose',
32
- * // fullArn: 'arn:aws:firehose:us-east-1:123456789012:deliverystream/my-app-logs-firehose'
33
- * // }
34
- */
35
- static parseARN(arn) {
36
- if (!arn
37
- || typeof arn !== 'string') {
38
- throw new log_error_1.LogError('ARN must be a non-empty string');
39
- }
40
- const arnRegex = /^arn:aws:([^:]+):([^:]*):([^:]*):(.+)$/;
41
- const match = arn.match(arnRegex);
42
- if (!match) {
43
- throw new log_error_1.LogError(`Invalid ARN format: ${arn}`);
44
- }
45
- const [, service, region, accountId, resource] = match;
46
- const resourceParts = resource.split(/[/:]/);
47
- if (resourceParts.length < 2) {
48
- throw new log_error_1.LogError(`Invalid resource format in ARN: ${arn}`);
49
- }
50
- const resourceType = resourceParts[0];
51
- const resourceName = resourceParts.slice(1).join('/'); // Handle cases with multiple slashes
52
- return {
53
- service,
54
- region,
55
- accountId,
56
- resourceType,
57
- resourceName,
58
- fullArn: arn
59
- };
60
- }
61
- /**
62
- * Validates if an ARN is for a Kinesis Firehose delivery stream
63
- *
64
- * @param {string} arn - The AWS ARN to validate
65
- *
66
- * @returns {boolean} true if it's a valid Firehose delivery stream ARN
67
- */
68
- static isFirehoseDeliveryStreamARN(arn) {
69
- try {
70
- const parsed = this.parseARN(arn);
71
- return parsed.service === 'firehose'
72
- && parsed.resourceType === 'deliverystream';
73
- }
74
- catch {
75
- return false;
76
- }
77
- }
78
- /**
79
- * Extracts Firehose delivery stream name from ARN
80
- *
81
- * @param {string} arn - The Kinesis Firehose ARN
82
- *
83
- * @throws {Error} if ARN is not a valid Firehose delivery stream ARN
84
- *
85
- * @returns {string} The delivery stream name
86
- */
87
- static getFirehoseStreamNameFromARN(arn) {
88
- if (!this.isFirehoseDeliveryStreamARN(arn)) {
89
- throw new log_error_1.LogError(`ARN is not a valid Kinesis Firehose delivery stream: ${arn}`);
90
- }
91
- const parsed = this.parseARN(arn);
92
- return parsed.resourceName;
93
- }
94
- /**
95
- * Extracts AWS region from ARN
96
- *
97
- * @param {string} arn - The AWS ARN
98
- *
99
- * @returns {string} The AWS region
100
- */
101
- static getRegionFromARN(arn) {
102
- const parsed = this.parseARN(arn);
103
- return parsed.region;
104
- }
105
- }
106
- exports.ArnHelper = ArnHelper;
107
- //# sourceMappingURL=arn.helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arn.helper.js","sourceRoot":"","sources":["../../src/helpers/arn.helper.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mDAA+C;AAuB/C;;;;GAIG;AACH,MAAa,SAAS;IACpB;;;;;;;;;;;;;;;;;;;;OAoBG;IACK,MAAM,CAAC,QAAQ,CAAC,GAAW;QAEjC,IACE,CAAC,GAAG;eACD,OAAO,GAAG,KAAK,QAAQ,EAC1B,CAAC;YACD,MAAM,IAAI,oBAAQ,CAAC,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