@devrev/ts-adaas 1.2.2 → 1.2.3

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,13 @@
2
2
 
3
3
  ## Release Notes
4
4
 
5
+ ### v1.2.3
6
+
7
+ - Add `local` flag to use for local development of the ADaaS snap-ins.
8
+ - Send library version, snap-in version and snap-in slug in headers while emitting.
9
+ - Make `actor_id` field optional for `SsorAttachment` interface.
10
+ - Fix bugs related to event handling, error logging.
11
+
5
12
  ### v1.2.2
6
13
 
7
14
  - Add library version as a part of control protocol.
@@ -10,3 +10,4 @@ export declare const AIRDROP_DEFAULT_ITEM_TYPES: {
10
10
  ATTACHMENTS: string;
11
11
  SSOR_ATTACHMENT: string;
12
12
  };
13
+ export declare const LIBRARY_VERSION: any;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AIRDROP_DEFAULT_ITEM_TYPES = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.ALLOWED_EVENT_TYPES = exports.ALLOWED_LOADING_EVENT_TYPES = exports.ALLOWED_EXTRACTION_EVENT_TYPES = exports.STATELESS_EVENT_TYPES = void 0;
3
+ exports.LIBRARY_VERSION = exports.AIRDROP_DEFAULT_ITEM_TYPES = exports.MAX_DEVREV_ARTIFACT_SIZE = exports.ARTIFACT_BATCH_SIZE = exports.ALLOWED_EVENT_TYPES = exports.ALLOWED_LOADING_EVENT_TYPES = exports.ALLOWED_EXTRACTION_EVENT_TYPES = exports.STATELESS_EVENT_TYPES = void 0;
4
4
  const extraction_1 = require("../types/extraction");
5
+ const helpers_1 = require("./helpers");
5
6
  exports.STATELESS_EVENT_TYPES = [
6
7
  extraction_1.EventType.ExtractionExternalSyncUnitsStart,
7
8
  extraction_1.EventType.ExtractionMetadataStart,
@@ -37,3 +38,4 @@ exports.AIRDROP_DEFAULT_ITEM_TYPES = {
37
38
  ATTACHMENTS: 'attachments',
38
39
  SSOR_ATTACHMENT: 'ssor_attachment',
39
40
  };
41
+ exports.LIBRARY_VERSION = (0, helpers_1.getLibraryVersion)();
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.emit = void 0;
4
4
  const axios_client_1 = require("../http/axios-client");
5
- const helpers_1 = require("./helpers");
5
+ const constants_1 = require("./constants");
6
6
  const emit = async ({ event, eventType, data, }) => {
7
7
  const newEvent = {
8
8
  event_type: eventType,
9
9
  event_context: event.payload.event_context,
10
10
  event_data: Object.assign({}, data),
11
11
  worker_metadata: {
12
- adaas_library_version: (0, helpers_1.getLibraryVersion)(),
12
+ adaas_library_version: constants_1.LIBRARY_VERSION,
13
13
  },
14
14
  };
15
15
  console.info('Emitting event', JSON.stringify(newEvent));
@@ -18,6 +18,9 @@ const emit = async ({ event, eventType, data, }) => {
18
18
  Accept: 'application/json, text/plain, */*',
19
19
  Authorization: event.context.secrets.service_account_token,
20
20
  'Content-Type': 'application/json',
21
+ 'X-DevRev-Client-Platform': event.payload.event_context.snap_in_slug,
22
+ 'X-DevRev-Client-Id': event.payload.event_context.snap_in_version_id,
23
+ 'X-DevRev-Client-Version': constants_1.LIBRARY_VERSION,
21
24
  },
22
25
  });
23
26
  };
