import RipplingSDK, { DetailViewActionFunctionEvent, FunctionContext, FunctionResponse, ListViewActionFunctionEvent, } from '@rippling/rippling-sdk'; const TODO_OBJECT_API_NAME = 'simple_todo__c'; const ACTION_BUTTON = 'Mark done'; type DetailEvent = DetailViewActionFunctionEvent< {}, typeof TODO_OBJECT_API_NAME, typeof ACTION_BUTTON, 'layout_simple_todo' >; type ListEvent = ListViewActionFunctionEvent<{}, typeof TODO_OBJECT_API_NAME, typeof ACTION_BUTTON>; type MarkDoneEvent = DetailEvent | ListEvent; export async function onRipplingEvent( event: MarkDoneEvent, context: FunctionContext, ): Promise> { const recordIds = event.trigger_type === 'record view' ? [event.record_id] : event.record_ids; if (recordIds.length === 0) { return new FunctionResponse({ body: { updatedRecordIds: [] }, message: 'Select at least one todo.', }); } const client = new RipplingSDK({ bearerToken: context.env.rippling_user_bearer_token, }); for (const recordId of recordIds) { await client.customObjects.records.update(TODO_OBJECT_API_NAME, recordId, { status__c: 'Done', }); } return new FunctionResponse({ body: { updatedRecordIds: recordIds }, message: `Marked ${recordIds.length} todo${recordIds.length === 1 ? '' : 's'} as done.`, }); }