Skip to content

Commit b254267

Browse files
Fix for attachments streaming. Expose getter to end developer. Increase delayFactor of exponential backoff mechanism. (#18)
1 parent bfd79d6 commit b254267

File tree

11 files changed

+258
-214
lines changed

11 files changed

+258
-214
lines changed

README.md

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,77 @@
22

33
## Release Notes
44

5+
### v1.1.5
6+
7+
- Increase `delayFactor` and number of retries for the exponential backoff retry mechanism for HTTP requests.
8+
- Provide an inject function for streaming attachments.
9+
- Fix the attachments streaming bug.
10+
511
### v1.1.4
612

7-
- Provide log line and stack trace on runtime worker errors.
13+
- Provide log lines and stack traces for runtime worker errors.
814

915
### v1.1.3
1016

11-
- Exported `axios` and `axiosClient` with exponential backoff retry mechanism for HTTP requests and omitting Authorization headers from Axios errors.
12-
- Resolved issues with circular structure logging.
13-
- Fixed attachments metadata normalization bug.
14-
- Improved repository logging.
17+
- Export `axios` and `axiosClient` with the exponential backoff retry mechanism for HTTP requests and omit Authorization headers from Axios errors.
18+
- Resolve circular structure logging issues.
19+
- Fix the attachments metadata normalization bug.
20+
- Improve repository logging.
1521

16-
#### v1.1.2
22+
### v1.1.2
1723

18-
- Unified incoming and outgoing event context.
19-
- Added `dev_oid` to logger tags.
24+
- Unify incoming and outgoing event context.
25+
- Add `dev_oid` to logger tags.
2026

21-
#### v1.1.1
27+
### v1.1.1
2228

23-
- Added default workers for loading deletion events.
29+
- Add default workers for loading deletion events.
2430

25-
#### v1.1.0
31+
### v1.1.0
2632

27-
- Support for sync from DevRev to external system. Known limitations: no support for loading attachments.
33+
- Support sync from DevRev to the external system. (Known limitations: no support for loading attachments.)
2834

29-
#### v1.0.4
35+
### v1.0.4
3036

3137
- Fix logging from worker threads.
3238

33-
#### v1.0.3
39+
### v1.0.3
3440

35-
- Added Release notes.
41+
- Add release notes.
3642

37-
#### v1.0.2
43+
### v1.0.2
3844

39-
- Bug fixes and improvements in local development.
45+
- Fix bugs and improve local development.
4046
- Expose `formatAxiosError` function for error handling.
4147

42-
#### v1.0.1
48+
### v1.0.1
4349

44-
- Bug fixes and improvements in logging.
50+
- Fix bugs and improve logging.
4551

46-
#### v1.0.0
52+
### v1.0.0
4753

48-
- Allow extractions to use full lambda runtime and gracefully handle execution context timeout.
49-
- Simplified metadata and data normalization and uploading with repo implementation.
50-
- Default handling of attachment extraction phase in ADaaS SDK library.
51-
- Reduced file size, streamlined process by gzip compression.
52-
- Bug fixes and improvements in error handling.
54+
- Enable extractions to use the full lambda runtime and gracefully handle execution context timeout.
55+
- Simplify metadata and data normalization and uploading with the repo implementation.
56+
- Provide default handling of the attachment extraction phase in the ADaaS SDK library.
57+
- Reduce file size and streamline processes with gzip compression.
58+
- Fix bugs and improve error handling.
5359

54-
#### v0.0.3
60+
### v0.0.3
5561

56-
- Support for new recipe management
62+
- Support new recipe management.
5763

58-
#### v0.0.2
64+
### v0.0.2
5965

60-
- Support for the State API
61-
- HTTP client for API requests
62-
- Local development environment creates local artifact files
63-
- Improvements in logging
66+
- Support the State API.
67+
- Provide an HTTP client for API requests.
68+
- Create local artifact files in the local development environment.
69+
- Improve logging.
6470

65-
#### v0.0.1
71+
### v0.0.1
6672

67-
- Demo implementation of ADaaS snap-in
68-
- Adapter for ADaaS control protocol with helper functions
69-
- Uploader for uploading artifacts
73+
- Implement a demo of the ADaaS snap-in.
74+
- Add an adapter for the ADaaS control protocol with helper functions.
75+
- Provide an uploader for uploading artifacts.
7076

7177
# Overview
7278

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devrev/ts-adaas",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/http/axios-client.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import axiosRetry from 'axios-retry';
33

44
const axiosClient = axios.create();
55

6-
// Exponential backoff algorithm: Retry 3 times and there will be a delay of more than 1 * no. of retries second + random number of milliseconds between each retry.
76
axiosRetry(axiosClient, {
8-
retries: 3,
7+
retries: 5,
98
retryDelay: (retryCount, error) => {
10-
console.log(`Retry attempt: ${retryCount} of ${error.config?.url}.`);
11-
return axiosRetry.exponentialDelay(retryCount, error, 1000);
9+
console.warn(
10+
'Retry attempt: ' + retryCount + 'to url: ' + error.config?.url + '.'
11+
);
12+
13+
// Exponential backoff algorithm: 1 * 2 ^ retryCount * 5000ms
14+
return axiosRetry.exponentialDelay(retryCount, error, 5000);
1215
},
1316
retryCondition: (error: AxiosError) => {
1417
if (

src/repo/repo.interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface NormalizedAttachment {
4141
file_name: string;
4242
author_id: string;
4343
parent_id: string;
44+
inline?: boolean;
4445
}
4546

4647
/**

src/state/state.interfaces.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export interface SdkState {
77
lastSuccessfulSyncStarted?: string;
88
toDevRev?: ToDevRev;
99
fromDevRev?: FromDevRev;
10-
};
11-
10+
}
1211

1312
/**
1413
* AdapterState is an interface that defines the structure of the adapter state that is used by the external extractor. It extends the connector state with additional fields: lastSyncStarted, lastSuccessfulSyncStarted, and attachmentsMetadata.

src/types/extraction.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { Artifact } from '../uploader/uploader.interfaces';
44

55
import { ErrorRecord } from './common';
66

7-
import { DonV2, LoaderReport } from './loading';
7+
import { DonV2, LoaderReport, RateLimited } from './loading';
8+
import { NormalizedAttachment } from 'repo/repo.interfaces';
9+
import { AxiosResponse } from 'axios';
810

911
/**
1012
* EventType is an enum that defines the different types of events that can be sent to the external extractor from ADaaS.
@@ -244,3 +246,25 @@ export interface LoaderEvent {
244246
event_context: EventContext;
245247
event_data?: EventData;
246248
}
249+
250+
export type ExternalSystemAttachmentStreamingFunction = ({
251+
item,
252+
event,
253+
}: ExternalSystemAttachmentStreamingParams) => Promise<ExternalSystemAttachmentStreamingResponse>;
254+
255+
export interface ExternalSystemAttachmentStreamingParams {
256+
item: NormalizedAttachment;
257+
event: AirdropEvent;
258+
}
259+
260+
export interface ExternalSystemAttachmentStreamingResponse {
261+
httpStream?: AxiosResponse;
262+
error?: ErrorRecord;
263+
delay?: number;
264+
}
265+
266+
export interface StreamAttachmentsResponse {
267+
error?: ErrorRecord;
268+
report?: LoaderReport;
269+
rateLimit?: RateLimited;
270+
}

src/types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export {
2222
AirdropMessage,
2323
ExtractorEvent,
2424
SyncMode,
25+
ExternalSystemAttachmentStreamingParams,
26+
ExternalSystemAttachmentStreamingResponse,
27+
ExternalSystemAttachmentStreamingFunction,
2528
} from './extraction';
2629

2730
// Loading

0 commit comments

Comments
 (0)