@devrev/ts-adaas 1.1.3 → 1.1.4

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
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Release Notes
4
4
 
5
+ ### v1.1.4
6
+
7
+ - Provide log line and stack trace on runtime worker errors.
8
+
5
9
  ### v1.1.3
6
10
 
7
11
  - Exported `axios` and `axiosClient` with exponential backoff retry mechanism for HTTP requests and omitting Authorization headers from Axios errors.
@@ -23,7 +23,7 @@ const emit = async ({ event, eventType, data, }) => {
23
23
  }
24
24
  catch (error) {
25
25
  if (axios_client_1.axios.isAxiosError(error)) {
26
- console.error(`Failed to emit event with event type ${eventType}.`, (0, logger_1.formatAxiosError)(error));
26
+ console.error(`Failed to emit event with event type ${eventType}.`, (0, logger_1.serializeAxiosError)(error));
27
27
  }
28
28
  else {
29
29
  // TODO: Stop it through UI or think about retrying this request. Implement exponential retry mechanism.
@@ -42,7 +42,7 @@ async function installInitialDomainMapping(event, initialDomainMappingJson) {
42
42
  }
43
43
  catch (error) {
44
44
  if (axios_client_1.axios.isAxiosError(error)) {
45
- console.error('Error while creating recipe blueprint', (0, logger_1.formatAxiosError)(error));
45
+ console.error('Error while creating recipe blueprint', (0, logger_1.serializeAxiosError)(error));
46
46
  }
47
47
  else {
48
48
  console.error('Error while creating recipe blueprint', error);
@@ -64,7 +64,7 @@ async function installInitialDomainMapping(event, initialDomainMappingJson) {
64
64
  }
65
65
  catch (error) {
66
66
  if (axios_client_1.axios.isAxiosError(error)) {
67
- console.error('Error while installing initial domain mapping', (0, logger_1.formatAxiosError)(error));
67
+ console.error('Error while installing initial domain mapping', (0, logger_1.serializeAxiosError)(error));
68
68
  }
69
69
  else {
70
70
  console.error('Error while installing initial domain mapping', error);
@@ -74,7 +74,7 @@ async function installInitialDomainMapping(event, initialDomainMappingJson) {
74
74
  }
75
75
  catch (error) {
76
76
  if (axios_client_1.axios.isAxiosError(error)) {
77
- console.error('Error while fetching snap in', (0, logger_1.formatAxiosError)(error));
77
+ console.error('Error while fetching snap in', (0, logger_1.serializeAxiosError)(error));
78
78
  }
79
79
  else {
80
80
  console.error('Error while fetching snap in', error);
package/dist/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export { processTask } from './workers/process-task';
9
9
  export { spawn } from './workers/spawn';
10
10
  export * from './types/workers';
11
11
  export { formatAxiosError } from './logger/logger';
12
+ export { serializeAxiosError } from './logger/logger';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.formatAxiosError = exports.spawn = exports.processTask = exports.WorkerAdapter = void 0;
17
+ exports.serializeAxiosError = exports.formatAxiosError = exports.spawn = exports.processTask = exports.WorkerAdapter = void 0;
18
18
  __exportStar(require("./deprecated/adapter"), exports);
19
19
  __exportStar(require("./deprecated/demo-extractor"), exports);
20
20
  __exportStar(require("./deprecated/uploader"), exports);
@@ -30,3 +30,5 @@ Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { r
30
30
  __exportStar(require("./types/workers"), exports);
31
31
  var logger_1 = require("./logger/logger");
32
32
  Object.defineProperty(exports, "formatAxiosError", { enumerable: true, get: function () { return logger_1.formatAxiosError; } });
33
+ var logger_2 = require("./logger/logger");
34
+ Object.defineProperty(exports, "serializeAxiosError", { enumerable: true, get: function () { return logger_2.serializeAxiosError; } });
@@ -1,6 +1,6 @@
1
1
  import { Console } from 'node:console';
2
2
  import { LoggerFactoryInterface, LogLevel, PrintableState } from './logger.interfaces';
3
- import { AxiosError } from 'axios';
3
+ import { AxiosError, RawAxiosResponseHeaders } from 'axios';
4
4
  export declare class Logger extends Console {
5
5
  private options?;
6
6
  constructor({ event, options }: LoggerFactoryInterface);
@@ -11,4 +11,23 @@ export declare class Logger extends Console {
11
11
  error(...args: unknown[]): void;
12
12
  }
13
13
  export declare function getPrintableState(state: Record<string, any>): PrintableState;
14
+ /**
15
+ * @deprecated
16
+ */
14
17
  export declare function formatAxiosError(error: AxiosError): object;
18
+ export declare const serializeError: (error: unknown) => Error;
19
+ export declare function serializeAxiosError(error: AxiosError): {
20
+ config: {
21
+ method: string | undefined;
22
+ params: any;
23
+ url: string | undefined;
24
+ };
25
+ isAxiosError: boolean;
26
+ isCorsOrNoNetworkError: boolean;
27
+ response: {
28
+ data: unknown;
29
+ headers: RawAxiosResponseHeaders;
30
+ status: number;
31
+ statusText: string;
32
+ } | null;
33
+ };
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Logger = void 0;
6
+ exports.serializeError = exports.Logger = void 0;
7
7
  exports.getPrintableState = getPrintableState;
8
8
  exports.formatAxiosError = formatAxiosError;
9
+ exports.serializeAxiosError = serializeAxiosError;
9
10
  const lambda_log_1 = __importDefault(require("lambda-log"));
10
11
  const node_console_1 = require("node:console");
11
12
  const logger_interfaces_1 = require("./logger.interfaces");
@@ -85,17 +86,42 @@ function getPrintableState(state) {
85
86
  // Process the state object directly since it's guaranteed to be an object
86
87
  return processValue(state);
87
88
  }
89
+ /**
90
+ * @deprecated
91
+ */
88
92
  function formatAxiosError(error) {
89
- var _a, _b, _c, _d;
90
- if (error.response) {
91
- return {
92
- status: error.response.status,
93
- data: error.response.data,
94
- method: (_a = error.config) === null || _a === void 0 ? void 0 : _a.method,
95
- baseURL: (_b = error.config) === null || _b === void 0 ? void 0 : _b.baseURL,
96
- url: (_c = error.config) === null || _c === void 0 ? void 0 : _c.url,
97
- payload: (_d = error.config) === null || _d === void 0 ? void 0 : _d.data,
98
- };
93
+ return serializeAxiosError(error);
94
+ }
95
+ const serializeError = (error) => {
96
+ let serializedError = error;
97
+ try {
98
+ serializedError = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)));
99
+ }
100
+ catch (err) {
101
+ console.error('Failed to serialize error object for logger', err);
99
102
  }
100
- return error;
103
+ return serializedError;
104
+ };
105
+ exports.serializeError = serializeError;
106
+ function serializeAxiosError(error) {
107
+ var _a, _b, _c;
108
+ const response = error.response
109
+ ? {
110
+ data: error.response.data,
111
+ headers: error.response.headers,
112
+ status: error.response.status,
113
+ statusText: error.response.statusText,
114
+ }
115
+ : null;
116
+ const config = {
117
+ method: (_a = error.config) === null || _a === void 0 ? void 0 : _a.method,
118
+ params: (_b = error.config) === null || _b === void 0 ? void 0 : _b.params,
119
+ url: (_c = error.config) === null || _c === void 0 ? void 0 : _c.url,
120
+ };
121
+ return {
122
+ config,
123
+ isAxiosError: true,
124
+ isCorsOrNoNetworkError: !error.response,
125
+ response,
126
+ };
101
127
  }
@@ -30,7 +30,7 @@ it('getPrintableState should return printable state', () => {
30
30
  },
31
31
  });
32
32
  });
33
- it('formatAxiosError should return formatted error', () => {
33
+ it('serializeAxiosError should return formatted error', () => {
34
34
  const error = {
35
35
  response: {
36
36
  status: 500,
@@ -40,13 +40,20 @@ it('formatAxiosError should return formatted error', () => {
40
40
  method: 'GET',
41
41
  },
42
42
  };
43
- const formattedError = (0, logger_1.formatAxiosError)(error);
43
+ const formattedError = (0, logger_1.serializeAxiosError)(error);
44
44
  expect(formattedError).toEqual({
45
- status: 500,
46
- data: 'Internal server error',
47
- method: 'GET',
48
- baseURL: undefined,
49
- url: undefined,
50
- payload: undefined,
45
+ config: {
46
+ method: 'GET',
47
+ params: undefined,
48
+ url: undefined,
49
+ },
50
+ isAxiosError: true,
51
+ isCorsOrNoNetworkError: false,
52
+ response: {
53
+ data: 'Internal server error',
54
+ headers: undefined,
55
+ status: 500,
56
+ statusText: undefined,
57
+ },
51
58
  });
52
59
  });
@@ -72,7 +72,7 @@ class State {
72
72
  }
73
73
  catch (error) {
74
74
  if (axios_client_1.axios.isAxiosError(error)) {
75
- console.error('Failed to update state.', (0, logger_1.formatAxiosError)(error));
75
+ console.error('Failed to update state.', (0, logger_1.serializeAxiosError)(error));
76
76
  }
77
77
  else {
78
78
  console.error('Failed to update state.', error);
@@ -99,7 +99,7 @@ class Uploader {
99
99
  }
100
100
  catch (error) {
101
101
  if (axios_client_1.axios.isAxiosError(error)) {
102
- console.error('Error while preparing artifact.', (0, logger_1.formatAxiosError)(error));
102
+ console.error('Error while preparing artifact.', (0, logger_1.serializeAxiosError)(error));
103
103
  }
104
104
  else {
105
105
  console.error('Error while preparing artifact.', error);
@@ -122,7 +122,7 @@ class Uploader {
122
122
  }
123
123
  catch (error) {
124
124
  if (axios_client_1.axios.isAxiosError(error)) {
125
- console.error('Error while uploading artifact.', (0, logger_1.formatAxiosError)(error));
125
+ console.error('Error while uploading artifact.', (0, logger_1.serializeAxiosError)(error));
126
126
  }
127
127
  else {
128
128
  console.error('Error while uploading artifact.', error);
@@ -147,7 +147,7 @@ class Uploader {
147
147
  }
148
148
  catch (error) {
149
149
  if (axios_client_1.axios.isAxiosError(error)) {
150
- console.error('Error while streaming artifact.', (0, logger_1.formatAxiosError)(error));
150
+ console.error('Error while streaming artifact.', (0, logger_1.serializeAxiosError)(error));
151
151
  }
152
152
  else {
153
153
  console.error('Error while streaming artifact.', error);
@@ -230,7 +230,7 @@ class Uploader {
230
230
  }
231
231
  catch (error) {
232
232
  if (axios_client_1.axios.isAxiosError(error)) {
233
- console.error('Error while downloading artifact from URL.', (0, logger_1.formatAxiosError)(error));
233
+ console.error('Error while downloading artifact from URL.', (0, logger_1.serializeAxiosError)(error));
234
234
  }
235
235
  else {
236
236
  console.error('Error while downloading artifact from URL.', error);
@@ -312,7 +312,7 @@ class Uploader {
312
312
  }
313
313
  catch (error) {
314
314
  if (axios_client_1.axios.isAxiosError(error)) {
315
- console.error('Error while fetching attachment from URL.', (0, logger_1.formatAxiosError)(error));
315
+ console.error('Error while fetching attachment from URL.', (0, logger_1.serializeAxiosError)(error));
316
316
  }
317
317
  else {
318
318
  console.error('Error while fetching attachment from URL.', error);
@@ -16,7 +16,7 @@ async function createWorker(workerData) {
16
16
  workerData,
17
17
  });
18
18
  worker.on(workers_1.WorkerEvent.WorkerError, (error) => {
19
- logger.error('Worker error', error);
19
+ logger.error('Worker error', (0, logger_1.serializeError)(error));
20
20
  reject();
21
21
  });
22
22
  worker.on(workers_1.WorkerEvent.WorkerOnline, () => {
@@ -341,7 +341,7 @@ class WorkerAdapter {
341
341
  }
342
342
  catch (error) {
343
343
  if (axios_client_1.axios.isAxiosError(error)) {
344
- console.error('Failed to update sync mapper record', (0, logger_1.formatAxiosError)(error));
344
+ console.error('Failed to update sync mapper record', (0, logger_1.serializeAxiosError)(error));
345
345
  return {
346
346
  error: {
347
347
  message: error.message,
@@ -412,7 +412,7 @@ class WorkerAdapter {
412
412
  }
413
413
  catch (error) {
414
414
  if (axios_client_1.axios.isAxiosError(error)) {
415
- console.error('Failed to create sync mapper record', (0, logger_1.formatAxiosError)(error));
415
+ console.error('Failed to create sync mapper record', (0, logger_1.serializeAxiosError)(error));
416
416
  return {
417
417
  error: {
418
418
  message: error.message,
@@ -445,7 +445,7 @@ class WorkerAdapter {
445
445
  }
446
446
  }
447
447
  else {
448
- console.error('Failed to get sync mapper record', (0, logger_1.formatAxiosError)(error));
448
+ console.error('Failed to get sync mapper record', (0, logger_1.serializeAxiosError)(error));
449
449
  return {
450
450
  error: {
451
451
  message: error.message,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/ts-adaas",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",