### Load DevRev Items: Create and Update Todos Source: https://context7.com/devrev/airdrop-template/llms.txt Processes DevRev items (todos) and synchronizes them to an external system using create and update functions. It handles item denormalization and interacts with an external HTTP client. Dependencies include '@devrev/ts-adaas' and local modules for HTTP client and data denormalization. ```typescript import { processTask, LoaderEventType, ExternalSystemItem, ExternalSystemItemLoadingParams, ExternalSystemItemLoadingResponse } from '@devrev/ts-adaas'; import { HttpClient } from './external-system/http-client'; import { denormalizeTodo } from './external-system/data-denormalization'; // Create function for new items async function createTodo({ item, mappers, event, }: ExternalSystemItemLoadingParams): Promise { const httpClient = new HttpClient(event); const todo = denormalizeTodo(item); const response = await httpClient.createTodo(todo); // Return format options: // Success: { id: 'external-id-123' } // Error: { error: 'Error message' } // Retry: { delay: 5000 } // milliseconds return response; } // Update function for existing items async function updateTodo({ item, mappers, event, }: ExternalSystemItemLoadingParams): Promise { const httpClient = new HttpClient(event); // Get external ID from sync mapper const syncMapperRecordResponse = await mappers.getByTargetId({ sync_unit: event.payload.event_context.sync_unit, target: item.id.devrev, }); const todoExternalId = syncMapperRecordResponse.data.sync_mapper_record.external_ids[0]; const todo = denormalizeTodo(item); const response = await httpClient.updateTodo(todo); return response; } processTask({ task: async ({ adapter }) => { const { reports, processed_files } = await adapter.loadItemTypes({ itemTypesToLoad: [ { itemType: 'todos', create: createTodo, update: updateTodo, }, ], }); await adapter.emit(LoaderEventType.DataLoadingDone, { reports, processed_files, }); }, onTimeout: async ({ adapter }) => { await adapter.emit(LoaderEventType.DataLoadingProgress, { reports: adapter.reports, processed_files: adapter.processedFiles, }); }, }); ``` -------------------------------- ### HTTP Client for External System API Integration Source: https://context7.com/devrev/airdrop-template/llms.txt This TypeScript HTTP client manages API communication with an external system, handling authentication and CRUD operations. It takes an AirdropEvent as input for connection data and provides methods to fetch, create, and update various data types like todos, users, and attachments. The client uses a placeholder implementation for create/update operations. ```typescript import { AirdropEvent } from '@devrev/ts-adaas'; import { HttpClient } from './external-system/http-client'; // Initialize with event containing connection data const event: AirdropEvent = { payload: { connection_data: { key: 'your-api-token' }, event_type: EventType.ExtractionDataStart } }; const client = new HttpClient(event); // Fetch todo lists const todoLists = await client.getTodoLists(); // Returns: [{ id: '1', name: 'Todo List', description: '...', item_count: 2, item_type: 'todos' }] // Fetch todos const todos = await client.getTodos(); // Returns: [{ id: 'todo-1', title: 'Todo 1', body: '

...

', creator: 'user-1', owner: 'user-1', created_date: '1999-12-25T01:00:03+01:00', modified_date: '1999-12-25T01:00:03+01:00' }] // Fetch users const users = await client.getUsers(); // Returns: [{ id: 'user-1', name: 'John Doe', email: 'johndoe@test.com', created_date: '1999-12-25T01:00:03+01:00', modified_date: '1999-12-25T01:00:03+01:00' }] // Fetch attachments const attachments = await client.getAttachments(); // Returns: [{ id: 'attachment-1', url: 'https://...', file_name: 'favicon1.ico', author_id: 'user-1', parent_id: 'todo-1' }] // Create todo in external system const newTodo = { id: 'todo-3', title: 'New Todo', body: '

Description

