This project implements a TypeScript-based solution to synchronize person data with Pipedrive, using the provided inputData.json and mappings.json. The core function, syncPdPerson(), reads mappings to transform input data into the Pipedrive Person payload. It first checks if a person with the mapped name exists in Pipedrive, updates that person if found, or creates a new person otherwise.
The codebase follows TypeScript best practices for type safety and maintainability. It is modular, includes robust error handling for API calls, and gracefully handles key edge cases.
- Node.js (v16+ recommended)
- npm or pnpm package manager
- Pipedrive account with API key
-
Clone the repository: git clone https://github.com/Aswin-K-22/pd-sync-assignment.git cd pd-sync-assignment
-
Install dependencies: npm install or pnpm install
-
Create a
.envfile in the project root with the following variables:
PIPEDRIVE_API_KEY=your_pipedrive_api_key PIPEDRIVE_COMPANY_DOMAIN=your_pipedrive_company_domain
src/index.ts— Main executable file containingsyncPdPerson()implementation.src/api/pipedrive.ts— API interaction functions with Pipedrive.src/mappings/inputData.json— Sample input data about a person.src/mappings/mappings.json— Field mappings between input data and Pipedrive payload keys.src/utils/data.ts— Utility functions (e.g., nested value extraction with fallback).src/types/pipedrive.ts— TypeScript interfaces and types related to Pipedrive API.
The following edge cases are handled in the implementation:
-
Empty
mappings.json:- Description: If
mappings.jsonis empty ([]), no fields can be mapped to the Pipedrive API payload. - Handling: The
syncPdPersonfunction checks ifmappingsis empty and throws an error:"mappings.json is empty". Tested with an emptymappings.json, resulting in the expected error.
- Description: If
-
Missing Name Mapping or Value:
- Description: If the
namemapping is missing inmappings.jsonor its corresponding value is missing or invalid (e.g., empty string) ininputData.json, the function cannot proceed. - Handling: The
syncPdPersonfunction validates the presence of thenamemapping and its value, throwing specific errors (e.g.,"No mapping found for 'name' in mappings.json"or"Name value is missing or invalid in inputData.json for key 'fullName'"). Tested withfullName: ""and missingnamemapping, resulting in the expected errors.
- Description: If the
-
Incorrect Input Key in
mappings.json:- Description: The provided
mappings.jsonincludes an incorrectinputKey(e.g.,phone.homeinstead ofphoneNumber.home), which does not match the structure ofinputData.json. - Handling: The
getNestedValuefunction implements a fallback mechanism that searches for a matching key ininputData.json(e.g., usingphoneNumber.homeifphone.homeis not found) and logs a warning (e.g.,"Used fallback path 'phoneNumber.home' instead of 'phone.home'"). Tested with the providedmappings.json.
- Description: The provided
-
Duplicate Persons in Pipedrive:
- Description: If multiple persons with the same name exist in Pipedrive, the function might select the wrong one, potentially affecting data accuracy.
- Handling: The
findPersonByNamefunction logs a warning if multiple persons are found (e.g.,"Multiple persons found with name 'Jason'. Selecting the first one.") and selects the first match to avoid creating duplicates. Tested with multiple 'Jason' persons in Pipedrive, resulting in the expected warning and successful update.
- Manual testing was performed using the
npm run devcommand, successfully syncing persons to Pipedrive with correct payloads. - The console logs show mapping steps, payload construction, and API response verification.
- Tested edge cases by modifying
mappings.jsonandinputData.jsonto confirm proper error handling and fallback logic. - Verified handling of multiple persons with the same name in Pipedrive through logs and update confirmation.
Aswin K
Email: aswinkwebdeveloper@gmail.com
GitHub: https://github.com/Aswin-K-22
Thank you for reviewing my assignment. Please feel free to reach out if you have any questions or feedback.