@devrev/ts-adaas 1.1.1 → 1.1.2

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,11 @@
2
2
 
3
3
  ## Release Notes
4
4
 
5
+ #### v1.1.2
6
+
7
+ - Unified incoming and outgoing event context.
8
+ - Added `dev_oid` to logger tags.
9
+
5
10
  #### v1.1.1
6
11
 
7
12
  - Added default workers for loading deletion events.
@@ -54,14 +59,14 @@
54
59
 
55
60
  # Overview
56
61
 
57
- The ADaaS (Airdrop-as-a-Service) Library for TypeScript helps developers build Snap-ins that integrate with DevRev’s ADaaS platform. This library simplifies the workflow for handling data extraction, event-driven actions, state management, and artifact handling.
62
+ The ADaaS (Airdrop-as-a-Service) Library for TypeScript helps developers build Snap-ins that integrate with DevRev’s ADaaS platform. This library simplifies the workflow for handling data extraction and loading, event-driven actions, state management, and artifact handling.
58
63
 
59
- ## Features
64
+ It provides features such as:
60
65
 
61
66
  - Type Definitions: Structured types for ADaaS control protocol
62
- - Event Management: Easily emit events for different extraction phases
67
+ - Event Management: Easily emit events for different extraction or loading phases
63
68
  - State Handling: Update and access state in real-time within tasks
64
- - Artifact Management: Supports batched storage of artifacts (2000 items per batch)
69
+ - Artifact Management: Supports batched storage of artifacts
65
70
  - Error & Timeout Support: Error handling and timeout management for long-running tasks
66
71
 
67
72
  # Installation
@@ -72,7 +77,22 @@ npm install @devrev/ts-adaas
72
77
 
73
78
  # Usage
74
79
 
75
- ADaaS Snap-ins are composed of several phases, each with unique requirements for initialization, data extraction, and error handling. The ADaaS library exports processTask to structure the work within each phase. The processTask function accepts task and onTimeout handlers, giving access to the adapter to streamline state updates, upload of extracted data, and event emission.
80
+ ADaaS Snap-ins can import data in both directions: from external sources to DevRev and from DevRev to external sources. Both directions are composed of several phases.
81
+
82
+ From external source to DevRev:
83
+
84
+ - External Sync Units Extraction
85
+ - Metadata Extraction
86
+ - Data Extraction
87
+ - Attachments Extraction
88
+
89
+ From DevRev to external source:
90
+
91
+ - Data Loading
92
+
93
+ Each phase comes with unique requirements for processing task, and both timeout and error handling.
94
+
95
+ The ADaaS library exports processTask to structure the work within each phase, and onTimeout function to handle timeouts.
76
96
 
77
97
  ### ADaaS Snap-in Invocation
78
98
 
@@ -127,10 +147,14 @@ const run = async (events: AirdropEvent[]) => {
127
147
  export default run;
128
148
  ```
129
149
 
130
- ## Extraction Phases
150
+ ## Extraction
131
151
 
132
152
  The ADaaS snap-in extraction lifecycle consists of three main phases: External Sync Units Extraction, Metadata Extraction, and Data Extraction. Each phase is defined in a separate file and is responsible for fetching the respective data.
133
153
 
154
+ The ADaaS library provides a repository management system to handle artifacts in batches. The `initializeRepos` function initializes the repositories, and the `push` function uploads the artifacts to the repositories. The `postState` function is used to post the state of the extraction task.
155
+
156
+ State management is crucial for ADaaS Snap-ins to maintain the state of the extraction task. The `postState` function is used to post the state of the extraction task. The state is stored in the adapter and can be retrieved using the `adapter.state` property.
157
+
134
158
  ### 1. External Sync Units Extraction
135
159
 
136
160
  This phase is defined in `external-sync-units-extraction.ts` and is responsible for fetching the external sync units.
@@ -243,7 +267,7 @@ processTask({
243
267
  });
244
268
  ```
245
269
 
246
- ## 4. Attachments Streaming
270
+ ### 4. Attachments Streaming
247
271
 
248
272
  The ADaaS library handles attachments streaming to improve efficiency and reduce complexity for developers. During the extraction phase, developers need only to provide metadata in a specific format for each attachment, and the library manages the streaming process.
249
273
 
@@ -259,12 +283,45 @@ export interface NormalizedAttachment {
259
283
  }
260
284
  ```
261
285
 
262
- ## Artifact Uploading and State Management
286
+ ## Loading phases
263
287
 
264
- The ADaaS library provides a repository management system to handle artifacts in batches. The `initializeRepos` function initializes the repositories, and the `push` function uploads the artifacts to the repositories. The `postState` function is used to post the state of the extraction task.
288
+ ### 1. Data Loading
265
289
 
266
- State management is crucial for ADaaS Snap-ins to maintain the state of the extraction task. The `postState` function is used to post the state of the extraction task. The state is stored in the adapter and can be retrieved using the `adapter.state` property.
290
+ This phase is defined in `data-loading.ts` and is responsible for loading the data to the external system.
291
+
292
+ Loading is done by providing an ordered list of itemTypes to load and their respective create and update functions.
293
+
294
+ ```typescript
295
+ processTask({
296
+ task: async ({ adapter }) => {
297
+ const { reports, processed_files } = await adapter.loadItemTypes({
298
+ itemTypesToLoad: [
299
+ {
300
+ itemType: 'tickets',
301
+ create: createTicket,
302
+ update: updateTicket,
303
+ },
304
+ {
305
+ itemType: 'conversations',
306
+ create: createConversation,
307
+ update: updateConversation,
308
+ },
309
+ ],
310
+ });
311
+
312
+ await adapter.emit(LoaderEventType.DataLoadingDone, {
313
+ reports,
314
+ processed_files,
315
+ });
316
+ },
317
+ onTimeout: async ({ adapter }) => {
318
+ await adapter.emit(LoaderEventType.DataLoadingProgress, {
319
+ reports: adapter.reports,
320
+ processed_files: adapter.processedFiles,
321
+ });
322
+ });
323
+ ```
267
324
 
268
- ## Timeout Handling
325
+ The loading functions `create` and `update` provide loading to the external system. They provide denormalization of the records to the schema of the external system and provide HTTP calls to the external system. Both loading functions must handle rate limiting for the external system and handle errors.
269
326
 
270
- The ADaaS library provides a timeout handler to handle timeouts in long-running tasks. The `onTimeout` handler is called when the task exceeds the timeout limit. The handler can be used to post the state of the extraction task and emit an event when a timeout occurs.
327
+ Functions return an ID and modified date of the record in the external system, or specify rate-liming offset or errors, if the record could not be created or updated.
@@ -9,9 +9,7 @@ const logger_1 = require("../logger/logger");
9
9
  const emit = async ({ event, eventType, data, }) => {
10
10
  const newEvent = {
11
11
  event_type: eventType,
12
- event_context: Object.assign({ uuid: event.payload.event_context.uuid, sync_run: event.payload.event_context.sync_run_id }, (event.payload.event_context.sync_unit_id && {
13
- sync_unit: event.payload.event_context.sync_unit_id,
14
- })),
12
+ event_context: event.payload.event_context,
15
13
  event_data: Object.assign({}, data),
16
14
  };
17
15
  return new Promise(async (resolve, reject) => {
@@ -93,9 +93,7 @@ class Adapter {
93
93
  }
94
94
  const newEvent = {
95
95
  event_type: newEventType,
96
- event_context: Object.assign({ uuid: this.event.payload.event_context.uuid, sync_run: this.event.payload.event_context.sync_run_id }, (this.event.payload.event_context.sync_unit_id && {
97
- sync_unit: this.event.payload.event_context.sync_unit_id,
98
- })),
96
+ event_context: this.event.payload.event_context,
99
97
  event_data: Object.assign({}, data),
100
98
  };
101
99
  try {
@@ -2,7 +2,6 @@ import { Console } from 'node:console';
2
2
  import { LoggerFactoryInterface, LogLevel, PrintableState } from './logger.interfaces';
3
3
  import { AxiosError } from 'axios';
4
4
  export declare class Logger extends Console {
5
- private event;
6
5
  private options?;
7
6
  constructor({ event, options }: LoggerFactoryInterface);
8
7
  logFn(args: unknown[], level: LogLevel): void;
@@ -14,12 +14,11 @@ const workers_1 = require("../types/workers");
14
14
  class Logger extends node_console_1.Console {
15
15
  constructor({ event, options }) {
16
16
  super(process.stdout, process.stderr);
17
- this.event = event;
18
17
  this.options = options;
19
18
  lambda_log_1.default.options.levelKey = null;
20
19
  lambda_log_1.default.options.tagsKey = null;
21
20
  lambda_log_1.default.options.messageKey = 'message';
22
- lambda_log_1.default.options.meta = Object.assign({}, event.payload.event_context);
21
+ lambda_log_1.default.options.meta = Object.assign(Object.assign({}, event.payload.event_context), { dev_oid: event.payload.event_context.dev_org });
23
22
  }
24
23
  logFn(args, level) {
25
24
  var _a;
@@ -74,6 +74,7 @@ export interface ExternalSyncUnit {
74
74
  }
75
75
  /**
76
76
  * EventContextIn is an interface that defines the structure of the input event context that is sent to the external extractor from ADaaS.
77
+ * @deprecated
77
78
  */
78
79
  export interface EventContextIn {
79
80
  callback_url: string;
@@ -100,12 +101,39 @@ export interface EventContextIn {
100
101
  }
101
102
  /**
102
103
  * EventContextOut is an interface that defines the structure of the output event context that is sent from the external extractor to ADaaS.
104
+ * @deprecated
103
105
  */
104
106
  export interface EventContextOut {
105
107
  uuid: string;
106
108
  sync_run: string;
107
109
  sync_unit?: string;
108
110
  }
111
+ /**
112
+ * EventContext is an interface that defines the structure of the event context that is sent to and from the external connector.
113
+ */
114
+ export interface EventContext {
115
+ callback_url: string;
116
+ dev_org: string;
117
+ dev_org_id: string;
118
+ dev_user: string;
119
+ dev_user_id: string;
120
+ external_sync_unit: string;
121
+ external_sync_unit_id: string;
122
+ external_sync_unit_name: string;
123
+ external_system: string;
124
+ external_system_type: string;
125
+ import_slug: string;
126
+ mode: string;
127
+ request_id: string;
128
+ snap_in_slug: string;
129
+ sync_run: string;
130
+ sync_run_id: string;
131
+ sync_tier: string;
132
+ sync_unit: DonV2;
133
+ sync_unit_id: string;
134
+ uuid: string;
135
+ worker_data_url: string;
136
+ }
109
137
  /**
110
138
  * ConnectionData is an interface that defines the structure of the connection data that is sent to the external extractor from ADaaS.
111
139
  * It contains the organization ID, organization name, key, and key type.
@@ -169,7 +197,7 @@ export interface AirdropEvent {
169
197
  */
170
198
  export interface AirdropMessage {
171
199
  connection_data: ConnectionData;
172
- event_context: EventContextIn;
200
+ event_context: EventContext;
173
201
  event_type: EventType;
174
202
  event_data?: EventData;
175
203
  }
@@ -179,7 +207,7 @@ export interface AirdropMessage {
179
207
  */
180
208
  export interface ExtractorEvent {
181
209
  event_type: string;
182
- event_context: EventContextOut;
210
+ event_context: EventContext;
183
211
  event_data?: EventData;
184
212
  }
185
213
  /**
@@ -187,6 +215,6 @@ export interface ExtractorEvent {
187
215
  */
188
216
  export interface LoaderEvent {
189
217
  event_type: string;
190
- event_context: EventContextOut;
218
+ event_context: EventContext;
191
219
  event_data?: EventData;
192
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrev/ts-adaas",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",