Skip to content

Add local flag, headers when emitting, bugfixes #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Release Notes

### v1.2.3

- Add `local` flag to use for local development of the ADaaS snap-ins.
- Send library version, snap-in version and snap-in slug in headers while emitting.
- Make `actor_id` field optional for `SsorAttachment` interface.
- Fix bugs related to event handling, error logging.

### v1.2.2

- Add library version as a part of control protocol.
Expand Down
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devrev/ts-adaas",
"version": "1.2.2",
"version": "1.2.3",
"description": "DevRev ADaaS (AirDrop-as-a-Service) Typescript SDK.",
"type": "commonjs",
"main": "./dist/index.js",
Expand All @@ -26,6 +26,7 @@
"@types/jest": "^29.5.12",
"@types/lambda-log": "^3.0.3",
"@types/node": "20.16.11",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "^8.57.0",
Expand All @@ -42,7 +43,8 @@
"form-data": "^4.0.1",
"js-jsonl": "^1.1.1",
"lambda-log": "^3.1.0",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"yargs": "^17.7.2"
},
"files": [
"dist"
Expand Down
3 changes: 3 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventType } from '../types/extraction';
import { getLibraryVersion } from './helpers';

export const STATELESS_EVENT_TYPES = [
EventType.ExtractionExternalSyncUnitsStart,
Expand Down Expand Up @@ -40,3 +41,5 @@ export const AIRDROP_DEFAULT_ITEM_TYPES = {
ATTACHMENTS: 'attachments',
SSOR_ATTACHMENT: 'ssor_attachment',
};

export const LIBRARY_VERSION = getLibraryVersion();
7 changes: 5 additions & 2 deletions src/common/control-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
LoaderEvent,
} from '../types/extraction';
import { LoaderEventType } from '../types/loading';
import { getLibraryVersion } from './helpers';
import { LIBRARY_VERSION } from './constants';

export interface EmitInterface {
event: AirdropEvent;
Expand All @@ -28,7 +28,7 @@ export const emit = async ({
...data,
},
worker_metadata: {
adaas_library_version: getLibraryVersion(),
adaas_library_version: LIBRARY_VERSION,
},
};

Expand All @@ -42,6 +42,9 @@ export const emit = async ({
Accept: 'application/json, text/plain, */*',
Authorization: event.context.secrets.service_account_token,
'Content-Type': 'application/json',
'X-DevRev-Client-Platform': event.payload.event_context.snap_in_slug,
'X-DevRev-Client-Id': event.payload.event_context.snap_in_version_id,
'X-DevRev-Client-Version': LIBRARY_VERSION,
},
}
);
Expand Down
13 changes: 12 additions & 1 deletion src/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export function getTimeoutErrorEventType(eventType: EventType): {
eventType: LoaderEventType.LoaderStateDeletionError,
};

case EventType.StartLoadingAttachments:
case EventType.ContinueLoadingAttachments:
return {
eventType: LoaderEventType.AttachmentLoadingError,
};

case EventType.StartDeletingLoaderAttachmentState:
return {
eventType: LoaderEventType.LoaderAttachmentStateDeletionError,
Expand Down Expand Up @@ -172,9 +178,14 @@ export function getCircularReplacer() {
// read adaas library version from package.json
export function getLibraryVersion() {
try {
return JSON.parse(
const version = JSON.parse(
readFileSync(path.resolve(__dirname, '../../package.json'), 'utf8')
)?.version;

if (version) {
return version;
}
return '';
} catch (error) {
console.error(
'Error reading adaas library version from package.json',
Expand Down
2 changes: 1 addition & 1 deletion src/repo/repo.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export interface NormalizedAttachment {
url: string;
id: string;
file_name: string;
author_id: string;
parent_id: string;
author_id?: string;
grand_parent_id?: number;
}

Expand Down
1 change: 1 addition & 0 deletions src/tests/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function createEvent({
mode: 'test_mode',
request_id: 'test_request_id',
snap_in_slug: 'test_snap_in_slug',
snap_in_version_id: 'test_snap_in_version_id',
sync_run: 'test_sync_run',
sync_run_id: 'test_sync_run_id',
sync_tier: 'test_sync_tier',
Expand Down
1 change: 1 addition & 0 deletions src/types/extraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export interface EventContext {
mode: string;
request_id: string;
snap_in_slug: string;
snap_in_version_id: string;
sync_run: string;
sync_run_id: string;
sync_tier: string;
Expand Down
1 change: 0 additions & 1 deletion src/types/workers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Worker } from 'worker_threads';
import { MessagePort } from 'node:worker_threads';

import { State } from '../state/state';
import { WorkerAdapter } from '../workers/worker-adapter';
Expand Down
2 changes: 1 addition & 1 deletion src/uploader/uploader.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface SsorAttachment {
parent_id: {
external: string;
};
actor_id: {
actor_id?: {
external: string;
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/workers/create-worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isMainThread, Worker } from 'node:worker_threads';

import { WorkerData, WorkerEvent } from '../types/workers';
import { Logger, serializeError } from '../logger/logger';
import { Logger } from '../logger/logger';

async function createWorker<ConnectorState>(
workerData: WorkerData<ConnectorState>
Expand All @@ -19,7 +19,7 @@ async function createWorker<ConnectorState>(
} as WorkerOptions);

worker.on(WorkerEvent.WorkerError, (error) => {
logger.error('Worker error', serializeError(error));
logger.error('Worker error', error);
reject();
});
worker.on(WorkerEvent.WorkerOnline, () => {
Expand Down
18 changes: 18 additions & 0 deletions src/workers/spawn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import axios from 'axios';
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs';

import {
AirdropEvent,
EventType,
Expand Down Expand Up @@ -91,6 +94,21 @@ export async function spawn<ConnectorState>({
connectorWorkerPath: workerPath,
});

if (options?.isLocalDevelopment) {
logger.warn(
'WARN: isLocalDevelopment is deprecated. Please use the -- local flag instead.'
);
}

// read the command line arguments to check if the local flag is passed
const argv = await yargs(hideBin(process.argv)).argv;
if (argv._.includes('local')) {
options = {
...(options || {}),
isLocalDevelopment: true,
};
}

if (script) {
try {
const worker = await createWorker<ConnectorState>({
Expand Down
9 changes: 6 additions & 3 deletions src/workers/worker-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,14 @@ export class WorkerAdapter<ConnectorState> {
parent_id: {
external: attachment.parent_id,
},
actor_id: {
external: attachment.author_id,
},
};

if (attachment.author_id) {
ssorAttachment.actor_id = {
external: attachment.author_id,
};
}

await this.getRepo('ssor_attachment')?.push([ssorAttachment]);
}
return;
Expand Down