@devrev/ts-adaas 1.6.0 → 1.7.0-beta.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.
@@ -42,13 +42,7 @@ async function installInitialDomainMapping(event, initialDomainMappingJson) {
42
42
  console.log('Successfully created recipe blueprint with id: ' + recipeBlueprintId);
43
43
  }
44
44
  catch (error) {
45
- const errorMessage = `Error while creating recipe blueprint. Continuing without it.`;
46
- if (axios_client_1.axios.isAxiosError(error)) {
47
- console.error(errorMessage, (0, logger_1.serializeAxiosError)(error));
48
- }
49
- else {
50
- console.error(errorMessage, error);
51
- }
45
+ console.warn('Error while creating recipe blueprint. Continuing without it.', (0, logger_1.serializeError)(error));
52
46
  }
53
47
  }
54
48
  // Install the initial domain mappings
@@ -60,6 +54,5 @@ async function installInitialDomainMapping(event, initialDomainMappingJson) {
60
54
  Authorization: devrevToken,
61
55
  },
62
56
  });
63
- console.log('Successfully installed initial domain mapping: ' +
64
- JSON.stringify(initialDomainMappingInstallResponse.data));
57
+ console.log(`Successfully installed initial domain mapping ${JSON.stringify(initialDomainMappingInstallResponse.data)}`);
65
58
  }
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
7
  const install_initial_domain_mapping_1 = require("./install-initial-domain-mapping");
8
8
  const axios_client_1 = require("../http/axios-client");
9
- const logger_1 = require("../logger/logger");
10
9
  const test_helpers_1 = require("../tests/test-helpers");
11
10
  const extraction_1 = require("../types/extraction");
12
11
  // Mock dependencies
@@ -15,7 +14,6 @@ jest.mock('../http/axios-client');
15
14
  jest.mock('../logger/logger');
16
15
  const mockAxiosClient = axios_client_1.axiosClient;
17
16
  const mockIsAxiosError = axios_1.default.isAxiosError;
