Skip to content

Commit 37309f5

Browse files
Add local flag, headers when emitting, bugfixes (#27)
1 parent 5c63d73 commit 37309f5

14 files changed

+66
-16
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Release Notes
44

5+
### v1.2.3
6+
7+
- Add `local` flag to use for local development of the ADaaS snap-ins.
8+
- Send library version, snap-in version and snap-in slug in headers while emitting.
9+
- Make `actor_id` field optional for `SsorAttachment` interface.
10+
- Fix bugs related to event handling, error logging.
11+
512
### v1.2.2
613

714
- Add library version as a part of control protocol.

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devrev/ts-adaas",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "DevRev ADaaS (AirDrop-as-a-Service) Typescript SDK.",
55
"type": "commonjs",
66
"main": "./dist/index.js",
@@ -26,6 +26,7 @@
2626
"@types/jest": "^29.5.12",
2727
"@types/lambda-log": "^3.0.3",
2828
"@types/node": "20.16.11",
29+
"@types/yargs": "^17.0.33",
2930
"@typescript-eslint/eslint-plugin": "^7.12.0",
3031
"@typescript-eslint/parser": "^7.12.0",
3132
"eslint": "^8.57.0",
@@ -42,7 +43,8 @@
4243
"form-data": "^4.0.1",
4344
"js-jsonl": "^1.1.1",
4445
"lambda-log": "^3.1.0",
45-
"ts-node": "^10.9.2"
46+
"ts-node": "^10.9.2",
47+
"yargs": "^17.7.2"
4648
},
4749
"files": [
4850
"dist"

src/common/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EventType } from '../types/extraction';
2+
import { getLibraryVersion } from './helpers';
23

34
export const STATELESS_EVENT_TYPES = [
45
EventType.ExtractionExternalSyncUnitsStart,
@@ -40,3 +41,5 @@ export const AIRDROP_DEFAULT_ITEM_TYPES = {
4041
ATTACHMENTS: 'attachments',
4142
SSOR_ATTACHMENT: 'ssor_attachment',
4243
};
44+
45+
export const LIBRARY_VERSION = getLibraryVersion();

src/common/control-protocol.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
LoaderEvent,
99
} from '../types/extraction';
1010
import { LoaderEventType } from '../types/loading';
11-
import { getLibraryVersion } from './helpers';
11+
import { LIBRARY_VERSION } from './constants';
1212

1313
export interface EmitInterface {
1414
event: AirdropEvent;
@@ -28,7 +28,7 @@ export const emit = async ({
2828
...data,
2929
},
3030
worker_metadata: {
31-
adaas_library_version: getLibraryVersion(),
31+
adaas_library_version: LIBRARY_VERSION,
3232
},
3333
};
3434

@@ -42,6 +42,9 @@ export const emit = async ({
4242
Accept: 'application/json, text/plain, */*',
4343
Authorization: event.context.secrets.service_account_token,
4444
'Content-Type': 'application/json',
45+
'X-DevRev-Client-Platform': event.payload.event_context.snap_in_slug,
46+
'X-DevRev-Client-Id': event.payload.event_context.snap_in_version_id,
47+
'X-DevRev-Client-Version': LIBRARY_VERSION,
4548
},
4649
}
4750
);

src/common/helpers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export function getTimeoutErrorEventType(eventType: EventType): {
6060
eventType: LoaderEventType.LoaderStateDeletionError,
6161
};
6262

