You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Adapter for ADaaS control protocol with helper functions
26
28
- Uploader for uploading artifacts
27
29
28
-
## Usage
30
+
#Overview
29
31
30
-
Create a new ADaaS adapter on each ADaaS snap-in invocation:
32
+
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.
31
33
32
-
```javascript
33
-
constadapter=newAdapter(event: AirdropEvent);
34
-
```
34
+
## Features
35
35
36
-
Adapter class provides:
36
+
- Type Definitions: Structured types for ADaaS control protocol
37
+
- Event Management: Easily emit events for different extraction phases
38
+
- State Handling: Update and access state in real-time within tasks
39
+
- Artifact Management: Supports batched storage of artifacts (2000 items per batch)
40
+
- Error & Timeout Support: Error handling and timeout management for long-running tasks
37
41
38
-
- helper function to emit response,
39
-
- automatic emit event if ADaaS snap-in invocation runs out of time,
40
-
- setter for updating ADaaS snap-in state and adding artifacts to the return ADaaS message.
42
+
# Installation
41
43
42
-
### Phases of Airdrop Extraction
44
+
```bash
45
+
npm install @devrev/ts-adaas
46
+
```
43
47
44
-
Each ADaaS snap-in must handle all the phases of ADaaS extraction.
48
+
# Usage
45
49
46
-
ADaaS library provides type definitions to ensure ADaaS snap-ins are compatible with ADaaS control protocol.
50
+
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.
47
51
48
-
```javascript
49
-
asyncrun() {
50
-
switch (this.event.payload.event_type) {
51
-
caseEventType.ExtractionExternalSyncUnitsStart: {
52
+
### ADaaS Snap-in Invocation
52
53
53
-
// extract available External Sync Units (projects, organizations, ...)
54
+
Each ADaaS snap-in must handle all the phases of ADaaS extraction. In a Snap-in, you typically define a `run` function that iterates over events and invokes workers per extraction phase.
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.
Create a new Uploader class for uploading artifacts:
223
+
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.
145
224
146
-
```javascript
147
-
constupload=newUploader(
148
-
event.execution_metadata.devrev_endpoint,
149
-
event.context.secrets.service_account_token
150
-
);
151
-
```
225
+
The Snap-in should provide attachment metadata following the `NormalizedAttachment` interface:
152
226
153
-
Files with extracted domain objects must be in JSONL (JSON Lines) format. Data files should contain 2000 - 5000 records each.
Each uploaded file must be attached to ADaaS adapter as soon as it is uploaded to ensure it is included in the ADaaS response message in case of a lambda timeout.
237
+
## Artifact Uploading and State Management
170
238
171
-
## Updating ADaaS snap-in state
239
+
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.
172
240
173
-
ADaaS snap-ins keep their own state between sync runs, between the states of a particular sync run and between invocations within a particular state.
241
+
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.
174
242
175
-
By managing its own state, the ADaaS snap-in keeps track of the process of extraction (what items have already been extracted and where to continue), the times of the last successful sync run and keeps record of progress of the extraction.
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.
0 commit comments