18
- const mockSerializeAxiosError = logger_1.serializeAxiosError;
19
17
  describe('installInitialDomainMapping', () => {
20
18
  // Create mock objects
21
19
  const mockEvent = (0, test_helpers_1.createEvent)({ eventType: extraction_1.EventType.ExtractionDataStart });
@@ -46,7 +44,9 @@ describe('installInitialDomainMapping', () => {
46
44
  // Re-initialize the spy and its mock implementation
47
45
  mockConsoleLog = jest.spyOn(console, 'log').mockImplementation(() => { });
48
46
  mockConsoleWarn = jest.spyOn(console, 'warn').mockImplementation(() => { });
49
- mockConsoleError = jest.spyOn(console, 'error').mockImplementation(() => { });
47
+ mockConsoleError = jest
48
+ .spyOn(console, 'error')
49
+ .mockImplementation(() => { });
50
50
  });
51
51
  // After each test, clear all mocks to prevent state from leaking.
52
52
  afterEach(() => {
@@ -104,7 +104,7 @@ describe('installInitialDomainMapping', () => {
104
104
  },
105
105
  });
106
106
  expect(mockConsoleLog).toHaveBeenCalledWith('Successfully created recipe blueprint with id: recipe-blueprint-123');
107
- expect(mockConsoleLog).toHaveBeenCalledWith('Successfully installed initial domain mapping: {"success":true,"mapping_id":"mapping-123"}');
107
+ expect(mockConsoleLog).toHaveBeenCalledWith(`Successfully installed initial domain mapping ${JSON.stringify(mockDomainMappingResponse.data)}`);
108
108
  });
109
109
  it('should successfully install without recipe blueprint when not provided', async () => {
110
110
  const mappingWithoutBlueprint = {
@@ -3,7 +3,9 @@ import { LoggerFactoryInterface, LogLevel, PrintableState } from './logger.inter
3
3
  import { AxiosError, RawAxiosResponseHeaders } from 'axios';
4
4
  export declare class Logger extends Console {
5
5
  private options?;
6
+ private tags;
6
7
  constructor({ event, options }: LoggerFactoryInterface);
8
+ private valueToString;
7
9
  logFn(args: unknown[], level: LogLevel): void;
8
10
  log(...args: unknown[]): void;
9
11
  info(...args: unknown[]): void;
@@ -15,7 +17,7 @@ export declare function getPrintableState(state: Record<string, any>): Printable
15
17
  * @deprecated
16
18
  */
17
19
  export declare function formatAxiosError(error: AxiosError): object;
18
- export declare const serializeError: (error: unknown) => Error;
20
+ export declare const serializeError: (error: unknown) => unknown;
19
21
  export declare function serializeAxiosError(error: AxiosError): {
20
22
  config: {
21
23
  method: string | undefined;
@@ -1,26 +1,30 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.serializeError = exports.Logger = void 0;
7
4
  exports.getPrintableState = getPrintableState;
8
5
  exports.formatAxiosError = formatAxiosError;
9
6
  exports.serializeAxiosError = serializeAxiosError;
10
- const lambda_log_1 = __importDefault(require("lambda-log"));
11
7
  const node_console_1 = require("node:console");
8
+ const node_util_1 = require("node:util");
12
9
  const logger_interfaces_1 = require("./logger.interfaces");
13
10
  const node_worker_threads_1 = require("node:worker_threads");
14
11
  const workers_1 = require("../types/workers");
15
- const helpers_1 = require("../common/helpers");
12
+ const axios_1 = require("axios");
16
13
  class Logger extends node_console_1.Console {
17
14
  constructor({ event, options }) {
18
15
  super(process.stdout, process.stderr);
19
16
  this.options = options;
20
- lambda_log_1.default.options.levelKey = null;
21
- lambda_log_1.default.options.tagsKey = null;
22
- lambda_log_1.default.options.messageKey = 'message';
23
- lambda_log_1.default.options.meta = Object.assign(Object.assign({}, event.payload.event_context), { dev_oid: event.payload.event_context.dev_org });
17
+ this.tags = Object.assign(Object.assign({}, event.payload.event_context), { dev_oid: event.payload.event_context.dev_org });
18
+ }
19
+ valueToString(value) {
20
+ if (typeof value === 'string') {
21
+ return value;
22
+ }
23
+ // Use Node.js built-in inspect for everything including errors
24
+ return (0, node_util_1.inspect)(value, {
25
+ compact: false,
26
+ depth: Infinity,
27
+ });
24
28
  }
25
29
  logFn(args, level) {
26
30
  var _a;
@@ -29,14 +33,28 @@ class Logger extends node_console_1.Console {
29
33
  console[level](...args);
30
34
  }
31
35
  else {
32
- lambda_log_1.default.log(level, JSON.stringify(args));
36
+ let message;
37
+ if (args.length === 1 && typeof args[0] === 'string') {
38
+ // Single string argument - use directly
39
+ message = args[0];
40
+ }
41
+ else if (args.length === 1) {
42
+ // Single non-string argument - convert to string properly
43
+ message = this.valueToString(args[0]);
44
+ }
45
+ else {
46
+ // Multiple arguments - create a readable format
47
+ message = args.map((arg) => this.valueToString(arg)).join(' ');
48
+ }
49
+ const logObject = Object.assign({ message }, this.tags);
50
+ console[level](JSON.stringify(logObject));
33
51
  }
34
52
  }
35
53
  else {
36
54
  node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
37
55
  subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
38
56
  payload: {
39
- args: JSON.parse(JSON.stringify(args, (0, helpers_1.getCircularReplacer)())),
57
+ args: args.map((arg) => this.valueToString(arg)),
40
58
  level,
41
59
  },
42
60
  });
@@ -93,14 +111,10 @@ function formatAxiosError(error) {
93
111
  return serializeAxiosError(error);
94
112
  }
95
113
  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);
114
+ if ((0, axios_1.isAxiosError)(error)) {
115
+ return serializeAxiosError(error);
102
116
  }
103
- return serializedError;
117
+ return error;
104
118
  };
105
119
  exports.serializeError = serializeError;
106
120
  function serializeAxiosError(error) {
@@ -1,6 +1,184 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_util_1 = require("node:util");
3
4
  const logger_1 = require("./logger");
5
+ const extraction_1 = require("../types/extraction");
6
+ const test_helpers_1 = require("../tests/test-helpers");
7
+ // Mock console methods
8
+ const mockConsoleInfo = jest.spyOn(console, 'info').mockImplementation();
9
+ const mockConsoleWarn = jest.spyOn(console, 'warn').mockImplementation();
10
+ const mockConsoleError = jest.spyOn(console, 'error').mockImplementation();
11
+ const mockConsoleLog = jest.spyOn(console, 'log').mockImplementation();
12
+ // Mock worker_threads
13
+ jest.mock('node:worker_threads', () => ({
14
+ isMainThread: true,
15
+ parentPort: null,
16
+ }));
17
+ describe('Logger', () => {
18
+ let mockEvent;
19
+ let mockOptions;
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ mockEvent = (0, test_helpers_1.createEvent)({
23
+ eventType: extraction_1.EventType.ExtractionDataStart,
24
+ eventContextOverrides: {
25
+ dev_org: 'DEV-test',
26
+ dev_org_id: 'DEV-test-id',
27
+ dev_user: 'DEVU-test',
28
+ dev_user_id: 'DEVU-test-id',
29
+ external_sync_unit: 'test-unit',
30
+ external_sync_unit_id: 'test-unit-id',
31
+ external_sync_unit_name: 'test-unit-name',
32
+ external_system: 'test-system',
33
+ external_system_type: 'test-type',
34
+ import_slug: 'test-import',
35
+ request_id: 'test-request-id',
36
+ snap_in_slug: 'test-snap-slug',
37
+ sync_run: 'test-sync-run',
38
+ sync_run_id: 'test-sync-run-id',
39
+ },
40
+ });
41
+ mockOptions = {
42
+ isLocalDevelopment: false,
43
+ };
44
+ });
45
+ afterAll(() => {
46
+ jest.restoreAllMocks();
47
+ });
48
+ describe('constructor', () => {
49
+ it('should initialize logger with event context and dev_oid', () => {
50
+ const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
51
+ // Access private property for testing
52
+ const tags = logger.tags;
53
+ expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_org }));
54
+ });
55
+ });
56
+ describe('production logging', () => {
57
+ let logger;
58
+ beforeEach(() => {
59
+ mockOptions.isLocalDevelopment = false;
60
+ logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
61
+ });
62
+ it('should log single string message without backslashes', () => {
63
+ const message = 'Worker is online. Started processing the task.';
64
+ logger.info(message);
65
+ expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_org })));
66
+ });
67
+ it('should log single object message with JSON stringify', () => {
68
+ const data = { id: 123, name: 'test' };
69
+ logger.info(data);
70
+ const expectedMessage = (0, node_util_1.inspect)(data, {
71
+ compact: false,
72
+ depth: Infinity,
73
+ });
74
+ expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_org })));
75
+ });
76
+ it('should log multiple arguments joined with space', () => {
77
+ const text = 'Successfully fetched';
78
+ const data = { count: 42 };
79
+ logger.info(text, data);
80
+ const expectedDataMessage = (0, node_util_1.inspect)(data, {
81
+ compact: false,
82
+ depth: Infinity,
83
+ });
84
+ expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_org })));
85
+ });
86
+ it('should handle mixed string and object arguments', () => {
87
+ const text1 = 'Processing';
88
+ const data = { id: 123 };
89
+ const text2 = 'completed';
90
+ logger.info(text1, data, text2);
91
+ const expectedDataMessage = (0, node_util_1.inspect)(data, {
92
+ compact: false,
93
+ depth: Infinity,
94
+ });
95
+ expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_org })));
96
+ });
97
+ });
98
+ describe('local development logging', () => {
99
+ let logger;
100
+ beforeEach(() => {
101
+ mockOptions.isLocalDevelopment = true;
102
+ logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
103
+ });
104
+ it('should use regular console methods in local development', () => {
105
+ const message = 'Test message';
106
+ const data = { test: true };
107
+ logger.info(message, data);
108
+ expect(mockConsoleInfo).toHaveBeenCalledWith(message, data);
109
+ });
110
+ });
111
+ describe('log levels', () => {
112
+ let logger;
113
+ beforeEach(() => {
114
+ mockOptions.isLocalDevelopment = false;
115
+ logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
116
+ });
117
+ it('should call console.info for info level', () => {
118
+ logger.info('test message');
119
+ expect(mockConsoleInfo).toHaveBeenCalled();
120
+ });
121
+ it('should call console.warn for warn level', () => {
122
+ logger.warn('test warning');
123
+ expect(mockConsoleWarn).toHaveBeenCalled();
124
+ });
125
+ it('should call console.error for error level', () => {
126
+ logger.error('test error');
127
+ expect(mockConsoleError).toHaveBeenCalled();
128
+ });
129
+ it('should call console.info for log level', () => {
130
+ logger.log('test log');
131
+ expect(mockConsoleInfo).toHaveBeenCalled();
132
+ });
133
+ });
134
+ describe('edge cases', () => {
135
+ let logger;
136
+ beforeEach(() => {
137
+ mockOptions.isLocalDevelopment = false;
138
+ logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
139
+ });
140
+ it('should handle empty string message', () => {
141
+ logger.info('');
142
+ expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
143
+ const callArgs = mockConsoleInfo.mock.calls[0][0];
144
+ const logObject = JSON.parse(callArgs);
145
+ expect(logObject.message).toBe('');
146
+ expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_org);
147
+ expect(logObject.request_id).toBe(mockEvent.payload.event_context.request_id);
148
+ });
149
+ it('should handle null and undefined values', () => {
150
+ logger.info('test', null, undefined);
151
+ expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
152
+ const callArgs = mockConsoleInfo.mock.calls[0][0];
153
+ const logObject = JSON.parse(callArgs);
154
+ // inspect shows 'null' and 'undefined' as strings
155
+ expect(logObject.message).toBe('test null undefined');
156
+ expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_org);
157
+ });
158
+ it('should handle complex nested objects', () => {
159
+ const complexObject = {
160
+ level1: {
161
+ level2: {
162
+ array: [1, 2, 3],
163
+ string: 'nested',
164
+ },
165
+ },
166
+ };
167
+ logger.info(complexObject);
168
+ expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
169
+ const callArgs = mockConsoleInfo.mock.calls[0][0];
170
+ const logObject = JSON.parse(callArgs);
171
+ // The logger uses inspect() with formatting, not JSON.stringify()
172
+ const expectedMessage = require('util').inspect(complexObject, {
173
+ compact: false,
174
+ depth: Infinity,
175
+ });
176
+ expect(logObject.message).toBe(expectedMessage);
177
+ expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_org);
178
+ expect(typeof logObject.callback_url).toBe('string');
179
+ });
180
+ });
181
+ });
4
182
  it('getPrintableState should return printable state', () => {
5
183
  const state = {
6
184
  test_key: 'test_value',
@@ -36,12 +36,7 @@ async function createAdapterState({ event, initialState, initialDomainMapping, o
36
36
  }
37
37
  }
38
38
  catch (error) {
39
- if (axios_client_1.axios.isAxiosError(error)) {
40
- console.error('Error while installing initial domain mapping', (0, logger_1.serializeAxiosError)(error));
41
- }
42
- else {
43
- console.error('Error while installing initial domain mapping', error);
44
- }
39
+ console.error('Error while installing initial domain mapping.', (0, logger_1.serializeError)(error));
45
40
  }
46
41
  }
47
42
  // Set lastSyncStarted if the event type is ExtractionDataStart
@@ -108,12 +103,7 @@ class State {
108
103
  console.log('State updated successfully to', (0, logger_1.getPrintableState)(this.state));
109
104
  }
110
105
  catch (error) {
111
- if (axios_client_1.axios.isAxiosError(error)) {
112
- console.error('Failed to update state', (0, logger_1.serializeAxiosError)(error));
113
- }
114
- else {
115
- console.error('Failed to update state', error);
116
- }
106
+ console.error('Failed to update the state.', (0, logger_1.serializeError)(error));
117
107
  process.exit(1);
118
108
  }
119
109
  }
@@ -139,7 +139,11 @@ export interface EventContext {
139
139
  initial_sync_scope?: InitialSyncScope;
140
140
  mode: string;
141
141
  request_id: string;
142
+ /**
143
+ * @deprecated reset_extraction is deprecated and should not be used. Use reset_extract_from instead.
144
+ */
142
145
  reset_extraction?: boolean;
146
+ reset_extract_from?: boolean;
143
147
  snap_in_slug: string;
144
148
  snap_in_version_id: string;
145
149
  sync_run: string;
@@ -11,7 +11,7 @@ describe('EventContext type tests', () => {
11
11
  });
12
12
  it('should handle context with all optional fields', () => {
13
13
  const event = Object.assign({}, baseEvent);
14
- event.payload.event_context = Object.assign(Object.assign({}, baseEvent.payload.event_context), { extract_from: '2024-01-01T00:00:00Z', initial_sync_scope: extraction_1.InitialSyncScope.TIME_SCOPED, reset_extraction: true });
14
+ event.payload.event_context = Object.assign(Object.assign({}, baseEvent.payload.event_context), { extract_from: '2024-01-01T00:00:00Z', initial_sync_scope: extraction_1.InitialSyncScope.TIME_SCOPED, reset_extract_from: true });
15
15
  // Test with all optionals present
16
16
  expect(event).toBeDefined();
17
17
  });
@@ -73,7 +73,7 @@ class Uploader {
73
73
  const file = this.compressGzip(js_jsonl_1.jsonl.stringify(fetchedObjects));
74
74
  if (!file) {
75
75
  return {
76
- error: { message: 'Error while compressing jsonl object.' },
76
+ error: new Error('Error while compressing jsonl object.'),
77
77
  };
78
78
  }
79
79
  const filename = itemType + '.jsonl.gz';
@@ -82,21 +82,21 @@ class Uploader {
82
82
  const preparedArtifact = await this.getArtifactUploadUrl(filename, fileType);
83
83
  if (!preparedArtifact) {
84
84
  return {
85
- error: { message: 'Error while getting artifact upload URL.' },
85
+ error: new Error('Error while getting artifact upload URL.'),
86
86
  };
87
87
  }
88
88
  // Upload prepared artifact to the given url
89
89
  const uploadItemResponse = await this.uploadArtifact(preparedArtifact, file);
90
90
  if (!uploadItemResponse) {
91
91
  return {
92
- error: { message: 'Error while uploading artifact.' },
92
+ error: new Error('Error while uploading artifact.'),
93
93
  };
94
94
  }
95
95
  // Confirm upload
96
96
  const confirmArtifactUploadResponse = await this.confirmArtifactUpload(preparedArtifact.artifact_id);
97
97
  if (!confirmArtifactUploadResponse) {
98
98
  return {
99
- error: { message: 'Error while confirming artifact upload.' },
99
+ error: new Error('Error while confirming artifact upload.'),
100
100
  };
101
101
  }
102
102
  // Return the artifact information to the platform
@@ -121,12 +121,7 @@ class Uploader {
121
121
  return response.data;
122
122
  }
123
123
  catch (error) {
124
- if (axios_client_1.axios.isAxiosError(error)) {
125
- console.error('Error while getting artifact upload URL.', (0, logger_1.serializeAxiosError)(error));
126
- }
127
- else {
128
- console.error('Error while getting artifact upload URL.', error);
129
- }
124
+ console.error('Error while getting artifact upload URL.', (0, logger_1.serializeError)(error));
130
125
  }
131
126
  }
132
127
  async uploadArtifact(artifact, file) {
@@ -142,12 +137,7 @@ class Uploader {
142
137
  return response;
143
138
  }
144
139
  catch (error) {
145
- if (axios_client_1.axios.isAxiosError(error)) {
146
- console.error('Error while uploading artifact.', (0, logger_1.serializeAxiosError)(error));
147
- }
148
- else {
149
- console.error('Error while uploading artifact.', error);
150
- }
140
+ console.error('Error while uploading artifact.', (0, logger_1.serializeError)(error));
151
141
  }
152
142
  }
153
143
  async streamArtifact(artifact, fileStream) {
@@ -171,12 +161,7 @@ class Uploader {
171
161
  return response;
172
162
  }
173
163
  catch (error) {
174
- if (axios_client_1.axios.isAxiosError(error)) {
175
- console.error('Error while streaming artifact.', (0, logger_1.serializeAxiosError)(error));
176
- }
177
- else {
178
- console.error('Error while streaming artifact.', error);
179
- }
164
+ console.error('Error while streaming artifact.', (0, logger_1.serializeError)(error));
180
165
  return;
181
166
  }
182
167
  }
@@ -192,12 +177,7 @@ class Uploader {
192
177
  return response;
193
178
  }
194
179
  catch (error) {
195
- if (axios_client_1.axios.isAxiosError(error)) {
196
- console.error('Error while confirming artifact upload.', (0, logger_1.serializeAxiosError)(error));
197
- }
198
- else {
199
- console.error('Error while confirming artifact upload.', error);
200
- }
180
+ console.error('Error while confirming artifact upload.', (0, logger_1.serializeError)(error));
201
181
  }
202
182
  }
203
183
  async getAttachmentsFromArtifactId({ artifact, }) {
@@ -205,28 +185,28 @@ class Uploader {
205
185
  const artifactUrl = await this.getArtifactDownloadUrl(artifact);
206
186
  if (!artifactUrl) {
207
187
  return {
208
- error: { message: 'Error while getting artifact download URL.' },
188
+ error: new Error('Error while getting artifact download URL.'),
209
189
  };
210
190
  }
211
191
  // Download artifact from the URL
212
192
  const gzippedJsonlObject = await this.downloadArtifact(artifactUrl);
213
193
  if (!gzippedJsonlObject) {
214
194
  return {
215
- error: { message: 'Error while downloading gzipped jsonl object.' },
195
+ error: new Error('Error while downloading gzipped jsonl object.'),
216
196
  };
217
197
  }
218
198
  // Decompress the gzipped jsonl object
219
199
  const jsonlObject = this.decompressGzip(gzippedJsonlObject);
220
200
  if (!jsonlObject) {
221
201
  return {
222
- error: { message: 'Error while decompressing gzipped jsonl object.' },
202
+ error: new Error('Error while decompressing gzipped jsonl object.'),
223
203
  };
224
204
  }
225
205
  // Parse the jsonl object to get the attachment metadata
226
206
  const jsonObject = this.parseJsonl(jsonlObject);
227
207
  if (!jsonObject) {
228
208
  return {
229
- error: { message: 'Error while parsing jsonl object.' },
209
+ error: new Error('Error while parsing jsonl object.'),
230
210
  };
231
211
  }
232
212
  return { attachments: jsonObject };
@@ -244,12 +224,7 @@ class Uploader {
244
224
  return response.data.download_url;
245
225
  }
246
226
  catch (error) {
247
- if (axios_client_1.axios.isAxiosError(error)) {
248
- console.error('Error while getting artifact download URL.', (0, logger_1.serializeAxiosError)(error));
249
- }
250
- else {
251
- console.error('Error while getting artifact download URL.', error);
252
- }
227
+ console.error('Error while getting artifact download URL.', (0, logger_1.serializeError)(error));
253
228
  }
254
229
  }
255
230
  async downloadArtifact(artifactUrl) {
@@ -260,12 +235,7 @@ class Uploader {
260
235
  return response.data;
261
236
  }
262
237
  catch (error) {
263
- if (axios_client_1.axios.isAxiosError(error)) {
264
- console.error('Error while downloading artifact from URL.', (0, logger_1.serializeAxiosError)(error));
265
- }
266
- else {
267
- console.error('Error while downloading artifact from URL.', error);
268
- }
238
+ console.error('Error while downloading artifact from URL.', (0, logger_1.serializeError)(error));
269
239
  }
270
240
  }
271
241
  compressGzip(jsonlObject) {
@@ -56,16 +56,17 @@ describe('Uploader Class Tests', () => {
56
56
  });
57
57
  });
58
58
  it('should handle failure in getArtifactUploadUrl', async () => {
59
+ var _a;
59
60
  // Mock unsuccessful response for getArtifactUploadUrl
60
61
  axios_client_1.axiosClient.get.mockResolvedValueOnce(undefined);
61
62
  const entity = 'entity';
62
63
  const fetchedObjects = [{ key: 'value' }];
63
64
  const uploadResponse = await uploader.upload(entity, fetchedObjects);
64
- expect(uploadResponse).toEqual({
65
- error: { message: 'Error while getting artifact upload URL.' },
66
- });
65
+ expect(uploadResponse.error).toBeInstanceOf(Error);
66
+ expect((_a = uploadResponse.error) === null || _a === void 0 ? void 0 : _a.message).toBe('Error while getting artifact upload URL.');
67
67
  });
68
68
  it('should handle failure in uploadArtifact', async () => {
69
+ var _a;
69
70
  // Mock successful response for getArtifactUploadUrl
70
71
  axios_client_1.axiosClient.get.mockResolvedValueOnce(getArtifactUploadUrlMockResponse);
71
72
  // Mock unsuccessful response for uploadArtifact
@@ -73,11 +74,11 @@ describe('Uploader Class Tests', () => {
73
74
  const entity = 'entity';
74
75
  const fetchedObjects = [{ key: 'value' }];
75
76
  const uploadResponse = await uploader.upload(entity, fetchedObjects);
76
- expect(uploadResponse).toEqual({
77
- error: { message: 'Error while uploading artifact.' },
78
- });
77
+ expect(uploadResponse.error).toBeInstanceOf(Error);
78
+ expect((_a = uploadResponse.error) === null || _a === void 0 ? void 0 : _a.message).toBe('Error while uploading artifact.');
79
79
  });
80
80
  it('should handle failure in confirmArtifactUpload', async () => {
81
+ var _a;
81
82
  // Mock successful response for getArtifactUploadUrl
82
83
  axios_client_1.axiosClient.get.mockResolvedValueOnce(getArtifactUploadUrlMockResponse);
83
84
  // Mock successful response from uploadArtifact
@@ -87,8 +88,7 @@ describe('Uploader Class Tests', () => {
87
88
  const entity = 'entity';
88
89
  const fetchedObjects = [{ key: 'value' }];
89
90
  const uploadResponse = await uploader.upload(entity, fetchedObjects);
90
- expect(uploadResponse).toEqual({
91
- error: { message: 'Error while confirming artifact upload.' },
92
- });
91
+ expect(uploadResponse.error).toBeInstanceOf(Error);
92
+ expect((_a = uploadResponse.error) === null || _a === void 0 ? void 0 : _a.message).toBe('Error while confirming artifact upload.');
93
93
  });
94
94
  });
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Spawn = void 0;
7
7
  exports.spawn = spawn;
8
- const axios_1 = __importDefault(require("axios"));
9
8
  const helpers_1 = require("yargs/helpers");
10
9
  const yargs_1 = __importDefault(require("yargs"));
11
10
  const extraction_1 = require("../types/extraction");
@@ -124,12 +123,7 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
124
123
  });
125
124
  }
126
125
  catch (error) {
127
- if (axios_1.default.isAxiosError(error)) {
128
- console.error('Error while emitting event', (0, logger_1.serializeAxiosError)(error));
129
- }
130
- else {
131
- console.error('Error while emitting event', error);
132
- }
126
+ console.error('Error while emitting event.', (0, logger_1.serializeError)(error));
133
127
  }
134
128
  }
