diff --git a/base_folder/src/core/types.ts b/base_folder/src/core/types.ts deleted file mode 100644 index 228c5d0..0000000 --- a/base_folder/src/core/types.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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; - }; - - 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; - // 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; - }; - - // Event sent to our app. - export type FunctionInput = { - // Actual payload of the event. - payload: Record; - // Context of the function invocation. - context: Context; - // Metadata of the function invocation. - execution_metadata: ExecutionMetadata; - input_data: InputData; - }; \ No newline at end of file diff --git a/base_folder/src/core/utils.ts b/base_folder/src/core/utils.ts deleted file mode 100644 index b9a376d..0000000 --- a/base_folder/src/core/utils.ts +++ /dev/null @@ -1,30 +0,0 @@ -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, - }; - } - \ No newline at end of file diff --git a/docs/function_invocation.mdx b/docs/function_invocation.mdx index 991c18e..ada4c2b 100644 --- a/docs/function_invocation.mdx +++ b/docs/function_invocation.mdx @@ -3,7 +3,7 @@ A function can be invoked synchronously or asynchronously. You need to implement the run method in your function. The run method is called when the function is invoked. The run method signature is defined below: ```typescript -async function run(events: []FunctionInput): any; +async function run(events: any[]): any; ``` The value returned from the `run` method is passed back in synchronous execution modes, such as commands, snap kit actions, and event source synchronous execution. In asynchronous execution modes, such as automation execution, the return value is ignored.