Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
feat: field mapping and custom schema (#207)
Browse files Browse the repository at this point in the history
* prisma migration to add field mapping schemas

* seed hs note model (unverified)

* seed hs note model (verified)

* seed hs note model

* transform note acc to schema mapping

* (approach 2) transform note acc to schema field mapping

* (approach 2) seed all note fields and fix single note structure

* minor fix

* common func to transform field mapping to model

* disunify using field mapping

* allow connections to override field mapping

* support custom objects in schema; show custom fields as additional

* add winston and morgan logger

* Field mapping for contact; support custom field mapping to custom crm field

* add field mapping config

* common unify and disunify methods

* seed contact field mapping

* use lodash get to transform nested mappings

* unify and disunify for contact

* disunify based on account config

* unify and disunify for company

* unify and disunify for deal

* unify and disunify for event

* unify and disunify for lead

* unify and disunify for task

* unify and disunify for user

* minor refactor

* handle 2 level nesting and fix mapping

* make target field optional; multi level nesting

* fix

* fix

* fix obj merge

* fix pipedrive get format

* preprocess

* preprocess unify and disunify

* disunify postprocess

* flatten before disunify

* pipedrive fix contact create

* minor fixes

* fix pipedrive lead disunify

* chore: add account id to morgan logs

* chore: cleanup

* chore: cleanup

* chore: cleanup

* feat: ui for field mapping (#242)

* feat: processing ui

* feat: immplememt sse and redis pubsub

* feat: read sse data to render failed ui

* minor changes

* feat: api to fetch mappable details and crm object properties

* feat: api to create connection field mapping

* feat: add custom field mapped to connection schema

* feat: reallly basic ui for std field mapping

* feat: reallly basic ui for custom field mapping

* feat: add styling

* fix: fix add btn order

* feat: check for t_id in sse msg; send private token for calling further apis

* feat: save mappings on click

* feat: fix ui

* feat: show done screen

* feat: mark form dirty if empty fields

* feat: show done stage if config doesnt exist

* chore: fix pr comments

* chore: use temp tenant token for auth; ui fixes

* chore: fix dropdown caret; redis timeout

* chore: pubsub fix

* chore: cleanup

* chore: cleanup

* chore: resolve conflicts

* feat: add remove mapping btn and divider

* fix: fix logger

* chore: cleanup

* chore: move endpoints to fern

* update yarn.lock

* fix issues

* add hubspot create custom properties api

---------

Co-authored-by: jatin <sandilya.jatin@gmail.com>
  • Loading branch information
hvinder and jatinsandilya authored Oct 2, 2023
1 parent ac18977 commit 94d20c6
Show file tree
Hide file tree
Showing 71 changed files with 4,994 additions and 2,059 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ npm-debug.log*
!.github/**/*.yml
!fern/**/*.yml
revert-dev.js
.yarn/install-state.gz
Binary file modified .yarn/install-state.gz
Binary file not shown.
10 changes: 10 additions & 0 deletions fern/api/definition/common/types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ types:
- zohocrm
- sfdc
- pipedrive
StandardObject:
enum:
- company
- contact
- deal
- event
- lead
- note
- task
- user
ResponseStatus:
enum:
- ok
Expand Down
75 changes: 75 additions & 0 deletions fern/api/definition/crm/field-mapping/field-mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json

imports:
errors: ../../common/errors.yml
types: ../../common/types.yml

types:
MappableFieldType:
properties:
fieldName: string
objectName: types.StandardObject
FieldDetailsType:
properties:
fieldName: string
fieldType: string
fieldDescription: string
FieldMappingType:
properties:
sourceFieldName: string
targetFieldName: string
object: string
GetFieldMappingResponse:
properties:
canAddCustomMapping: boolean
mappableFields: list<MappableFieldType>
fieldList: unknown
CreateFieldMappingRequestBody:
properties:
standardMappings: list<FieldMappingType>
customMappings: list<FieldMappingType>
CreateFieldMappingResponse:
properties:
status: types.ResponseStatus

service:
base-path: /crm/field-mapping
auth: false
headers:
x-revert-api-token:
type: optional<string>
docs: Your official API key for accessing revert apis.
x-revert-t-id:
type: string
docs: The unique customer id used when the customer linked their account.
x-revert-t-token:
type: optional<string>
docs: The temp used to identify tenant.
x-api-version:
type: optional<string>
docs: Optional Revert API version you're using. If missing we default to the latest version of the API.
audiences:
- external
endpoints:
getFieldMapping:
docs: Get field mappings for a connection
method: GET
path: ''
request:
name: GetFieldMappingRequest
response: GetFieldMappingResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
createFieldMapping:
docs: Create field mappings for a connection
method: POST
path: ''
request:
name: CreateFieldMappingRequest
body: CreateFieldMappingRequestBody
response: CreateFieldMappingResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
- errors.NotFoundError
64 changes: 64 additions & 0 deletions fern/api/definition/crm/properties.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json

imports:
errors: ../common/errors.yml
types: ../common/types.yml

types:
FieldDetailsType:
properties:
fieldName: string
fieldType: string
fieldDescription: string
FieldDetailsTypeRequest:
extends: FieldDetailsType
properties:
groupName: string
type: string
SetObjectPropertiesRequest: FieldDetailsTypeRequest
GetObjectPropertiesResponse: unknown
SetObjectPropertiesResponse: unknown

service:
base-path: /crm/properties
auth: false
headers:
x-revert-api-token:
type: string
docs: Your official API key for accessing revert apis.
x-revert-t-id:
type: string
docs: The unique customer id used when the customer linked their account.
x-api-version:
type: optional<string>
docs: Optional Revert API version you're using. If missing we default to the latest version of the API.
audiences:
- external
endpoints:
getObjectProperties:
docs: Get object properties for connection
method: GET
path: /{objectName}
path-parameters:
objectName: types.StandardObject
request:
name: GetObjectPropertiesRequest
response: GetObjectPropertiesResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
- errors.NotFoundError
setCustomProperties:
docs: Set custom properties on an object for a given connection
method: POST
path: /{objectName}
path-parameters:
objectName: types.StandardObject
request:
name: SetObjectCustomPropertiesRequest
body: SetObjectPropertiesRequest
response: SetObjectPropertiesResponse
errors:
- errors.UnAuthorizedError
- errors.InternalServerError
- errors.NotFoundError
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"packages/*"
],
"devDependencies": {
"concurrently": "^8.2.1",
"fern-api": "0.12.0",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
Expand All @@ -17,7 +18,8 @@
"fern-docs": "fern generate --group external",
"build": "yarn workspaces foreach run build",
"prepare": "husky install",
"lint": "lint-staged"
"lint": "lint-staged",
"dev:all": "concurrently --kill-others \"yarn workspace @revertdotdev/js dev\" \"yarn workspace @revertdotdev/backend dev\" \"yarn workspace @revertdotdev/revert-ui start\" "
},
"prisma": {
"schema": "packages/backend/prisma/schema.prisma",
Expand Down
19 changes: 19 additions & 0 deletions packages/backend/constants/associations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Subtype } from "./typeHelpers";

export type AllAssociation = 'contactId' | 'companyId' | 'leadId' | 'dealId' | 'noteId';

export type CompanyAssociation = Subtype<AllAssociation, 'dealId'>;

export type ContactAssociation = Subtype<AllAssociation, 'dealId'>;

export type DealAssociation = Subtype<AllAssociation, 'contactId' | 'companyId'>;

export type EventAssociation = Subtype<AllAssociation, 'dealId' | 'contactId'>;

export type LeadAssociation = Subtype<AllAssociation, 'contactId' | 'companyId' | 'dealId'>;

export type NoteAssociation = Subtype<AllAssociation, 'contactId' | 'companyId' | 'leadId' | 'dealId'>;

export type TaskAssociation = Subtype<AllAssociation, 'dealId'>;

export type UserAssociation = Subtype<AllAssociation, 'dealId'>;
71 changes: 70 additions & 1 deletion packages/backend/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,73 @@ export const DEFAULT_SCOPE = {
[TP_ID.pipedrive]: [],
};

export type AllAssociation = 'contactId' | 'companyId' | 'leadId' | 'dealId' | 'noteId';
export const mapIntegrationIdToIntegrationName = {
[TP_ID.hubspot]: "Hubspot",
[TP_ID.pipedrive]: "Pipedrive",
[TP_ID.sfdc]: "Salesforce",
[TP_ID.zohocrm]: "Zoho",
}

export const rootSchemaMappingId = 'revertRootSchemaMapping';

export enum StandardObjects {
company = 'company',
contact = 'contact',
deal = 'deal',
event = 'event',
lead = 'lead',
note = 'note',
task = 'task',
user = 'user',
}

export const objectNameMapping: Record<string, Record<TP_ID, string | undefined>> = {
[StandardObjects.company]: {
[TP_ID.hubspot]: 'companies',
[TP_ID.pipedrive]: 'organization',
[TP_ID.sfdc]: 'Account',
[TP_ID.zohocrm]: 'Accounts',
},
[StandardObjects.contact]: {
[TP_ID.hubspot]: 'contacts',
[TP_ID.pipedrive]: 'person',
[TP_ID.sfdc]: 'Contact',
[TP_ID.zohocrm]: 'Contacts',
},
[StandardObjects.deal]: {
[TP_ID.hubspot]: 'deals',
[TP_ID.pipedrive]: 'deal',
[TP_ID.sfdc]: 'Opportunity',
[TP_ID.zohocrm]: 'Deals',
},
[StandardObjects.event]: {
[TP_ID.hubspot]: 'meetings',
[TP_ID.pipedrive]: 'activity',
[TP_ID.sfdc]: 'Event',
[TP_ID.zohocrm]: 'Events',
},
[StandardObjects.lead]: {
[TP_ID.hubspot]: 'contacts',
[TP_ID.pipedrive]: 'lead',
[TP_ID.sfdc]: 'Lead',
[TP_ID.zohocrm]: 'Leads',
},
[StandardObjects.note]: {
[TP_ID.hubspot]: 'notes',
[TP_ID.pipedrive]: 'note',
[TP_ID.sfdc]: 'Note',
[TP_ID.zohocrm]: 'Notes',
},
[StandardObjects.task]: {
[TP_ID.hubspot]: 'tasks',
[TP_ID.pipedrive]: 'activity',
[TP_ID.sfdc]: 'Task',
[TP_ID.zohocrm]: 'Tasks',
},
[StandardObjects.user]: {
[TP_ID.hubspot]: 'users',
[TP_ID.pipedrive]: undefined,
[TP_ID.sfdc]: 'User',
[TP_ID.zohocrm]: 'users',
},
};
Loading

1 comment on commit 94d20c6

@vercel
Copy link

@vercel vercel bot commented on 94d20c6 Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

revert-client – ./

revert-client-git-main-revertdev.vercel.app
revert-client-revertdev.vercel.app
app.revert.dev

Please sign in to comment.