apitally 0.15.3 → 0.16.1

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.
Files changed (65) hide show
  1. package/dist/adonisjs/middleware.cjs.map +1 -1
  2. package/dist/adonisjs/middleware.js.map +1 -1
  3. package/dist/adonisjs/provider.cjs +118 -46
  4. package/dist/adonisjs/provider.cjs.map +1 -1
  5. package/dist/adonisjs/provider.js +118 -46
  6. package/dist/adonisjs/provider.js.map +1 -1
  7. package/dist/common/client.cjs +118 -46
  8. package/dist/common/client.cjs.map +1 -1
  9. package/dist/common/client.js +118 -46
  10. package/dist/common/client.js.map +1 -1
  11. package/dist/common/requestLogger.cjs +118 -46
  12. package/dist/common/requestLogger.cjs.map +1 -1
  13. package/dist/common/requestLogger.d.cts +5 -0
  14. package/dist/common/requestLogger.d.ts +5 -0
  15. package/dist/common/requestLogger.js +118 -46
  16. package/dist/common/requestLogger.js.map +1 -1
  17. package/dist/express/index.cjs +126 -50
  18. package/dist/express/index.cjs.map +1 -1
  19. package/dist/express/index.js +126 -50
  20. package/dist/express/index.js.map +1 -1
  21. package/dist/express/middleware.cjs +126 -50
  22. package/dist/express/middleware.cjs.map +1 -1
  23. package/dist/express/middleware.js +126 -50
  24. package/dist/express/middleware.js.map +1 -1
  25. package/dist/express/utils.cjs +8 -4
  26. package/dist/express/utils.cjs.map +1 -1
  27. package/dist/express/utils.js +8 -4
  28. package/dist/express/utils.js.map +1 -1
  29. package/dist/fastify/index.cjs +118 -46
  30. package/dist/fastify/index.cjs.map +1 -1
  31. package/dist/fastify/index.js +118 -46
  32. package/dist/fastify/index.js.map +1 -1
  33. package/dist/fastify/plugin.cjs +118 -46
  34. package/dist/fastify/plugin.cjs.map +1 -1
  35. package/dist/fastify/plugin.js +118 -46
  36. package/dist/fastify/plugin.js.map +1 -1
  37. package/dist/h3/index.cjs +118 -46
  38. package/dist/h3/index.cjs.map +1 -1
  39. package/dist/h3/index.js +118 -46
  40. package/dist/h3/index.js.map +1 -1
  41. package/dist/h3/plugin.cjs +118 -46
  42. package/dist/h3/plugin.cjs.map +1 -1
  43. package/dist/h3/plugin.js +118 -46
  44. package/dist/h3/plugin.js.map +1 -1
  45. package/dist/hono/index.cjs +118 -46
  46. package/dist/hono/index.cjs.map +1 -1
  47. package/dist/hono/index.js +118 -46
  48. package/dist/hono/index.js.map +1 -1
  49. package/dist/hono/middleware.cjs +118 -46
  50. package/dist/hono/middleware.cjs.map +1 -1
  51. package/dist/hono/middleware.js +118 -46
  52. package/dist/hono/middleware.js.map +1 -1
  53. package/dist/koa/index.cjs +118 -46
  54. package/dist/koa/index.cjs.map +1 -1
  55. package/dist/koa/index.js +118 -46
  56. package/dist/koa/index.js.map +1 -1
  57. package/dist/koa/middleware.cjs +118 -46
  58. package/dist/koa/middleware.cjs.map +1 -1
  59. package/dist/koa/middleware.js +118 -46
  60. package/dist/koa/middleware.js.map +1 -1
  61. package/dist/nestjs/index.cjs +126 -50
  62. package/dist/nestjs/index.cjs.map +1 -1
  63. package/dist/nestjs/index.js +126 -50
  64. package/dist/nestjs/index.js.map +1 -1
  65. package/package.json +1 -1
@@ -413,6 +413,16 @@ var MASK_HEADER_PATTERNS = [
413
413
  /token/i,
414
414
  /cookie/i
415
415
  ];
