-
Notifications
You must be signed in to change notification settings - Fork 1
Rate limit and attachment support #24
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
patricijabrecko
merged 4 commits into
devrev:main
from
Codeplain-ai:feat/rate-limit-and-attachment-support
Sep 23, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * Type definitions for DevRev function inputs and related types | ||
| */ | ||
|
|
||
| export type Context = { | ||
| // ID of the dev org for which the function is being invoked. | ||
| dev_oid: string; | ||
| // ID of the automation/command/snap-kit Action/Event Source for which the function is being invoked. | ||
| source_id: string; | ||
| // ID of the snap-in as part of which the function is being invoked. | ||
| snap_in_id: string; | ||
| // ID of the snap-in Version as part of which the function is being invoked. | ||
| snap_in_version_id: string; | ||
| // ID of the service account. | ||
| service_account_id: string; | ||
| // This secrets map would contain some secrets which platform would provide to the snap-in. | ||
| // `service_account_token`: This is the token of the service account which belongs to this snap-in. This can be used to make API calls to DevRev. | ||
| // `actor_session_token`: For commands, and snap-kits, where the user is performing some action, this is the token of the user who is performing the action. | ||
| secrets: Record<string, string>; | ||
| }; | ||
|
|
||
| export type ExecutionMetadata = { | ||
| // A unique id for the function invocation. Can be used to filter logs for a particular invocation. | ||
| request_id: string; | ||
| // Function name as defined in the manifest being invoked. | ||
| function_name: string; | ||
| // Type of event that triggered the function invocation as defined in manifest. | ||
| event_type: string; | ||
| // DevRev endpoint to which the function can make API calls. | ||
| // Example : "https://api.devrev.ai/" | ||
| devrev_endpoint: string; | ||
| }; | ||
|
|
||
| export type InputData = { | ||
| // Map of organization inputs and their corresponding values stored in snap-in. | ||
| // The values are passed as string and typing need to be handled by the function | ||
| global_values: Record<string, string>; | ||
| // Map of event sources and their corresponding ids stored in snap-in. | ||
| // These could be used to schedule events on a schedule based event source. | ||
| event_sources: Record<string, string>; | ||
| }; | ||
|
|
||
| // Event sent to our app. | ||
| export type FunctionInput = { | ||
| // Actual payload of the event. | ||
| payload: Record<string, any>; | ||
| // Context of the function invocation. | ||
| context: Context; | ||
| // Metadata of the function invocation. | ||
| execution_metadata: ExecutionMetadata; | ||
| input_data: InputData; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { AirdropEvent, AirdropMessage } from '@devrev/ts-adaas'; | ||
| import { FunctionInput } from './types'; | ||
|
|
||
| export function convertToAirdropEvent(fi: FunctionInput): AirdropEvent { | ||
| // Create a properly structured AirdropMessage | ||
| const airdropMessage: AirdropMessage = { | ||
| connection_data: fi.payload.connection_data, | ||
| event_context: { | ||
| ...fi.payload.event_context, | ||
| ...fi.context, | ||
| request_id: fi.execution_metadata?.request_id, | ||
| }, | ||
| event_type: fi.payload.event_type, | ||
| event_data: fi.payload.event_data || {}, | ||
| }; | ||
|
|
||
| return { | ||
| context: { | ||
| ...fi.context, | ||
| secrets: { | ||
| service_account_token: fi.context.secrets?.service_account_token || '', | ||
| ...fi.context.secrets, | ||
| }, | ||
| }, | ||
| payload: airdropMessage, | ||
| execution_metadata: fi.execution_metadata, | ||
| input_data: fi.input_data, | ||
| }; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Attachment normalization | ||
|
|
||
| Attachments have a special way of normalization compared to other resources. Function for normalizing "attachments" should return an object "NormalizedAttachment" instead of "NormalizedItem". | ||
|
|
||
| ## NormalizedAttachment | ||
|
|
||
| NormalizedAttachment represents the standardized structure of an attachment after normalization in the Airdrop platform. This interface defines the essential properties needed to identify and link attachments to their parent items. | ||
|
|
||
| ### Properties | ||
|
|
||
| - _url_ | ||
|
|
||
| Required. A **string** representing the URL where the attachment can be accessed. | ||
|
|
||
| - _id_ | ||
|
|
||
| Required. A **string** that uniquely identifies the normalized attachment. | ||
|
|
||
| - _file_name_ | ||
|
|
||
| Required. A **string** representing the name of the attachment file. | ||
|
|
||
| - _parent_id_ | ||
|
|
||
| Required. A **string** identifying the parent item this attachment belongs to. | ||
|
|
||
| - _author_id_ | ||
|
|
||
| Optional. A **string** identifying the author or creator of the attachment. | ||
|
|
||
| - _grand_parent_id_ | ||
|
|
||
| Optional. A **number** identifying a higher-level parent entity, if applicable. | ||
|
|
||
| ### Example | ||
|
|
||
| ```typescript | ||
| export function normalizeAttachment(item: any): NormalizedAttachment { | ||
| return { | ||
| id: item.gid, | ||
| url: item.download_url, | ||
| file_name: item.name, | ||
| parent_id: item.parent_id, | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| ### Further remarks | ||
|
|
||
| Note: | ||
|
|
||
| - In the example above, parent_id should be the ID of the resource that the attachment belongs to. For example, if we're normalizing an attachment for a task, parent_id should be the ID of the task. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Data Extraction Rules for Emitting Events | ||
|
|
||
| ## Input event: `EXTRACTION_DATA_START` or `EXTRACTION_DATA_CONTINUE` | ||
|
|
||
| Here are the rules when `EXTRACTION_DATA_START` or `EXTRACTION_DATA_CONTINUE` event is received by the snap-in: | ||
|
|
||
| - If there's a timeout ("onTimeout" method in "spawn" method), the snap-in should emit an event with type `EXTRACTION_DATA_PROGRESS` (no "data" payload). | ||
| - If the extraction is successful and all the resources have been extracted, the snap-in should emit an event with type `EXTRACTION_DATA_DONE` (no "data" payload). | ||
| - In case of unexpected error, the snap-in should emit an event with type `EXTRACTION_DATA_ERROR` ("data" payload should contain attribute "error" - error message as a string). | ||
| - In case of rate limiting (status code 429) for "data extraction", the snap-in *must* emit an event with type `EXTRACTION_DATA_DELAY`. If emitting event of type `EXTRACTION_DATA_DELAY`, you *must* also provide a "delay" attribute, specifying the delay in seconds as an integer. | ||
| - Example: `await adapter.emit(ExtractorEventType.ExtractionDataDelay, { delay: "30" });` | ||
|
|
||
| ## Input event: `EXTRACTION_EXTERNAL_SYNC_UNITS_START` | ||
|
|
||
| Here are the rules when `EXTRACTION_EXTERNAL_SYNC_UNITS_START` event is received by the snap-in: | ||
|
|
||
| - If "external sync unit extraction" is successful and the snap-in has extracted all the external sync units, the snap-in should emit an event with type `EXTRACTION_EXTERNAL_SYNC_UNITS_DONE` (no "data" payload). | ||
| - In case of unexpected error, the snap-in should emit an event with type `EXTRACTION_EXTERNAL_SYNC_UNITS_ERROR` ("data" payload should contain attribute "error" - error message as a string). | ||
| - In case of rate limiting (status code 429) for "external sync unit extraction", the snap-in should also emit an event with type `EXTRACTION_EXTERNAL_SYNC_UNITS_ERROR`. | ||
|
|
||
| ## Input event: `EXTRACTION_METADATA_START` | ||
|
|
||
| Here are the rules when `EXTRACTION_METADATA_START` event is received by the snap-in: | ||
| - If "metadata extraction" is successful and the snap-in has extracted all the metadata, the snap-in should emit an event with type `EXTRACTION_METADATA_DONE` (no "data" payload). | ||
| - In case of unexpected error, the snap-in should emit an event with type `EXTRACTION_METADATA_ERROR` ("data" payload should contain attribute "error" - error message as a string). | ||
|
|
||
| ## Input event: `EXTRACTION_ATTACHMENTS_START` or `EXTRACTION_ATTACHMENTS_CONTINUE` | ||
|
|
||
| Here are the rules when `EXTRACTION_ATTACHMENTS_START` or `EXTRACTION_ATTACHMENTS_CONTINUE` event is received by the snap-in: | ||
| - If "attachments extraction" is successful and the snap-in has extracted all the attachments, the snap-in should emit an event with type "EXTRACTION_ATTACHMENTS_DONE" | ||
| - If case of unexpected error, the snap-in should emit an event with type "EXTRACTION_ATTACHMENTS_ERROR" ("data" payload should contain attribute "error" - error message as a string). | ||
| - In case of rate limiting (status code 429) for "attachments extraction", the snap-in should also emit an event with type "EXTRACTION_ATTACHMENTS_DELAY". If emitting event of type "EXTRACTION_ATTACHMENTS_DELAY", you *must* also provide a "delay" attribute, specifying the delay in seconds as an integer. | ||
| - Example: `await adapter.emit(ExtractorEventType.ExtractionAttachmentsDelay, { delay: "30" });` | ||
| - If there's a timeout ("onTimeout" method in "spawn" method), the snap-in should emit an event with type "EXTRACTION_ATTACHMENTS_PROGRESS". | ||
|
|
||
|
|
||
| ## IMPORTANT FOR ALL INPUT EVENTS | ||
|
|
||
| - In all cases, only a single event should be emitted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.