@@ -80,6 +80,11 @@ function getTimeoutErrorEventType(eventType) {
80
80
  return {
81
81
  eventType: loading_1.LoaderEventType.LoaderStateDeletionError,
82
82
  };
83
+ case extraction_1.EventType.StartLoadingAttachments:
84
+ case extraction_1.EventType.ContinueLoadingAttachments:
85
+ return {
86
+ eventType: loading_1.LoaderEventType.AttachmentLoadingError,
87
+ };
83
88
  case extraction_1.EventType.StartDeletingLoaderAttachmentState:
84
89
  return {
85
90
  eventType: loading_1.LoaderEventType.LoaderAttachmentStateDeletionError,
@@ -160,7 +165,11 @@ function getCircularReplacer() {
160
165
  function getLibraryVersion() {
161
166
  var _a;
162
167
  try {
163
- return (_a = JSON.parse((0, fs_1.readFileSync)(path.resolve(__dirname, '../../package.json'), 'utf8'))) === null || _a === void 0 ? void 0 : _a.version;
168
+ const version = (_a = JSON.parse((0, fs_1.readFileSync)(path.resolve(__dirname, '../../package.json'), 'utf8'))) === null || _a === void 0 ? void 0 : _a.version;
169
+ if (version) {
170
+ return version;
171
+ }
172
+ return '';
164
173
  }
165
174
  catch (error) {
166
175
  console.error('Error reading adaas library version from package.json', error);
@@ -34,8 +34,8 @@ export interface NormalizedAttachment {
34
34
  url: string;
35
35
  id: string;
36
36
  file_name: string;
37
- author_id: string;
38
37
  parent_id: string;
38
+ author_id?: string;
39
39
  grand_parent_id?: number;
40
40
  }
41
41
  /**
@@ -31,6 +31,7 @@ function createEvent({ eventType, externalSyncUnits = [], progress, error, delay
31
31
  mode: 'test_mode',
32
32
  request_id: 'test_request_id',
33
33
  snap_in_slug: 'test_snap_in_slug',
34
+ snap_in_version_id: 'test_snap_in_version_id',
34
35
  sync_run: 'test_sync_run',
35
36
  sync_run_id: 'test_sync_run_id',
36
37
  sync_tier: 'test_sync_tier',
@@ -131,6 +131,7 @@ export interface EventContext {
131
131
  mode: string;
132
132
  request_id: string;
133
133
  snap_in_slug: string;
134
+ snap_in_version_id: string;
134
135
  sync_run: string;
135
136
  sync_run_id: string;
136
137
  sync_tier: string;
@@ -58,7 +58,7 @@ export interface SsorAttachment {
58
58
  parent_id: {
59
59
  external: string;
60
60
  };
61
- actor_id: {
61
+ actor_id?: {
62
62
  external: string;
63
63
  };
64
64
  }
@@ -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', (0, logger_1.serializeError)(error));
19
+ logger.error('Worker error', error);
20
20
  reject();
21
21
  });
22
22
  worker.on(workers_1.WorkerEvent.WorkerOnline, () => {
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Spawn = void 0;
7
7
  exports.spawn = spawn;
8
8
  const axios_1 = __importDefault(require("axios"));
9
+ const helpers_1 = require("yargs/helpers");
10
+ const yargs_1 = __importDefault(require("yargs"));
9
11
  const extraction_1 = require("../types/extraction");
10
12
  const control_protocol_1 = require("../common/control-protocol");
11
- const helpers_1 = require("../common/helpers");
13
+ const helpers_2 = require("../common/helpers");
12
14
  const logger_1 = require("../logger/logger");
13
15
  const workers_1 = require("../types/workers");
14
16
  const create_worker_1 = require("./create-worker");
@@ -75,6 +77,14 @@ async function spawn({ event, initialState, workerPath, options, }) {
75
77
  event,
76
78
  connectorWorkerPath: workerPath,
77
79
  });
80
+ if (options === null || options === void 0 ? void 0 : options.isLocalDevelopment) {
81
+ logger.warn('WARN: isLocalDevelopment is deprecated. Please use the -- local flag instead.');
82
+ }
83
+ // read the command line arguments to check if the local flag is passed
84
+ const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).argv;
85
+ if (argv._.includes('local')) {
86
+ options = Object.assign(Object.assign({}, (options || {})), { isLocalDevelopment: true });
87
+ }
78
88
  if (script) {
79
89
  try {
80
90
  const worker = await (0, create_worker_1.createWorker)({
@@ -181,7 +191,7 @@ class Spawn {
181
191
  return;
182
192
  }
183
193
  this.alreadyEmitted = true;
184
- const timeoutEventType = (0, helpers_1.getTimeoutErrorEventType)(this.event.payload.event_type);
194
+ const timeoutEventType = (0, helpers_2.getTimeoutErrorEventType)(this.event.payload.event_type);
185
195
  if (timeoutEventType) {
186
196
  const { eventType } = timeoutEventType;
187
197
  try {
@@ -529,10 +529,12 @@ class WorkerAdapter {
529
529
  parent_id: {
530
530
  external: attachment.parent_id,
531
531
  },
532
- actor_id: {
533
- external: attachment.author_id,
534
- },
535
532
  };
533
+ if (attachment.author_id) {
534
+ ssorAttachment.actor_id = {
535
+ external: attachment.author_id,
536
+ };
537
+ }
536
538
  await ((_b = this.getRepo('ssor_attachment')) === null || _b === void 0 ? void 0 : _b.push([ssorAttachment]));
537
539
  }
538
540
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/ts-adaas",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "DevRev ADaaS (AirDrop-as-a-Service) Typescript SDK.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
@@ -26,6 +26,7 @@
26
26
  "@types/jest": "^29.5.12",
27
27
  "@types/lambda-log": "^3.0.3",
28
28
  "@types/node": "20.16.11",
29
+ "@types/yargs": "^17.0.33",
29
30
  "@typescript-eslint/eslint-plugin": "^7.12.0",
30
31
  "@typescript-eslint/parser": "^7.12.0",
31
32
  "eslint": "^8.57.0",
@@ -42,7 +43,8 @@
42
43
  "form-data": "^4.0.1",
43
44
  "js-jsonl": "^1.1.1",
44
45
  "lambda-log": "^3.1.0",
45
- "ts-node": "^10.9.2"
46
+ "ts-node": "^10.9.2",
47
+ "yargs": "^17.7.2"
46
48
  },
47
49
  "files": [
48
50
  "dist"