416
+ var MASK_BODY_FIELD_PATTERNS = [
417
+ /password/i,
418
+ /pwd/i,
419
+ /token/i,
420
+ /secret/i,
421
+ /auth/i,
422
+ /card[-_ ]?number/i,
423
+ /ccv/i,
424
+ /ssn/i
425
+ ];
416
426
  var DEFAULT_CONFIG = {
417
427
  enabled: false,
418
428
  logQueryParams: true,
@@ -423,6 +433,7 @@ var DEFAULT_CONFIG = {
423
433
  logException: true,
424
434
  maskQueryParams: [],
425
435
  maskHeaders: [],
436
+ maskBodyFields: [],
426
437
  excludePaths: []
427
438
  };
428
439
  var _RequestLogger = class _RequestLogger {
@@ -473,11 +484,23 @@ var _RequestLogger = class _RequestLogger {
473
484
  ];
474
485
  return matchPatterns(name, patterns);
475
486
  }
487
+ shouldMaskBodyField(name) {
488
+ const patterns = [
489
+ ...this.config.maskBodyFields,
490
+ ...MASK_BODY_FIELD_PATTERNS
491
+ ];
492
+ return matchPatterns(name, patterns);
493
+ }
476
494
  hasSupportedContentType(headers) {
477
495
  var _a3;
478
496
  const contentType = (_a3 = headers.find(([k]) => k.toLowerCase() === "content-type")) == null ? void 0 : _a3[1];
479
497
  return this.isSupportedContentType(contentType);
480
498
  }
499
+ hasJsonContentType(headers) {
500
+ var _a3;
501
+ const contentType = (_a3 = headers.find(([k]) => k.toLowerCase() === "content-type")) == null ? void 0 : _a3[1];
502
+ return contentType ? /\bjson\b/i.test(contentType) : null;
503
+ }
481
504
  isSupportedContentType(contentType) {
482
505
  return typeof contentType === "string" && ALLOWED_CONTENT_TYPES.some((t) => contentType.startsWith(t));
483
506
  }
@@ -496,6 +519,72 @@ var _RequestLogger = class _RequestLogger {
496
519
  this.shouldMaskHeader(k) ? MASKED : v
497
520
  ]);
498
521
  }
