Skip to content

Conversation

@radovanjorgic
Copy link
Collaborator

@radovanjorgic radovanjorgic commented Nov 12, 2025

Description

Migrated event type names from old E2DR to DR2E naming convention.
Added a simple function for easier translation and migration.

Connected Issues

Checklist

  • Tests added/updated and ran with npm run test OR no tests needed.
  • Ran backwards compatibility tests with npm run test:backwards-compatibility.
  • Code formatted and checked with npm run lint.
  • Tested airdrop-template linked to this PR.
  • Documentation updated and provided a link to PR / new docs OR no docs needed.

@radovanjorgic radovanjorgic requested review from a team and gasperzgonec as code owners November 12, 2025 14:21
@radovanjorgic radovanjorgic marked this pull request as draft November 12, 2025 14:21
@gasperzgonec gasperzgonec force-pushed the rado/event-renamings-poc branch 4 times, most recently from db603ae to f462b19 Compare November 18, 2025 08:56
@gasperzgonec gasperzgonec marked this pull request as ready for review November 18, 2025 08:58
@gasperzgonec gasperzgonec changed the title Event renamings with normalization functions Implement translations from E2DR to DR2E Nov 18, 2025
Copy link
Collaborator Author

@radovanjorgic radovanjorgic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update PR title to something understandable to 3P developers (old to new event types instead of E2DR to DR2E). Please verify this works on template, asana and maybe even release one beta version so other connectors can test if their connectors still work. I would be super careful with merging this.

@gasperzgonec gasperzgonec changed the title Implement translations from E2DR to DR2E Implement translations from old event types to new ones Nov 24, 2025
@gasperzgonec gasperzgonec force-pushed the rado/event-renamings-poc branch from 37917c2 to de2c3cd Compare November 24, 2025 14:17
@gasperzgonec gasperzgonec self-requested a review November 24, 2025 14:21
@gasperzgonec gasperzgonec self-assigned this Nov 25, 2025
Copy link
Collaborator Author

@radovanjorgic radovanjorgic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, few nits.

@gasperzgonec gasperzgonec force-pushed the rado/event-renamings-poc branch from ef82227 to 0fc8fe0 Compare November 27, 2025 11:12
@gasperzgonec gasperzgonec force-pushed the rado/event-renamings-poc branch from 0fc8fe0 to d307312 Compare November 27, 2025 11:13
Comment on lines 64 to 86
function getCallerDirectory(): string {
const originalPrepareStackTrace = Error.prepareStackTrace;

Error.prepareStackTrace = (_, stack) => stack;
const err = new Error();
Error.captureStackTrace(err);
const stack = err.stack as unknown as NodeJS.CallSite[];
Error.prepareStackTrace = originalPrepareStackTrace;

// Iterate through the stack to find the first file that's not part of the SDK
for (const callSite of stack) {
const filename = callSite.getFileName();
if (
filename &&
!filename.includes('@devrev/ts-adaas') &&
!filename.includes('adaas-sdk')
) {
return path.dirname(filename);
}
}
return path;

// Fallback to __dirname if we can't determine the caller
return __dirname;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have had to reimplement the automatic detection of the directory the spawn is being called from.
This works by reading the callstack and navigating up just far enough to get out of the SDK.

This might not be perfect and it could fail on some edge-cases (that I was unable to think of), but it has been tested both locally and in Lambda.

If we override the getWorker, that will be appended to the path where we called spawn, if it's not provided, the pre-defined paths will be appended to the path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I don't like this. This way of stack inspection seems pretty fragile and unreliable to me. I have a feeling it might break with bundlers, if the package name differs and so on. Also, this is pretty non-standard approach for JavaScript.

On the other side, I think there won't be many cases where users want to override those paths, so can we rather require user to pass baseDirectory in the options alongside with workerPathOverridings. What is __dirname in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replaced it with a field in spawn, that allows user to pass in the current script directory.

[EventType.UnknownEventType]: EventType.UnknownEventType,
};

const normalized = eventTypeMap[eventTypeString];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use translated instead normalized all over the code

isLocalDevelopment?: boolean;
timeout?: number;
batchSize?: number;
workerPathOverrides?: Partial<Record<EventType, string>>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still use Partial here and don't have separate interface for this?

export interface GetWorkerPathInterface {
event: AirdropEvent;
connectorWorkerPath?: string | null;
callerDir?: string | null;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document this a bit through JSDoc please, what is callerDir?

Comment on lines 64 to 86
function getCallerDirectory(): string {
const originalPrepareStackTrace = Error.prepareStackTrace;

Error.prepareStackTrace = (_, stack) => stack;
const err = new Error();
Error.captureStackTrace(err);
const stack = err.stack as unknown as NodeJS.CallSite[];
Error.prepareStackTrace = originalPrepareStackTrace;

// Iterate through the stack to find the first file that's not part of the SDK
for (const callSite of stack) {
const filename = callSite.getFileName();
if (
filename &&
!filename.includes('@devrev/ts-adaas') &&
!filename.includes('adaas-sdk')
) {
return path.dirname(filename);
}
}
return path;

// Fallback to __dirname if we can't determine the caller
return __dirname;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I don't like this. This way of stack inspection seems pretty fragile and unreliable to me. I have a feeling it might break with bundlers, if the package name differs and so on. Also, this is pretty non-standard approach for JavaScript.

On the other side, I think there won't be many cases where users want to override those paths, so can we rather require user to pass baseDirectory in the options alongside with workerPathOverridings. What is __dirname in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants