|
1 |
| -# ADaaS Library |
| 1 | +# Airdrop SDK |
2 | 2 |
|
3 |
| -## Release Notes |
| 3 | +[](https://coveralls.io/github/devrev/adaas-sdk?branch=main) |
4 | 4 |
|
5 |
| -### v1.2.5 |
| 5 | +## Overview |
6 | 6 |
|
7 |
| -- Add batch size option. |
8 |
| -- Replace DevRev Typescript SDK requests with Axios for uploading and downloading artifacts. |
9 |
| -- Remove unneccessary postState from default workers. |
10 |
| -- Fix bugs related to attachment streaming. |
| 7 | +The Airdrop SDK for TypeScript helps developers build snap-ins that integrate with DevRev’s Airdrop platform. |
| 8 | +This SDK simplifies the workflow for handling data extraction and loading, event-driven actions, state management, and artifact handling. |
11 | 9 |
|
12 |
| -### v1.2.4 |
| 10 | +It provides features such as: |
13 | 11 |
|
14 |
| -- Do not fail the extraction of attachments if streaming of single attachment fails. |
| 12 | +- Type Definitions: Structured types for Airdrop control protocol |
| 13 | +- Event Management: Easily emit events for different extraction or loading phases |
| 14 | +- State Handling: Update and access state in real-time within tasks |
| 15 | +- Artifact Management: Supports batched storage of artifacts |
| 16 | +- Error & Timeout Support: Error handling and timeout management for long-running tasks |
15 | 17 |
|
16 |
| -### v1.2.3 |
| 18 | +## Installation |
17 | 19 |
|
18 |
| -- Add `local` flag to use for local development of the ADaaS snap-ins. |
19 |
| -- Send library version, snap-in version and snap-in slug in headers while emitting. |
20 |
| -- Make `actor_id` field optional for `SsorAttachment` interface. |
21 |
| -- Fix bugs related to event handling, error logging. |
| 20 | +```bash |
| 21 | +npm install @devrev/ts-adaas |
| 22 | +``` |
22 | 23 |
|
23 |
| -### v1.2.2 |
| 24 | +## Reference |
24 | 25 |
|
25 |
| -- Add library version as a part of control protocol. |
26 |
| -- Improve axios client and adapter logging. |
27 |
| -- Fix bugs related to state handling. |
| 26 | +### `spawn` function |
28 | 27 |
|
29 |
| -### v1.2.1 |
| 28 | +This function initializes a new worker thread and oversees its lifecycle. |
| 29 | +It should be invoked when the snap-in receives a message from the Airdrop platform. |
| 30 | +The worker script provided then handles the event accordingly. |
30 | 31 |
|
31 |
| -- Reduced the `delayFactor` to minimize unnecessary delays. |
32 |
| -- Correct the setting of the `lastSyncStarted` timestamp. |
33 |
| -- Improve logging for attachment extraction and loading. |
34 |
| -- Fix several bugs related to the control protocol. |
| 32 | +#### Usage |
35 | 33 |
|
36 |
| -### v1.2.0 |
| 34 | +```typescript |
| 35 | +spawn({ event, initialState, workerPath, options }) |
| 36 | +``` |
37 | 37 |
|
38 |
| -- Add support for loading attachments from DevRev to external system. |
| 38 | +#### Parameters |
39 | 39 |
|
40 |
| -### v1.1.6 |
| 40 | +* _event_ |
| 41 | + |
| 42 | + Required. An object of type __AirdropEvent__ that is received from the Airdrop platform. |
41 | 43 |
|
42 |
| -- Add exponential retry and handle rate-limiting towards DevRev. |
43 |
| -- Gracefully handle failure to upload extracted attachments. |
| 44 | +* _initialState_ |
44 | 45 |
|
45 |
| -### v1.1.5 |
| 46 | + Required. Object of __any__ type that represents the initial state of the snap-in. |
46 | 47 |
|
47 |
| -- Increase `delayFactor` and number of retries for the exponential backoff retry mechanism for HTTP requests. |
48 |
| -- Provide an inject function for streaming attachments. |
49 |
| -- Fix the attachments streaming bug. |
| 48 | +* _workerPath_ |
50 | 49 |
|
51 |
| -### v1.1.4 |
| 50 | + Required. A __string__ that represents the path to the worker file. |
52 | 51 |
|
53 |
| -- Provide log lines and stack traces for runtime worker errors. |
| 52 | +* _options_ |
54 | 53 |
|
55 |
| -### v1.1.3 |
| 54 | + Optional. An object of type **WorkerAdapterOptions**, which will be passed to the newly created worker. This worker will then initialize a `WorkerAdapter` by invoking the `processTask` function. The options include: |
| 55 | + |
| 56 | + * `isLocalDevelopment` |
| 57 | + |
| 58 | + A __boolean__ flag. If set to `true`, intermediary files containing extracted data will be stored on the local machine, which is useful during development. The default value is `false`. |
56 | 59 |
|
57 |
| -- Export `axios` and `axiosClient` with the exponential backoff retry mechanism for HTTP requests and omit Authorization headers from Axios errors. |
58 |
| -- Resolve circular structure logging issues. |
59 |
| -- Fix the attachments metadata normalization bug. |
60 |
| -- Improve repository logging. |
| 60 | + * `timeout` |
| 61 | + |
| 62 | + A __number__ that specifies the timeout duration for the lambda function, in milliseconds. The default is 10 minutes (10 * 60 * 1000 milliseconds), with a maximum allowable duration of 13 minutes (13 * 60 * 1000 milliseconds). |
| 63 | + |
| 64 | + * `batchSize` |
61 | 65 |
|
62 |
| -### v1.1.2 |
| 66 | + A __number__ that determines the maximum number of items to be processed and saved to an intermediary file before being sent to the Airdrop platform. The default batch size is 2,000. |
63 | 67 |
|
64 |
| -- Unify incoming and outgoing event context. |
65 |
| -- Add `dev_oid` to logger tags. |
| 68 | +#### Return value |
66 | 69 |
|
67 |
| -### v1.1.1 |
| 70 | +A __promise__ that resolves once the worker has completed processing. |
68 | 71 |
|
69 |
| -- Add default workers for loading deletion events. |
| 72 | +#### Example |
70 | 73 |
|
71 |
| -### v1.1.0 |
| 74 | +```typescript |
| 75 | +const run = async (events: AirdropEvent[]) => { |
| 76 | + for (const event of events) { |
| 77 | + const file = getWorkerPerExtractionPhase(event); |
| 78 | + await spawn<ExtractorState>({ |
| 79 | + event, |
| 80 | + initialState, |
| 81 | + workerPath: file, |
| 82 | + }); |
| 83 | + } |
| 84 | +}; |
| 85 | +``` |
72 | 86 |
|
73 |
| -- Support sync from DevRev to the external system. (Known limitations: no support for loading attachments.) |
| 87 | +### `processTask` function |
74 | 88 |
|
75 |
| -### v1.0.4 |
| 89 | +The `processTask` function retrieves the current state from the Airdrop platform and initializes a new `WorkerAdapter`. |
| 90 | +It executes the code specified in the `task` parameter, which contains the worker's functionality. |
| 91 | +If a timeout occurs, the function handles it by executing the `onTimeout` callback, ensuring the worker exits gracefully. |
| 92 | +Both functions receive an `adapter` parameter, representing the initialized `WorkerAdapter` object. |
76 | 93 |
|
77 |
| -- Fix logging from worker threads. |
78 | 94 |
|
79 |
| -### v1.0.3 |
| 95 | +#### Usage |
| 96 | +```typescript |
| 97 | +processTask({ task, onTimeout }) |
| 98 | +``` |
80 | 99 |
|
81 |
| -- Add release notes. |
| 100 | +#### Parameters |
82 | 101 |
|
83 |
| -### v1.0.2 |
| 102 | +* _task_ |
| 103 | + |
| 104 | + Required. A __function__ that defines the logic associated with the given event type. |
84 | 105 |
|
85 |
| -- Fix bugs and improve local development. |
86 |
| -- Expose `formatAxiosError` function for error handling. |
| 106 | +* _onTimeout_ |
| 107 | + |
| 108 | + Required. A __function__ managing the timeout of the lambda invocation, including saving any necessary progress at the time of timeout. |
87 | 109 |
|
88 |
| -### v1.0.1 |
| 110 | +#### Example |
89 | 111 |
|
90 |
| -- Fix bugs and improve logging. |
| 112 | +````typescript |
| 113 | +// External sync units extraction |
| 114 | +processTask({ |
| 115 | + task: async ({ adapter }) => { |
| 116 | + const httpClient = new HttpClient(adapter.event); |
91 | 117 |
|
92 |
| -### v1.0.0 |
| 118 | + const todoLists = await httpClient.getTodoLists(); |
93 | 119 |
|
94 |
| -- Enable extractions to use the full lambda runtime and gracefully handle execution context timeout. |
95 |
| -- Simplify metadata and data normalization and uploading with the repo implementation. |
96 |
| -- Provide default handling of the attachment extraction phase in the ADaaS SDK library. |
97 |
| -- Reduce file size and streamline processes with gzip compression. |
98 |
| -- Fix bugs and improve error handling. |
| 120 | + const externalSyncUnits: ExternalSyncUnit[] = todoLists.map((todoList) => normalizeTodoList(todoList)); |
99 | 121 |
|
100 |
| -### v0.0.3 |
| 122 | + await adapter.emit(ExtractorEventType.ExtractionExternalSyncUnitsDone, { |
| 123 | + external_sync_units: externalSyncUnits, |
| 124 | + }); |
| 125 | + }, |
| 126 | + onTimeout: async ({ adapter }) => { |
| 127 | + await adapter.emit(ExtractorEventType.ExtractionExternalSyncUnitsError, { |
| 128 | + error: { |
| 129 | + message: 'Failed to extract external sync units. Lambda timeout.', |
| 130 | + }, |
| 131 | + }); |
| 132 | + }, |
| 133 | +}); |
| 134 | +```` |
101 | 135 |
|
102 |
| -- Support new recipe management. |
| 136 | +### `WorkerAdapter` class |
103 | 137 |
|
104 |
| -### v0.0.2 |
| 138 | +Used to interact with Airdrop platform. |
| 139 | +Provides utilities to emit events to the Airdrop platform, update the state of the snap-in and upload artifacts (files with data) to the platform. |
105 | 140 |
|
106 |
| -- Support the State API. |
107 |
| -- Provide an HTTP client for API requests. |
108 |
| -- Create local artifact files in the local development environment. |
109 |
| -- Improve logging. |
| 141 | +### Usage |
110 | 142 |
|
111 |
| -### v0.0.1 |
| 143 | +```typescript |
| 144 | +new WorkerAdapter({ |
| 145 | + event, |
| 146 | + adapterState, |
| 147 | + options, |
| 148 | +}); |
| 149 | +``` |
112 | 150 |
|
113 |
| -- Implement a demo of the ADaaS snap-in. |
114 |
| -- Add an adapter for the ADaaS control protocol with helper functions. |
115 |
| -- Provide an uploader for uploading artifacts. |
| 151 | +#### Parameters |
116 | 152 |
|
117 |
| -# Overview |
| 153 | +* _event_ |
| 154 | + |
| 155 | + Required. An object of type __AirdropEvent__ that is received from the Airdrop platform. |
118 | 156 |
|
119 |
| -[](https://coveralls.io/github/devrev/adaas-sdk?branch=main) |
| 157 | +* _adapterState_ |
| 158 | + |
| 159 | + Required. An object of type __State__, which represents the initial state of the adapter. |
120 | 160 |
|
121 |
| -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. |
| 161 | +* _options_ |
| 162 | + |
| 163 | + Optional. An object of type __WorkerAdapterOptions__ that specifies additional configuration options for the `WorkerAdapter`. This object is passed via the `spawn` function. |
122 | 164 |
|
123 |
| -It provides features such as: |
| 165 | +#### Example |
124 | 166 |
|
125 |
| -- Type Definitions: Structured types for ADaaS control protocol |
126 |
| -- Event Management: Easily emit events for different extraction or loading phases |
127 |
| -- State Handling: Update and access state in real-time within tasks |
128 |
| -- Artifact Management: Supports batched storage of artifacts |
129 |
| -- Error & Timeout Support: Error handling and timeout management for long-running tasks |
| 167 | +```typescript |
| 168 | +const adapter = new WorkerAdapter<ConnectorState>({ |
| 169 | + event, |
| 170 | + adapterState, |
| 171 | + options, |
| 172 | +}); |
| 173 | +``` |
130 | 174 |
|
131 |
| -# Installation |
| 175 | +### `WorkerAdapter.state` property |
132 | 176 |
|
133 |
| -```bash |
134 |
| -npm install @devrev/ts-adaas |
| 177 | +Getter and setter methods for working with the adapter state. |
| 178 | + |
| 179 | +### Usage |
| 180 | + |
| 181 | +```typescript |
| 182 | +// get state |
| 183 | +const adapterState = adapter.state; |
| 184 | + |
| 185 | +// set state |
| 186 | +adapter.state = newAdapterState; |
| 187 | +``` |
| 188 | + |
| 189 | +#### Example |
| 190 | + |
| 191 | +```typescript |
| 192 | +export const initialState: ExtractorState = { |
| 193 | + users: { completed: false }, |
| 194 | + tasks: { completed: false }, |
| 195 | + attachments: { completed: false }, |
| 196 | +}; |
| 197 | + |
| 198 | +adapter.state = initialState; |
| 199 | +``` |
| 200 | + |
| 201 | +### `WorkerAdapter.initializeRepos` method |
| 202 | + |
| 203 | +Initializes a `Repo` object for each item provided. |
| 204 | + |
| 205 | +### Usage |
| 206 | + |
| 207 | +```typescript |
| 208 | +adapter.initializeRepos(repos); |
| 209 | +``` |
| 210 | + |
| 211 | +#### Parameters |
| 212 | + |
| 213 | +* _repos_ |
| 214 | + |
| 215 | + Required. An array of objects of type `RepoInterface`. |
| 216 | + |
| 217 | +#### Example |
| 218 | + |
| 219 | +This should typically be called within the function passed as a parameter to the `processTask` function in the data extraction phase. |
| 220 | + |
| 221 | +```typescript |
| 222 | +const repos = [ |
| 223 | + { |
| 224 | + itemType: 'tasks', |
| 225 | + normalize: normalizeTask, |
| 226 | + } |
| 227 | +]; |
| 228 | + |
| 229 | +adapter.initializeRepos(repos); |
| 230 | +``` |
| 231 | + |
| 232 | +### `WorkerAdapter.getRepo` method |
| 233 | + |
| 234 | +Finds a Repo from the initialized repos. |
| 235 | + |
| 236 | +### Usage |
| 237 | + |
| 238 | +```typescript |
| 239 | +adapter.getRepo(itemType); |
| 240 | +``` |
| 241 | + |
| 242 | +#### Parameters |
| 243 | + |
| 244 | +* _itemType_ |
| 245 | + |
| 246 | + Required. A __string__ that represents the itemType property for the searched repo. |
| 247 | + |
| 248 | +#### Return value |
| 249 | + |
| 250 | +An object of type __Repo__ if the repo is found, otherwise __undefined__. |
| 251 | + |
| 252 | +#### Example |
| 253 | + |
| 254 | +This should typically be called within the function passed as a parameter to the `processTask` function. |
| 255 | + |
| 256 | +```typescript |
| 257 | +// Push users to the repository designated for 'users' data. |
| 258 | +await adapter.getRepo('users')?.push(users); |
| 259 | +``` |
| 260 | + |
| 261 | +### `WorkerAdapter.emit` method |
| 262 | + |
| 263 | +Emits an event to the Airdrop platform. |
| 264 | + |
| 265 | +### Usage |
| 266 | + |
| 267 | +```typescript |
| 268 | +adapter.emit( newEventType, data ): |
| 269 | +``` |
| 270 | + |
| 271 | +#### Parameters |
| 272 | + |
| 273 | +* _newEventType_ |
| 274 | + |
| 275 | + Required. The event type to be emitted, of type __ExtractorEventType__ or __LoaderEventType__. |
| 276 | + |
| 277 | +* _data_ |
| 278 | + |
| 279 | + Optional. An object of type __EventData__ which represents the data to be sent with the event. |
| 280 | + |
| 281 | +#### Return value |
| 282 | + |
| 283 | +A __promise__, which resolves to undefined after the emit function completes its execution or rejects with an error. |
| 284 | + |
| 285 | +#### Example |
| 286 | + |
| 287 | +This should typically be called within the function passed as a parameter to the `processTask` function. |
| 288 | + |
| 289 | +```typescript |
| 290 | +// Emitting successfully finished data extraction. |
| 291 | +await adapter.emit(ExtractorEventType.ExtractionDataDone); |
| 292 | + |
| 293 | +// Emitting a delay in attachments extraction phase. |
| 294 | +await adapter.emit(ExtractorEventType.ExtractionAttachmentsDelay, { |
| 295 | + delay: 10, |
| 296 | +}); |
135 | 297 | ```
|
0 commit comments