135
129
  }
@@ -217,12 +211,7 @@ class Spawn {
217
211
  this.resolve();
218
212
  }
219
213
  catch (error) {
220
- if (axios_1.default.isAxiosError(error)) {
221
- console.error('Error while emitting event', (0, logger_1.serializeAxiosError)(error));
222
- }
223
- else {
224
- console.error('Error while emitting event', error);
225
- }
214
+ console.error('Error while emitting event.', (0, logger_1.serializeError)(error));
226
215
  }
227
216
  }
228
217
  }
@@ -92,7 +92,7 @@ class WorkerAdapter {
92
92
  }
93
93
  // Loop through the batches of attachments
94
94
  for (let i = lastProcessedBatchIndex; i < reducedAttachments.length; i++) {
95
- // Check if we hit timeout
95
+ // Check if we hit timeout
96
96
  if (adapter.isTimeout) {
97
97
  await (0, helpers_2.sleep)(constants_1.DEFAULT_SLEEP_DELAY_MS);
98
98
  }
@@ -263,12 +263,7 @@ class WorkerAdapter {
263
263
  node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(message);
264
264
  }
265
265
  catch (error) {
266
- if (axios_client_1.axios.isAxiosError(error)) {
267
- console.error(`Error while emitting event with event type: ${newEventType}`, (0, logger_1.serializeAxiosError)(error));
268
- }
269
- else {
270
- console.error(`Unknown error while emitting event with event type: ${newEventType}`, error);
271
- }
266
+ console.error(`Error while emitting event with event type: ${newEventType}.`, (0, logger_1.serializeError)(error));
272
267
  node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage(workers_1.WorkerMessageSubject.WorkerMessageExit);
273
268
  }
274
269
  }