', creator: 'user-1', owner: 'user-1', created_date: new Date().toISOString(), modified_date: new Date().toISOString() }; const createResponse = await client.createTodo(newTodo); // Returns: { error: 'Could not create todo in external system.' } (placeholder implementation) // Update existing todo const updatedTodo = { ...newTodo, title: 'Updated Todo' }; const updateResponse = await client.updateTodo(updatedTodo); // Returns: { error: 'Could not update todo in external system.' } (placeholder implementation) ``` -------------------------------- ### Function Factory - Access Extraction and Loading Functions (TypeScript) Source: https://context7.com/devrev/airdrop-template/llms.txt Provides centralized access to extraction and loading functions within the DevRev AirSync Snap-in Template. It exports a type-safe registry of available snap-in functions, allowing developers to easily access and use specific functionalities. ```typescript import { functionFactory } from './function-factory'; // Access extraction function const extractionFunction = functionFactory.extraction; // Access loading function const loadingFunction = functionFactory.loading; // Type-safe function names type AvailableFunctions = keyof typeof functionFactory; // 'extraction' | 'loading' ``` -------------------------------- ### Denormalize DevRev Item to External System Format Source: https://context7.com/devrev/airdrop-template/llms.txt Transforms DevRev normalized items into the format required for external system API calls. This function is crucial for preparing data before creating or updating items in the external system. It takes an 'ExternalSystemItem' as input and returns an 'ExternalTodo' object. ```typescript import { ExternalSystemItem } from '@devrev/ts-adaas'; import { denormalizeTodo } from './external-system/data-denormalization'; import { ExternalTodo } from './external-system/types'; // DevRev normalized item const devrevItem: ExternalSystemItem = { id: { devrev: 'don:core:dvrv-us-1:devo/ABC:issue/123' }, data: { title: 'Fix bug in payment processor', body: '

Critical bug affecting checkout

', creator: 'user-1', owner: 'user-2' }, created_date: '2024-01-15T10:00:00Z', modified_date: '2024-01-16T14:30:00Z' }; // Denormalize for external system API const externalTodo: ExternalTodo = denormalizeTodo(devrevItem); // Returns: { // id: 'don:core:dvrv-us-1:devo/ABC:issue/123', // title: 'Fix bug in payment processor', // body: '

Critical bug affecting checkout

