From ed698e4ec36268f48abe8ea9fdca3526dce5da82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patricija=20Bre=C4=8Dko?= Date: Tue, 8 Jul 2025 09:35:55 +0200 Subject: [PATCH 1/2] Add function invocation docs --- devrev-snapin-template.plain | 1 + docs/function_invocation.mdx | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 docs/function_invocation.mdx diff --git a/devrev-snapin-template.plain b/devrev-snapin-template.plain index a077240..d89b68d 100644 --- a/devrev-snapin-template.plain +++ b/devrev-snapin-template.plain @@ -3,6 +3,7 @@ - The Snap-In is a TypeScript Node.js application. - The Function implements part of The Snap-In functionality. + - Details on how The Function must be invoked are provided in the resource [Function Invocation](docs/function_invocation.mdx). - The Airdrop SDK Library for TypeScript helps developers build snap-ins that integrate with DevRev’s Airdrop platform. - The documentation for the The Airdrop SDK Library is provided in the resource [airdrop_sdk_library_documentation.md](docs/airdrop_sdk_library_documentation.md). diff --git a/docs/function_invocation.mdx b/docs/function_invocation.mdx new file mode 100644 index 0000000..923a2d4 --- /dev/null +++ b/docs/function_invocation.mdx @@ -0,0 +1,52 @@ +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 +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; +}; +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; +}; +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. +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; +}; +async function run(events: []FunctionInput): any; +``` +As of now, it's safe to assume that only one event is passed to the function at a time. The function can be invoked multiple times for multiple events. +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. From 4815d38358128670e1ab2c7e68480f94ddb14725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patricija=20Bre=C4=8Dko?= Date: Tue, 8 Jul 2025 09:40:10 +0200 Subject: [PATCH 2/2] Typo --- docs/function_invocation.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/function_invocation.mdx b/docs/function_invocation.mdx index 923a2d4..6c21abf 100644 --- a/docs/function_invocation.mdx +++ b/docs/function_invocation.mdx @@ -30,7 +30,7 @@ type ExecutionMetadata = { }; 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 + // The values are passed as string and typing needs 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.