@@ -487,22 +482,12 @@ class WorkerAdapter {
487
482
  });
488
483
  }
489
484
  catch (error) {
490
- if (axios_client_1.axios.isAxiosError(error)) {
491
- console.warn('Failed to update sync mapper record', (0, logger_1.serializeAxiosError)(error));
492
- return {
493
- error: {
494
- message: error.message,
495
- },
496
- };
497
- }
498
- else {
499
- console.warn('Failed to update sync mapper record', error);
500
- return {
501
- error: {
502
- message: 'Failed to update sync mapper record' + error,
503
- },
504
- };
505
- }
485
+ console.warn('Failed to update sync mapper record.', (0, logger_1.serializeError)(error));
486
+ return {
487
+ error: {
488
+ message: 'Failed to update sync mapper record' + (0, logger_1.serializeError)(error),
489
+ },
490
+ };
506
491
  }
507
492
  }
508
493
  return {
@@ -557,18 +542,11 @@ class WorkerAdapter {
557
542
  };
558
543
  }
559
544
  catch (error) {
560
- if (axios_client_1.axios.isAxiosError(error)) {
561
- console.warn('Failed to create sync mapper record', (0, logger_1.serializeAxiosError)(error));
562
- return {
563
- error: {
564
- message: error.message,
565
- },
566
- };
567
- }
568
- console.warn('Failed to create sync mapper record', error);
545
+ console.warn('Failed to create sync mapper record.', (0, logger_1.serializeError)(error));
569
546
  return {
570
547
  error: {
571
- message: 'Failed to create sync mapper record' + error,
548
+ message: 'Failed to create sync mapper record. ' +
549
+ (0, logger_1.serializeError)(error),
572
550
  },
573
551
  };
574
552
  }