', // creator: 'user-1', // owner: 'user-2', // created_date: '2024-01-15T10:00:00Z', // modified_date: '2024-01-16T14:30:00Z' // } // Use with HTTP client const httpClient = new HttpClient(event); await httpClient.createTodo(externalTodo); ``` -------------------------------- ### Sync DevRev Data to External System (TypeScript) Source: https://context7.com/devrev/airdrop-template/llms.txt This function synchronizes data from DevRev back to an external system, handling both creation and updates. It processes a list of AirdropEvents, triggering specific loading processes for data and attachments based on event types. ```typescript import { AirdropEvent, EventType } from '@devrev/ts-adaas'; import loading from './functions/loading'; // Example loading events const loadingEvents: AirdropEvent[] = [ { payload: { event_type: EventType.StartLoadingData, connection_data: { key: 'api-token-123' }, event_context: { sync_unit: 'todo-list-1' } } }, { payload: { event_type: EventType.StartLoadingAttachments, connection_data: { key: 'api-token-123' }, event_context: { sync_unit: 'todo-list-1' } } } ]; // Run loading await loading(loadingEvents); // The loading function will spawn workers for: // 1. Data loading (create/update todos) // 2. Attachments loading ``` -------------------------------- ### External Sync Units Extraction Worker - Fetch and Normalize Todo Lists (TypeScript) Source: https://context7.com/devrev/airdrop-template/llms.txt A worker for the DevRev AirSync Snap-in Template that extracts high-level sync units, such as todo lists, from an external system. It fetches data using an HTTP client, normalizes it to the DevRev format, and emits completion or error events. ```typescript import { processTask, ExtractorEventType, ExternalSyncUnit } from '@devrev/ts-adaas'; import { HttpClient } from './external-system/http-client'; import { normalizeTodoList } from './external-system/data-normalization'; processTask({ task: async ({ adapter }) => { const httpClient = new HttpClient(adapter.event); // Fetch todo lists from external system const todoLists = await httpClient.getTodoLists(); // Normalize to DevRev format const externalSyncUnits: ExternalSyncUnit[] = todoLists.map(list => normalizeTodoList(list) ); // Emit completion event with extracted units await adapter.emit(ExtractorEventType.ExtractionExternalSyncUnitsDone, { external_sync_units: externalSyncUnits, }); }, onTimeout: async ({ adapter }) => { await adapter.emit(ExtractorEventType.ExtractionExternalSyncUnitsError, { error: { message: 'Failed to extract external sync units. Lambda timeout.' }, }); }, }); ``` -------------------------------- ### Manage Extractor State with Custom Types in TypeScript Source: https://context7.com/devrev/airdrop-template/llms.txt This snippet demonstrates how to define and manage custom extractor states by extending the base ExtractorState. It shows initializing a state object with custom properties like todos, users, and attachments, and how to access and update these properties within a worker task using an adapter. This pattern is useful for tracking detailed progress and custom data during data extraction processes. ```typescript import { ExtractorState, initialExtractorState } from './functions/extraction'; // Define custom state interface interface CustomExtractorState extends ExtractorState { todos: { completed: boolean; page?: number; total?: number }; users: { completed: boolean; page?: number; total?: number }; attachments: { completed: boolean; page?: number; total?: number }; customField?: { lastSyncTime: string }; } // Initialize state const state: CustomExtractorState = { ...initialExtractorState, todos: { completed: false, page: 0, total: 0 }, users: { completed: false, page: 0, total: 0 }, attachments: { completed: false, page: 0, total: 0 }, customField: { lastSyncTime: new Date().toISOString() } }; // Use in worker processTask({ task: async ({ adapter }) => { // Access and update state adapter.state.todos.page = 1; adapter.state.todos.total = 100; // Process items... adapter.state.todos.completed = true; } }); ``` -------------------------------- ### Extract External System Metadata Source: https://context7.com/devrev/airdrop-template/llms.txt Extracts and processes external system metadata, including custom fields and type definitions. This worker combines static metadata with potentially dynamic data fetched from an API. It utilizes '@devrev/ts-adaas' for task processing and event emission. Dependencies include '@devrev/ts-adaas' and a local JSON file for static metadata. ```typescript import { processTask, ExtractorEventType } from '@devrev/ts-adaas'; import staticExternalDomainMetadata from './external-system/external_domain_metadata.json'; processTask({ task: async ({ adapter }) => { adapter.initializeRepos([{ itemType: 'external_domain_metadata' }]); // Combine static and dynamic metadata const externalDomainMetadata = { ...staticExternalDomainMetadata, // Add dynamic metadata from API if needed // customFields: await httpClient.getCustomFields() }; await adapter.getRepo('external_domain_metadata')?.push([externalDomainMetadata]); await adapter.emit(ExtractorEventType.ExtractionMetadataDone); }, onTimeout: async ({ adapter }) => { await adapter.emit(ExtractorEventType.ExtractionMetadataError, { error: { message: 'Failed to extract metadata. Lambda timeout.' }, }); }, }); ``` -------------------------------- ### Extraction Function - Orchestrate Data Import from External System (TypeScript) Source: https://context7.com/devrev/airdrop-template/llms.txt Orchestrates the data extraction process for the DevRev AirSync Snap-in Template using event-driven workers. It processes AirdropEvents and spawns appropriate workers based on event types for various extraction phases like metadata and data extraction. ```typescript import { AirdropEvent, EventType } from '@devrev/ts-adaas'; import extraction from './functions/extraction'; // Example extraction event const extractionEvents: AirdropEvent[] = [ { payload: { event_type: EventType.ExtractionExternalSyncUnitsStart, connection_data: { key: 'api-token-123' }, event_context: { sync_unit: 'todo-list-1' } } }, { payload: { event_type: EventType.ExtractionDataStart, connection_data: { key: 'api-token-123' } } } ]; // Run extraction await extraction(extractionEvents); // The extraction function will spawn workers for: // 1. External sync units extraction (todo lists) // 2. Metadata extraction (field definitions) // 3. Data extraction (todos, users, attachments) // 4. Attachments extraction ``` -------------------------------- ### Data Extraction Worker for DevRev Source: https://context7.com/devrev/airdrop-template/llms.txt This TypeScript worker extracts data items (todos, users, attachments) from an external system and normalizes them for DevRev storage. It uses the '@devrev/ts-adaas' library and custom normalization functions. Dependencies include an HTTP client for fetching data and adapter for DevRev integration. ```typescript import { processTask, ExtractorEventType } from '@devrev/ts-adaas'; import { HttpClient } from './external-system/http-client'; import { normalizeTodo, normalizeUser, normalizeAttachment } from './external-system/data-normalization'; // Define repositories for storing extracted data const repos = [ { itemType: 'todos', normalize: (item: object) => normalizeTodo(item as ExternalTodo), }, { itemType: 'users', normalize: (item: object) => normalizeUser(item as ExternalUser), }, { itemType: 'attachments', normalize: (item: object) => normalizeAttachment(item as ExternalAttachment), }, ]; processTask({ task: async ({ adapter }) => { adapter.initializeRepos(repos); const httpClient = new HttpClient(adapter.event); // Extract todos const todos = await httpClient.getTodos(); await adapter.getRepo('todos')?.push(todos); adapter.state.todos.completed = true; // Extract users const users = await httpClient.getUsers(); await adapter.getRepo('users')?.push(users); adapter.state.users.completed = true; // Extract attachments const attachments = await httpClient.getAttachments(); await adapter.getRepo('attachments')?.push(attachments); adapter.state.attachments.completed = true; await adapter.emit(ExtractorEventType.ExtractionDataDone); }, onTimeout: async ({ adapter }) => { await adapter.emit(ExtractorEventType.ExtractionDataProgress); }, }); ``` -------------------------------- ### Normalize External Data to DevRev Format (TypeScript) Source: https://context7.com/devrev/airdrop-template/llms.txt These functions transform data structures from external systems into DevRev's normalized format. They are essential for data ingestion and ensure consistency. The functions handle specific entity types like todo lists, individual todos, users, and attachments, mapping external fields to their DevRev equivalents. ```typescript import { normalizeTodoList, normalizeTodo, normalizeUser, normalizeAttachment } from './external-system/data-normalization'; import { ExternalTodoList, ExternalTodo, ExternalUser, ExternalAttachment } from './external-system/types'; // Normalize todo list (external sync unit) const externalTodoList: ExternalTodoList = { id: '1', name: 'My Project Tasks', description: 'Tasks for Q1 project', item_count: 15, item_type: 'todos' }; const normalizedList = normalizeTodoList(externalTodoList); // Returns: { id: '1', name: 'My Project Tasks', description: '...', item_count: 15, item_type: 'todos' } // Normalize todo item const externalTodo: ExternalTodo = { id: 'todo-1', title: 'Implement feature X', body: '

Complete implementation by EOD

', creator: 'user-1', owner: 'user-2', created_date: '2024-01-15T10:00:00Z', modified_date: '2024-01-16T14:30:00Z' }; const normalizedTodo = normalizeTodo(externalTodo); // Returns: { // id: 'todo-1', // created_date: '2024-01-15T10:00:00Z', // modified_date: '2024-01-16T14:30:00Z', // data: { // title: 'Implement feature X', // body: '

...

', // creator: 'user-1', // owner: 'user-2', // item_url_field: 'https://external-system.com/todos/todo-1' // } // } // Normalize user const externalUser: ExternalUser = { id: 'user-1', name: 'John Doe', email: 'john.doe@company.com', created_date: '2023-06-01T08:00:00Z', modified_date: '2024-01-10T12:00:00Z' }; const normalizedUser = normalizeUser(externalUser); // Returns: { // id: 'user-1', // created_date: '2023-06-01T08:00:00Z', // modified_date: '2024-01-10T12:00:00Z', // data: { name: 'John Doe', email: 'john.doe@company.com' } // } // Normalize attachment const externalAttachment: ExternalAttachment = { id: 'att-1', url: 'https://cdn.example.com/files/document.pdf', file_name: 'specification.pdf', author_id: 'user-1', parent_id: 'todo-1' }; const normalizedAttachment = normalizeAttachment(externalAttachment); // Returns: { // id: 'att-1', // url: 'https://cdn.example.com/files/document.pdf', // file_name: 'specification.pdf', // author_id: 'user-1', // parent_id: 'todo-1' // } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.