522
+ maskBody(data) {
523
+ if (typeof data === "object" && data !== null && !Array.isArray(data)) {
524
+ const result = {};
525
+ for (const [key, value] of Object.entries(data)) {
526
+ if (typeof value === "string" && this.shouldMaskBodyField(key)) {
527
+ result[key] = MASKED;
528
+ } else {
529
+ result[key] = this.maskBody(value);
530
+ }
531
+ }
532
+ return result;
533
+ }
534
+ if (Array.isArray(data)) {
535
+ return data.map((item) => this.maskBody(item));
536
+ }
537
+ return data;
538
+ }
539
+ applyMasking(item) {
540
+ if (this.config.maskRequestBodyCallback && item.request.body && item.request.body !== BODY_TOO_LARGE) {
541
+ try {
542
+ const maskedBody = this.config.maskRequestBodyCallback(item.request);
543
+ item.request.body = maskedBody ?? BODY_MASKED;
544
+ } catch {
545
+ item.request.body = void 0;
546
+ }
547
+ }
548
+ if (this.config.maskResponseBodyCallback && item.response.body && item.response.body !== BODY_TOO_LARGE) {
549
+ try {
550
+ const maskedBody = this.config.maskResponseBodyCallback(item.request, item.response);
551
+ item.response.body = maskedBody ?? BODY_MASKED;
552
+ } catch {
553
+ item.response.body = void 0;
554
+ }
555
+ }
556
+ if (item.request.body && item.request.body.length > MAX_BODY_SIZE) {
557
+ item.request.body = BODY_TOO_LARGE;
558
+ }
559
+ if (item.response.body && item.response.body.length > MAX_BODY_SIZE) {
560
+ item.response.body = BODY_TOO_LARGE;
561
+ }
562
+ for (const key of [
563
+ "request",
564
+ "response"
565
+ ]) {
566
+ const bodyData = item[key].body;
567
+ if (!bodyData || bodyData === BODY_TOO_LARGE || bodyData === BODY_MASKED) {
568
+ continue;
569
+ }
570
+ const headers = item[key].headers;
571
+ const hasJsonContent = this.hasJsonContentType(headers);
572
+ if (hasJsonContent === null || hasJsonContent) {
573
+ try {
574
+ const parsedBody = JSON.parse(bodyData.toString());
575
+ const maskedBody = this.maskBody(parsedBody);
576
+ item[key].body = Buffer3.from(JSON.stringify(maskedBody));
577
+ } catch {
578
+ }
579
+ }
580
+ }
581
+ item.request.headers = this.config.logRequestHeaders ? this.maskHeaders(item.request.headers) : [];
582
+ item.response.headers = this.config.logResponseHeaders ? this.maskHeaders(item.response.headers) : [];
583
+ const url = new URL(item.request.url);
584
+ url.search = this.config.logQueryParams ? this.maskQueryParams(url.search) : "";
585
+ item.request.url = url.toString();
586
+ return item;
587
+ }
499
588
  logRequest(request, response, error) {
500
589
  var _a3, _b, _c;
501
590
  if (!this.enabled || this.suspendUntil !== null) return;
@@ -505,64 +594,30 @@ var _RequestLogger = class _RequestLogger {
505
594
  if (this.shouldExcludePath(path) || this.shouldExcludeUserAgent(userAgent) || (((_c = (_b = this.config).excludeCallback) == null ? void 0 : _c.call(_b, request, response)) ?? false)) {
506
595
  return;
507
596
  }
508
- url.search = this.config.logQueryParams ? this.maskQueryParams(url.search) : "";
509
- request.url = url.toString();
510
597
  if (!this.config.logRequestBody || !this.hasSupportedContentType(request.headers)) {
511
598
  request.body = void 0;
512
- } else if (request.body) {
513
- if (request.body.length > MAX_BODY_SIZE) {
514
- request.body = BODY_TOO_LARGE;
515
- } else if (this.config.maskRequestBodyCallback) {
516
- try {
517
- request.body = this.config.maskRequestBodyCallback(request) ?? BODY_MASKED;
518
- if (request.body.length > MAX_BODY_SIZE) {
519
- request.body = BODY_TOO_LARGE;
520
- }
521
- } catch {
522
- request.body = void 0;
523
- }
524
- }
525
599
  }
526
600
  if (!this.config.logResponseBody || !this.hasSupportedContentType(response.headers)) {
527
601
  response.body = void 0;
528
- } else if (response.body) {
529
- if (response.body.length > MAX_BODY_SIZE) {
530
- response.body = BODY_TOO_LARGE;
531
- } else if (this.config.maskResponseBodyCallback) {
532
- try {
533
- response.body = this.config.maskResponseBodyCallback(request, response) ?? BODY_MASKED;
534
- if (response.body.length > MAX_BODY_SIZE) {
535
- response.body = BODY_TOO_LARGE;
536
- }
537
- } catch {
538
- response.body = void 0;
539
- }
540
- }
541
602
  }
542
- request.headers = this.config.logRequestHeaders ? this.maskHeaders(request.headers) : [];
543
- response.headers = this.config.logResponseHeaders ? this.maskHeaders(response.headers) : [];
603
+ if (request.size !== void 0 && request.size < 0) {
604
+ request.size = void 0;
605
+ }
606
+ if (response.size !== void 0 && response.size < 0) {
607
+ response.size = void 0;
608
+ }
544
609
  const item = {
545
610
  uuid: randomUUID2(),
546
- request: skipEmptyValues(request),
547
- response: skipEmptyValues(response),
611
+ request,
612
+ response,
548
613
  exception: error && this.config.logException ? {
549
614
  type: error.name,
550
615
  message: truncateExceptionMessage(error.message),
551
616
  stacktrace: truncateExceptionStackTrace(error.stack || ""),
552
617
  sentryEventId: getSentryEventId()
553
- } : null
618
+ } : void 0
554
619
  };
555
- [
556
- item.request.body,
557
- item.response.body
558
- ].forEach((body) => {
559
- if (body) {
560
- body.toJSON = function() {
561
- return this.toString("base64");
562
- };
563
- }
564
- });
565
- this.pendingWrites.push(JSON.stringify(item));
620
+ this.pendingWrites.push(item);
566
621
  if (this.pendingWrites.length > MAX_PENDING_WRITES) {
567
622
  this.pendingWrites.shift();
568
623
  }
@@ -576,9 +631,26 @@ var _RequestLogger = class _RequestLogger {
576
631
  this.currentFile = new TempGzipFile();
577
632
  }
578
633
  while (this.pendingWrites.length > 0) {
579
- const item = this.pendingWrites.shift();
634
+ let item = this.pendingWrites.shift();
580
635
  if (item) {
581
- await this.currentFile.writeLine(Buffer3.from(item));
636
+ item = this.applyMasking(item);
637
+ const finalItem = {
638
+ uuid: item.uuid,
639
+ request: skipEmptyValues(item.request),
640
+ response: skipEmptyValues(item.response),
641
+ exception: item.exception
642
+ };
643
+ [
644
+ finalItem.request.body,
645
+ finalItem.response.body
646
+ ].forEach((body) => {
647
+ if (body) {
648
+ body.toJSON = function() {
649
+ return this.toString("base64");
650
+ };
651
+ }
652
+ });
653
+ await this.currentFile.writeLine(Buffer3.from(JSON.stringify(finalItem)));
582
654
  }
583
655
  }
584
656
  });
@@ -1227,10 +1299,14 @@ var parseStack = /* @__PURE__ */ __name(function(stack, basePath, endpoints, ver
1227
1299
  }, "parseStack");
1228
1300
  var getEndpoints = /* @__PURE__ */ __name(function(app, basePath) {
1229
1301
  const endpoints = parseEndpoints(app);
1230
- return endpoints.flatMap((route) => route.methods.filter((method) => ![
1231
- "HEAD",
1232
- "OPTIONS"
1233
- ].includes(method.toUpperCase())).map((method) => ({
1302
+ const standardHttpMethods = [
1303
+ "GET",
1304
+ "POST",
1305
+ "PUT",
1306
+ "DELETE",
1307
+ "PATCH"
1308
+ ];
1309
+ return endpoints.flatMap((route) => route.methods.filter((method) => standardHttpMethods.includes(method.toUpperCase())).map((method) => ({
1234
1310
  method,
1235
1311
  path: (basePath + route.path).replace(/\/\//g, "/")
1236
1312
  })));