63+
case EventType.StartLoadingAttachments:
64+
case EventType.ContinueLoadingAttachments:
65+
return {
66+
eventType: LoaderEventType.AttachmentLoadingError,
67+
};
68+
6369
case EventType.StartDeletingLoaderAttachmentState:
6470
return {
6571
eventType: LoaderEventType.LoaderAttachmentStateDeletionError,
@@ -172,9 +178,14 @@ export function getCircularReplacer() {
172178
// read adaas library version from package.json
173179
export function getLibraryVersion() {
174180
try {
175-
return JSON.parse(
181+
const version = JSON.parse(
176182
readFileSync(path.resolve(__dirname, '../../package.json'), 'utf8')
177183
)?.version;
184+
185+
if (version) {
186+
return version;
187+
}
188+
return '';
178189
} catch (error) {
179190
console.error(
180191
'Error reading adaas library version from package.json',

src/repo/repo.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export interface NormalizedAttachment {
3939
url: string;
4040
id: string;
4141
file_name: string;
42-
author_id: string;
4342
parent_id: string;
43+
author_id?: string;
4444
grand_parent_id?: number;
4545
}
4646

src/tests/test-helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function createEvent({
4545
mode: 'test_mode',
4646
request_id: 'test_request_id',
4747
snap_in_slug: 'test_snap_in_slug',
48+
snap_in_version_id: 'test_snap_in_version_id',
4849
sync_run: 'test_sync_run',
4950
sync_run_id: 'test_sync_run_id',
5051
sync_tier: 'test_sync_tier',

src/types/extraction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export interface EventContext {
148148
mode: string;
149149
request_id: string;
150150
snap_in_slug: string;
151+
snap_in_version_id: string;
151152
sync_run: string;
152153
sync_run_id: string;
153154
sync_tier: string;

src/types/workers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Worker } from 'worker_threads';
2-
import { MessagePort } from 'node:worker_threads';
32

43
import { State } from '../state/state';
54
import { WorkerAdapter } from '../workers/worker-adapter';

src/uploader/uploader.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface SsorAttachment {
6565
parent_id: {
6666
external: string;
6767
};
68-
actor_id: {
68+
actor_id?: {
6969
external: string;
7070
};
7171
}

src/workers/create-worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isMainThread, Worker } from 'node:worker_threads';
22

33
import { WorkerData, WorkerEvent } from '../types/workers';
4-
import { Logger, serializeError } from '../logger/logger';
4+
import { Logger } from '../logger/logger';
55

66
async function createWorker<ConnectorState>(
77
workerData: WorkerData<ConnectorState>
@@ -19,7 +19,7 @@ async function createWorker<ConnectorState>(
1919
} as WorkerOptions);
2020

2121
worker.on(WorkerEvent.WorkerError, (error) => {
22-
logger.error('Worker error', serializeError(error));
22+
logger.error('Worker error', error);
2323
reject();
2424
});
2525
worker.on(WorkerEvent.WorkerOnline, () => {

src/workers/spawn.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import axios from 'axios';
2+
import { hideBin } from 'yargs/helpers';
3+
import yargs from 'yargs';
4+
25
import {
36
AirdropEvent,
47
EventType,
@@ -91,6 +94,21 @@ export async function spawn<ConnectorState>({
9194
connectorWorkerPath: workerPath,
9295
});
9396

97+
if (options?.isLocalDevelopment) {
98+
logger.warn(
99+
'WARN: isLocalDevelopment is deprecated. Please use the -- local flag instead.'
100+
);
101+
}
102+
103+
// read the command line arguments to check if the local flag is passed
104+
const argv = await yargs(hideBin(process.argv)).argv;
105+
if (argv._.includes('local')) {
106+
options = {
107+
...(options || {}),
108+
isLocalDevelopment: true,
109+
};
110+
}
111+
94112
if (script) {
95113
try {
96114
const worker = await createWorker<ConnectorState>({

src/workers/worker-adapter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,14 @@ export class WorkerAdapter<ConnectorState> {
727727
parent_id: {
728728
external: attachment.parent_id,
729729
},
730-
actor_id: {
731-
external: attachment.author_id,
732-
},
733730
};
734731

732+
if (attachment.author_id) {
733+
ssorAttachment.actor_id = {
734+
external: attachment.author_id,
735+
};
736+
}
737+
735738
await this.getRepo('ssor_attachment')?.push([ssorAttachment]);
736739
}
737740
return;

0 commit comments

Comments
 (0)