@moreapp/common-nodejs 0.7.13 → 0.7.14

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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
7
  const content_disposition_parser_1 = __importDefault(require("content-disposition-parser"));
8
8
  class MoreAppClient {
9
+ client;
9
10
  constructor(options) {
10
11
  this.client = axios_1.default.create({
11
12
  ...options.axios,
package/dist/logger.d.ts CHANGED
@@ -1 +1,5 @@
1
1
  export declare const logger: import("winston").Logger;
2
+ export declare const formatters: {
3
+ errorFormat: import("logform").FormatWrap;
4
+ stackdriverTracingFormat: import("logform").FormatWrap;
5
+ };
package/dist/logger.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = void 0;
3
+ exports.formatters = exports.logger = void 0;
4
4
  const winston_1 = require("winston");
5
5
  const entry_1 = require("@google-cloud/logging/build/src/entry");
6
6
  const stackdriverTracingFormat = (0, winston_1.format)((info) => {
@@ -11,8 +11,31 @@ const stackdriverTracingFormat = (0, winston_1.format)((info) => {
11
11
  }
12
12
  return info;
13
13
  });
14
+ const errorFormat = (0, winston_1.format)((info) => {
15
+ for (const prop in info) {
16
+ if (info[prop] instanceof Error) {
17
+ info[prop] = transformError(info[prop]);
18
+ }
19
+ }
20
+ return info;
21
+ });
22
+ const transformError = (error) => {
23
+ const transformed = {
24
+ name: error.name,
25
+ message: error.message,
26
+ };
27
+ if (error["cause"] !== undefined) {
28
+ transformed["cause"] =
29
+ error["cause"] instanceof Error ? transformError(error["cause"]) : error["cause"];
30
+ }
31
+ return transformed;
32
+ };
14
33
  exports.logger = (0, winston_1.createLogger)({
15
34
  level: "info",
16
35
  transports: [new winston_1.transports.Console()],
17
- format: winston_1.format.combine(stackdriverTracingFormat(), winston_1.format.json()),
36
+ format: winston_1.format.combine(stackdriverTracingFormat(), errorFormat(), winston_1.format.json()),
18
37
  });
38
+ exports.formatters = {
39
+ errorFormat,
40
+ stackdriverTracingFormat,
41
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const logger_1 = require("./logger");
4
+ describe("errorFormat", () => {
5
+ test("should format standard errors", async () => {
6
+ const error = new Error("Failed to persist");
7
+ const formatted = logger_1.formatters
8
+ .errorFormat()
9
+ .transform({ level: "error", message: "Something went wrong", exception: error });
10
+ expect(formatted).toStrictEqual({
11
+ level: "error",
12
+ message: "Something went wrong",
13
+ exception: {
14
+ name: "Error",
15
+ message: "Failed to persist",
16
+ },
17
+ });
18
+ });
19
+ test("should format error with (deeply nested) cause", async () => {
20
+ const error = new Error("Failed to persist", {
21
+ cause: new Error("Caused by me!", { cause: "Well actually..." }),
22
+ });
23
+ const formatted = logger_1.formatters.errorFormat().transform({
24
+ level: "error",
25
+ message: "Something went wrong",
26
+ exception: error,
27
+ });
28
+ expect(formatted).toStrictEqual({
29
+ level: "error",
30
+ message: "Something went wrong",
31
+ exception: {
32
+ name: "Error",
33
+ message: "Failed to persist",
34
+ cause: {
35
+ name: "Error",
36
+ message: "Caused by me!",
37
+ cause: "Well actually...",
38
+ },
39
+ },
40
+ });
41
+ });
42
+ });
43
+ describe("tracingFormat", () => {
44
+ test("should transform tracing data to Stackdriver format", async () => {
45
+ const formatted = logger_1.formatters.stackdriverTracingFormat().transform({
46
+ level: "error",
47
+ message: "Something went wrong",
48
+ trace_id: "TRACE_ID",
49
+ span_id: "SPAN_ID",
50
+ });
51
+ expect(formatted).toStrictEqual({
52
+ level: "error",
53
+ message: "Something went wrong",
54
+ trace_id: "TRACE_ID",
55
+ span_id: "SPAN_ID",
56
+ "logging.googleapis.com/trace": "TRACE_ID",
57
+ "logging.googleapis.com/spanId": "SPAN_ID",
58
+ "logging.googleapis.com/trace_sampled": true,
59
+ });
60
+ });
61
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moreapp/common-nodejs",
3
- "version": "0.7.13",
3
+ "version": "0.7.14",
4
4
  "license": "UNLICENSED",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",