Skip to content

Commit 963bb6b

Browse files
Attachments extraction fixes, bump to the latest SDK version (#24)
https://app.devrev.ai/devrev/works/ISS-151039
1 parent 4e7e216 commit 963bb6b

File tree

8 files changed

+83
-55
lines changed

8 files changed

+83
-55
lines changed

.github/templates/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ keyring_types:
2929
method: GET
3030

3131
imports:
32-
- slug: %PROJECT_NAME%-extractor
32+
- slug: %PROJECT_NAME%
3333
display_name: %PRETTY_NAME%
3434
description: %PRETTY_NAME%
3535
extractor_function: extraction

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ADaaS Template
22

3-
This GitHub repository provides a template with example code to implement an Airdrop as a Service (ADaaS) Snap-in .
3+
This GitHub repository provides a template with example code to implement an Airdrop as a Service (ADaaS) Snap-in.
44

55
## Prerequisites
66

@@ -13,7 +13,7 @@ This GitHub repository provides a template with example code to implement an Air
1313
1\. Clone Repository:
1414

1515
- Either clone this repository or create a new repository from it by clicking the "Use this template" button above.
16-
- Set the desired repository name for your own copy (e.g., `airdrop-<external system>-snap-in`).
16+
- The repository name must start with `airdrop-` (e.g., `airdrop-<external system>-snap-in`).
1717

1818
2\. Open the project in your IDE and set up project environment variables, by following these steps:
1919

code/package-lock.json

Lines changed: 45 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"yargs": "^17.6.2"
5656
},
5757
"dependencies": {
58-
"@devrev/ts-adaas": "^1.1.6",
58+
"@devrev/ts-adaas": "1.2.1",
5959
"axios": "^1.7.7",
6060
"dotenv": "^16.0.3",
6161
"js-jsonl": "^1.1.1",

code/src/functions/external-system/http-client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
22

3-
import { AirdropEvent, ExternalSystemItemLoadingParams, ExternalSystemItemLoadingResponse } from '@devrev/ts-adaas';
3+
import {
4+
AirdropEvent,
5+
ExternalSystemItem,
6+
ExternalSystemItemLoadingParams,
7+
ExternalSystemItemLoadingResponse,
8+
} from '@devrev/ts-adaas';
49

510
export class HttpClient {
611
private apiEndpoint: string;
@@ -19,15 +24,15 @@ export class HttpClient {
1924
item,
2025
mappers,
2126
event,
22-
}: ExternalSystemItemLoadingParams): Promise<ExternalSystemItemLoadingResponse> {
27+
}: ExternalSystemItemLoadingParams<ExternalSystemItem>): Promise<ExternalSystemItemLoadingResponse> {
2328
return { error: 'Could not create an issue in external system.' };
2429
}
2530

2631
async updateIssue({
2732
item,
2833
mappers,
2934
event,
30-
}: ExternalSystemItemLoadingParams): Promise<ExternalSystemItemLoadingResponse> {
35+
}: ExternalSystemItemLoadingParams<ExternalSystemItem>): Promise<ExternalSystemItemLoadingResponse> {
3136
return { error: 'Could not update an issue in external system.' };
3237
}
3338
}

code/src/functions/extraction/workers/attachments-extraction.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
axios,
3+
axiosClient,
34
ExternalSystemAttachmentStreamingParams,
45
ExternalSystemAttachmentStreamingResponse,
56
ExtractorEventType,
@@ -9,22 +10,24 @@ import {
910

1011
const getAttachmentStream = async ({
1112
item,
12-
event,
1313
}: ExternalSystemAttachmentStreamingParams): Promise<ExternalSystemAttachmentStreamingResponse> => {
14-
const { id, url, inline } = item;
14+
const { id, url } = item;
1515

1616
try {
17-
const fileStreamResponse = await axios.get(url, {
17+
const fileStreamResponse = await axiosClient.get(url, {
1818
responseType: 'stream',
1919
});
2020

2121
return { httpStream: fileStreamResponse };
2222
} catch (error) {
2323
if (axios.isAxiosError(error)) {
24-
console.error('Error while fetching attachment from URL.', serializeAxiosError(error));
24+
console.warn(`Error while fetching attachment ${id} from URL.`, serializeAxiosError(error));
25+
console.warn('Failed attachment metadata', item);
2526
} else {
26-
console.error('Error while fetching attachment from URL.', error);
27+
console.warn(`Error while fetching attachment ${id} from URL.`, error);
28+
console.warn('Failed attachment metadata', item);
2729
}
30+
2831
return {
2932
error: {
3033
message: 'Error while fetching attachment ' + id + ' from URL.',
@@ -35,20 +38,24 @@ const getAttachmentStream = async ({
3538

3639
processTask({
3740
task: async ({ adapter }) => {
38-
const { error, delay } = await adapter.streamAttachments({
39-
stream: getAttachmentStream,
40-
});
41-
42-
if (delay) {
43-
await adapter.emit(ExtractorEventType.ExtractionAttachmentsDelay, {
44-
delay,
41+
try {
42+
const response = await adapter.streamAttachments({
43+
stream: getAttachmentStream,
4544
});
46-
} else if (error) {
47-
await adapter.emit(ExtractorEventType.ExtractionAttachmentsError, {
48-
error,
49-
});
50-
} else {
51-
await adapter.emit(ExtractorEventType.ExtractionAttachmentsDone);
45+
46+
if (response?.delay) {
47+
await adapter.emit(ExtractorEventType.ExtractionAttachmentsDelay, {
48+
delay: response.delay,
49+
});
50+
} else if (response?.error) {
51+
await adapter.emit(ExtractorEventType.ExtractionAttachmentsError, {
52+
error: response.error,
53+
});
54+
} else {
55+
await adapter.emit(ExtractorEventType.ExtractionAttachmentsDone);
56+
}
57+
} catch (error) {
58+
console.error('An error occured while processing a task.', error);
5259
}
5360
},
5461
onTimeout: async ({ adapter }) => {

code/src/functions/loading/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function getWorkerPerLoadingPhase(event: AirdropEvent) {
77
switch (event.payload.event_type) {
88
case EventType.StartLoadingData:
99
case EventType.ContinueLoadingData:
10-
path = __dirname + '/workers/data-loading';
10+
path = __dirname + '/workers/load-data';
1111
break;
1212
}
1313
return path;

0 commit comments

Comments
 (0)