@@ -581,7 +559,7 @@ class WorkerAdapter {
581
559
  };
582
560
  }
583
561
  else {
584
- console.warn('Failed to create item in external system', error);
562
+ console.warn('Failed to create item in external system.', (0, logger_1.serializeError)(error));
585
563
  return {
586
564
  report: {
587
565
  item_type: itemTypeToLoad.itemType,
@@ -591,7 +569,7 @@ class WorkerAdapter {
591
569
  }
592
570
  }
593
571
  else {
594
- console.warn('Failed to get sync mapper record', (0, logger_1.serializeAxiosError)(error));
572
+ console.warn('Failed to get sync mapper record.', (0, logger_1.serializeError)(error));
595
573
  return {
596
574
  error: {
597
575
  message: error.message,
@@ -599,10 +577,10 @@ class WorkerAdapter {
599
577
  };
600
578
  }
601
579
  }
602
- console.warn('Failed to get sync mapper record', error);
580
+ console.warn('Failed to get sync mapper record.', (0, logger_1.serializeError)(error));
603
581
  return {
604
582
  error: {
605
- message: 'Failed to get sync mapper record' + error,
583
+ message: 'Failed to get sync mapper record. ' + (0, logger_1.serializeError)(error),
606
584
  },
607
585
  };
608
586
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/ts-adaas",
3
- "version": "1.6.0",
3
+ "version": "1.7.0-beta.1",
4
4
  "description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
@@ -34,8 +34,7 @@
34
34
  "eslint-config-prettier": "^10.1.5",
35
35
  "eslint-plugin-prettier": "^5.1.3",
36
36
  "jest": "^29.7.0",
37
- "ts-jest": "^29.3.3",
38
- "typescript": "^5.3.3"
37
+ "ts-jest": "^29.3.3"
39
38
  },
40
39
  "dependencies": {
41
40
  "@devrev/typescript-sdk": "^1.1.59",
@@ -43,8 +42,8 @@
43
42
  "axios-retry": "^4.5.0",
44
43
  "form-data": "^4.0.1",
45
44
  "js-jsonl": "^1.1.1",
46
- "lambda-log": "^3.1.0",
47
45
  "ts-node": "^10.9.2",
46
+ "typescript": "^5.3.3",
48
47
  "yargs": "^17.7.2"
49
48
  },
50
49
  "files": [