From 3d5083e519ca30e469b54561edb9d5ee6b508515 Mon Sep 17 00:00:00 2001 From: nael Date: Sat, 15 Jun 2024 01:49:21 +0200 Subject: [PATCH] Revert ":sparkles: New features" This reverts commit c8a89a0eac0b32e098fec6c0c4c0c5715f042ccd. --- .env.example | 2 +- .gitignore | 3 +- .../Connector/ConnectorDisplay.tsx | 27 +- .../components/Connection/ConnectionTable.tsx | 2 +- .../src/hooks/get/useConnections.tsx | 1 - docker-compose.dev.yml | 35 +- docker-compose.source.yml | 2 +- docker-compose.yml | 2 +- ngrok.yml | 10 - packages/api/prisma/schema.prisma | 404 +++++++++--------- packages/api/scripts/connectorUpdate.js | 207 ++++----- packages/api/scripts/init.sql | 4 +- packages/api/scripts/seed.sql | 2 +- .../connections-strategies.service.ts | 2 +- .../src/ticketing/@webhook/zendesk/handler.ts | 11 +- packages/shared/src/connectors/enum.ts | 2 +- 16 files changed, 335 insertions(+), 381 deletions(-) delete mode 100644 ngrok.yml diff --git a/.env.example b/.env.example index d12846bda..7f4c6b285 100644 --- a/.env.example +++ b/.env.example @@ -30,9 +30,9 @@ POSTGRES_DB=panora_db POSTGRES_HOST=postgres POSTGRES_PASSWORD=my_password -# Endpoint on which realtime webhooks are sent to WEBHOOK_INGRESS=http://localhost:3000 + # Each Provider is of form PROVIDER_VERTICAL_SOFTWAREMODE_ATTRIBUTE # ================================================ # Integration Providers diff --git a/.gitignore b/.gitignore index 72a33af56..2377557f2 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ redis_data .DS_Store .pnpm-store/ .npmrc -.vscode \ No newline at end of file +.vscode +ngrok.yml \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx b/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx index 4e54aa115..73e2892e9 100644 --- a/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx +++ b/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx @@ -31,22 +31,22 @@ const formSchema = z.object({ }).optional(), client_id : z.string({ required_error: "Please Enter a Client ID", - }).optional(), + }), client_secret : z.string({ required_error: "Please Enter a Client Secret", - }).optional(), + }), scope : z.string({ required_error: "Please Enter a scope", - }).optional(), + }), api_key: z.string({ required_error: "Please Enter a API Key", - }).optional(), + }), username: z.string({ required_error: "Please Enter Username", - }).optional(), + }), secret: z.string({ required_error: "Please Enter Secret", - }).optional(), + }), }) export function ConnectorDisplay({ item }: ItemDisplayProps) { @@ -200,7 +200,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { updateToggle: false, status: dataToUpdate.status, attributes: ["api_key"], - values: [api_key!] + values: [api_key] }), { loading: 'Loading...', @@ -229,7 +229,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { createCsPromise({ type: providerToType(item?.name, item?.vertical!, AuthStrategy.api_key), attributes: ["api_key"], - values: [api_key!] + values: [api_key] }), { loading: 'Loading...', @@ -276,7 +276,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { updateToggle: false, status: dataToUpdate.status, attributes: ["username", "secret"], - values: [username!, secret!] + values: [username, secret] }), { loading: 'Loading...', @@ -306,7 +306,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { createCsPromise({ type: providerToType(item?.name, item?.vertical!, AuthStrategy.basic), attributes: ["username", "secret"], - values: [username!, secret!] + values: [username, secret] }), { loading: 'Loading...', @@ -342,7 +342,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { fetchCredentials({ type: mappingConnectionStrategies[0].type, attributes: item?.authStrategy === AuthStrategy.oauth2 ? needsSubdomain(item.name.toLowerCase(), item.vertical!.toLowerCase()) ? ["subdomain", "client_id", "client_secret", "scope"] : ["client_id", "client_secret", "scope"] - : item?.authStrategy === AuthStrategy.api_key ? ["api_key"] : ["username", "secret"] + : item?.authStrategy === AuthStrategy.api_key ? ["api_key"] : ["username", "secret"] }, { onSuccess(data) { if (item?.authStrategy === AuthStrategy.oauth2) { @@ -436,9 +436,9 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) {
{ item.authStrategy == AuthStrategy.oauth2 && + <> - - { needsSubdomain(item.name.toLowerCase(), item.vertical!.toLowerCase()) && + { needsSubdomain(item.name.toLowerCase(), item.vertical!.toLowerCase()) &&
} -
diff --git a/apps/client-ts/src/hooks/get/useConnections.tsx b/apps/client-ts/src/hooks/get/useConnections.tsx index b82dd6b55..27b4948bc 100644 --- a/apps/client-ts/src/hooks/get/useConnections.tsx +++ b/apps/client-ts/src/hooks/get/useConnections.tsx @@ -5,7 +5,6 @@ import Cookies from 'js-cookie'; const useConnections = () => { - console.log(Cookies.get('access_token')) return useQuery({ queryKey: ['connections'], queryFn: async (): Promise => { diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 17aea9853..0a184166e 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -32,6 +32,7 @@ services: environment: DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?ssl=false DISTRIBUTION: ${DISTRIBUTION} + WEBHOOK_INGRESS: ${WEBHOOK_INGRESS} JWT_SECRET: ${JWT_SECRET} REDIS_HOST: ${REDIS_HOST} REDIS_PASS: ${REDIS_PASS} @@ -39,7 +40,6 @@ services: REDIS_PORT: ${REDIS_PORT} #REDIS_TLS: 1 # set this variable to 1 when Redis is AWS hosted REDIS_DB: ${REDIS_DB} - WEBHOOK_INGRESS: ${WEBHOOK_INGRESS} ENCRYPT_CRYPTO_SECRET_KEY: ${ENCRYPT_CRYPTO_SECRET_KEY} HUBSPOT_CRM_CLOUD_CLIENT_ID: ${HUBSPOT_CRM_CLOUD_CLIENT_ID} HUBSPOT_CRM_CLOUD_CLIENT_SECRET: ${HUBSPOT_CRM_CLOUD_CLIENT_SECRET} @@ -189,23 +189,22 @@ services: volumes: - .:/app - ngrok: - image: ngrok/ngrok:latest - restart: always - command: - - "start" - - "--all" - - "--config" - - "/etc/ngrok.yml" - volumes: - - ./ngrok.yml:/etc/ngrok.yml - ports: - - 4040:4040 - depends_on: - api: - condition: service_healthy - network_mode: "host" - + #ngrok: + #image: ngrok/ngrok:latest + #restart: always + #command: + # - "start" + # - "--all" + # - "--config" + # - "/etc/ngrok.yml" + # volumes: + # - ./ngrok.yml:/etc/ngrok.yml + # ports: + # - 4040:4040 + #depends_on: + # api: + # condition: service_healthy + # network_mode: "host" docs: build: diff --git a/docker-compose.source.yml b/docker-compose.source.yml index 52efe86a7..bcbeaf32e 100644 --- a/docker-compose.source.yml +++ b/docker-compose.source.yml @@ -33,13 +33,13 @@ services: DOPPLER_TOKEN: ${DOPPLER_TOKEN_API} DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?ssl=false DISTRIBUTION: ${DISTRIBUTION} + WEBHOOK_INGRESS: ${WEBHOOK_INGRESS} JWT_SECRET: ${JWT_SECRET} REDIS_HOST: ${REDIS_HOST} REDIS_USER: ${REDIS_USER} REDIS_PASS: ${REDIS_PASS} BACKEND_PORT: ${BACKEND_PORT} REDIS_DB: ${REDIS_DB} - WEBHOOK_INGRESS: ${WEBHOOK_INGRESS} ENCRYPT_CRYPTO_SECRET_KEY: ${ENCRYPT_CRYPTO_SECRET_KEY} HUBSPOT_CRM_CLOUD_CLIENT_ID: ${HUBSPOT_CRM_CLOUD_CLIENT_ID} HUBSPOT_CRM_CLOUD_CLIENT_SECRET: ${HUBSPOT_CRM_CLOUD_CLIENT_SECRET} diff --git a/docker-compose.yml b/docker-compose.yml index ed87a9316..62dbcfabc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,13 +27,13 @@ services: environment: DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}?ssl=false DISTRIBUTION: ${DISTRIBUTION} + WEBHOOK_INGRESS: ${WEBHOOK_INGRESS} JWT_SECRET: ${JWT_SECRET} REDIS_HOST: ${REDIS_HOST} REDIS_USER: ${REDIS_USER} REDIS_PASS: ${REDIS_PASS} REDIS_PORT: ${REDIS_PORT} REDIS_DB: ${REDIS_DB} - WEBHOOK_INGRESS: ${WEBHOOK_INGRESS} ENCRYPT_CRYPTO_SECRET_KEY: ${ENCRYPT_CRYPTO_SECRET_KEY} HUBSPOT_CRM_CLOUD_CLIENT_ID: ${HUBSPOT_CRM_CLOUD_CLIENT_ID} HUBSPOT_CRM_CLOUD_CLIENT_SECRET: ${HUBSPOT_CRM_CLOUD_CLIENT_SECRET} diff --git a/ngrok.yml b/ngrok.yml deleted file mode 100644 index f60f3d752..000000000 --- a/ngrok.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: 2 -authtoken: 2hkEp1JOOyYzutRyUa5f74UWll5_7oDCZH2Rd5bryqKj9geTV -log_level: debug -log: stdout - -tunnels: - api-tunnel: - proto: http - addr: 3000 - domain: prepared-wildcat-infinitely.ngrok-free.app \ No newline at end of file diff --git a/packages/api/prisma/schema.prisma b/packages/api/prisma/schema.prisma index ef9a9158f..7e528d24a 100644 --- a/packages/api/prisma/schema.prisma +++ b/packages/api/prisma/schema.prisma @@ -50,159 +50,6 @@ model webhooks_reponses { webhook_delivery_attempts webhook_delivery_attempts[] } -model crm_deals_stages { - id_crm_deals_stage String @id(map: "pk_crm_deal_stages") @db.Uuid - stage_name String? - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - id_linked_user String? @db.Uuid - remote_id String? - remote_platform String? - crm_deals crm_deals[] -} - -model crm_users { - id_crm_user String @id(map: "pk_crm_users") @db.Uuid - name String? - email String? - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - id_linked_user String? @db.Uuid - remote_id String? - remote_platform String? - crm_companies crm_companies[] - crm_contacts crm_contacts[] - crm_deals crm_deals[] - crm_engagements crm_engagements[] - crm_tasks crm_tasks[] -} - -model cs_attributes { - id_cs_attribute String @id(map: "pk_ct_attributes") @db.Uuid - attribute_slug String - data_type String - id_cs_entity String @db.Uuid -} - -model cs_entities { - id_cs_entity String @id(map: "pk_ct_entities") @db.Uuid - id_connection_strategy String @db.Uuid -} - -model cs_values { - id_cs_value String @id(map: "pk_ct_values") @db.Uuid - value String - id_cs_attribute String @db.Uuid -} - -/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments -model entity { - id_entity String @id(map: "pk_entity") @db.Uuid - ressource_owner_id String @db.Uuid - attribute attribute[] - value value[] -} - -/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments -model remote_data { - id_remote_data String @id(map: "pk_remote_data") @db.Uuid - ressource_owner_id String? @unique(map: "force_unique_ressourceownerid") @db.Uuid - format String? - data String? - created_at DateTime? @db.Timestamp(6) -} - -/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments -model tcg_accounts { - id_tcg_account String @id(map: "pk_tcg_account") @db.Uuid - remote_id String? - name String? - domains String[] - remote_platform String? - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - id_linked_user String? @db.Uuid - tcg_contacts tcg_contacts[] -} - -model tcg_collections { - id_tcg_collection String @id(map: "pk_tcg_collections") @db.Uuid - name String? - description String? - remote_id String? - remote_platform String? - collection_type String? - parent_collection String? @db.Uuid - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - id_linked_user String @db.Uuid -} - -model tcg_teams { - id_tcg_team String @id(map: "pk_tcg_teams") @db.Uuid - remote_id String? - remote_platform String? - name String? - description String? - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - id_linked_user String? @db.Uuid -} - -/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments -model tcg_users { - id_tcg_user String @id(map: "pk_tcg_users") @db.Uuid - name String? - email_address String? - remote_id String? - remote_platform String? - teams String[] - created_at DateTime? @db.Timestamp(6) - modified_at DateTime? @db.Timestamp(6) - id_linked_user String? @db.Uuid - tcg_comments tcg_comments[] -} - -/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments -model managed_webhooks { - id_managed_webhook String @id(map: "pk_managed_webhooks") @db.Uuid - active Boolean - id_connection String @db.Uuid - endpoint String @db.Uuid - api_version String? - active_events String[] - remote_signing_secret String? - modified_at DateTime @db.Timestamp(6) - created_at DateTime @db.Timestamp(6) -} - -model fs_drives { - id_fs_drive String @id(map: "pk_fs_drives") @db.Uuid - remote_created_at DateTime? @db.Timestamp(6) - drive_url String? - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - remote_id String? -} - -/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments -model fs_permissions { - id_fs_permission String @id(map: "pk_fs_permissions") @db.Uuid - remote_id String? - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - user String @db.Uuid - group String @db.Uuid - type String[] - roles String[] -} - -model fs_shared_links { - id_fs_shared_link String @id(map: "pk_fs_shared_links") @db.Uuid - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) -} - model api_keys { id_api_key String @id(map: "id_") @db.Uuid api_key_hash String @unique(map: "unique_api_keys") @@ -266,22 +113,6 @@ model connections { @@index([id_linked_user], map: "fk_connections_to_linkedusersid") } -model connector_sets { - id_connector_set String @id(map: "pk_project_connector") @db.Uuid - crm_hubspot Boolean - crm_zoho Boolean - crm_attio Boolean - crm_pipedrive Boolean - crm_zendesk Boolean - crm_close Boolean - tcg_zendesk Boolean - tcg_jira Boolean - tcg_gorgias Boolean - tcg_gitlab Boolean - tcg_front Boolean - projects projects[] -} - /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments model crm_addresses { id_crm_address String @id(map: "pk_crm_addresses") @db.Uuid @@ -372,6 +203,17 @@ model crm_deals { @@index([id_crm_company], map: "fk_crm_deal_crmcompanyid") } +model crm_deals_stages { + id_crm_deals_stage String @id(map: "pk_crm_deal_stages") @db.Uuid + stage_name String? + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + id_linked_user String? @db.Uuid + remote_id String? + remote_platform String? + crm_deals crm_deals[] +} + /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments model crm_email_addresses { id_crm_email String @id(map: "pk_crm_contact_email_addresses") @db.Uuid @@ -486,6 +328,48 @@ model crm_tasks { @@index([id_crm_deal], map: "fk_crmtask_dealid") } +model crm_users { + id_crm_user String @id(map: "pk_crm_users") @db.Uuid + name String? + email String? + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + id_linked_user String? @db.Uuid + remote_id String? + remote_platform String? + crm_companies crm_companies[] + crm_contacts crm_contacts[] + crm_deals crm_deals[] + crm_engagements crm_engagements[] + crm_tasks crm_tasks[] +} + +model cs_attributes { + id_cs_attribute String @id(map: "pk_ct_attributes") @db.Uuid + attribute_slug String + data_type String + id_cs_entity String @db.Uuid +} + +model cs_entities { + id_cs_entity String @id(map: "pk_ct_entities") @db.Uuid + id_connection_strategy String @db.Uuid +} + +model cs_values { + id_cs_value String @id(map: "pk_ct_values") @db.Uuid + value String + id_cs_attribute String @db.Uuid +} + +/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments +model entity { + id_entity String @id(map: "pk_entity") @db.Uuid + ressource_owner_id String @db.Uuid + attribute attribute[] + value value[] +} + /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments model events { id_event String @id(map: "pk_jobs") @db.Uuid @@ -504,39 +388,6 @@ model events { @@index([id_linked_user], map: "fk_linkeduserid_projectid") } -model fs_files { - id_fs_file String @id(map: "pk_fs_files") @db.Uuid - name String? - type String? - path String? - mime_type String? - size BigInt? - remote_id String? - id_fs_folder String? @db.Uuid - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - id_fs_permission String @db.Uuid - - @@index([id_fs_folder], map: "fk_fs_file_folderid") - @@index([id_fs_permission], map: "fk_fs_file_permissionid") -} - -model fs_folders { - id_fs_folder String @id(map: "pk_fs_folders") @db.Uuid - folder_url String? - size BigInt? - description String? - parent_folder String? @db.Uuid - remote_id String? - created_at DateTime @db.Timestamp(6) - modified_at DateTime @db.Timestamp(6) - id_fs_drive String? @db.Uuid - id_fs_permission String @db.Uuid - - @@index([id_fs_drive], map: "fk_fs_folder_driveid") - @@index([id_fs_permission], map: "fk_fs_folder_permissionid") -} - model invite_links { id_invite_link String @id(map: "pk_invite_links") @db.Uuid status String @@ -591,6 +442,28 @@ model projects { @@index([id_connector_set], map: "fk_connectors_sets") } +/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments +model remote_data { + id_remote_data String @id(map: "pk_remote_data") @db.Uuid + ressource_owner_id String? @unique(map: "force_unique_ressourceownerid") @db.Uuid + format String? + data String? + created_at DateTime? @db.Timestamp(6) +} + +/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments +model tcg_accounts { + id_tcg_account String @id(map: "pk_tcg_account") @db.Uuid + remote_id String? + name String? + domains String[] + remote_platform String? + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + id_linked_user String? @db.Uuid + tcg_contacts tcg_contacts[] +} + /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments model tcg_attachments { id_tcg_attachment String @id(map: "pk_tcg_attachments") @db.Uuid @@ -611,6 +484,19 @@ model tcg_attachments { @@index([id_tcg_ticket], map: "fk_tcg_attachment_tcg_ticketid") } +model tcg_collections { + id_tcg_collection String @id(map: "pk_tcg_collections") @db.Uuid + name String? + description String? + remote_id String? + remote_platform String? + collection_type String? + parent_collection String? @db.Uuid + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + id_linked_user String @db.Uuid +} + /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments model tcg_comments { id_tcg_comment String @id(map: "pk_tcg_comments") @db.Uuid @@ -669,6 +555,17 @@ model tcg_tags { @@index([id_tcg_ticket], map: "fk_tcg_tag_tcg_ticketid") } +model tcg_teams { + id_tcg_team String @id(map: "pk_tcg_teams") @db.Uuid + remote_id String? + remote_platform String? + name String? + description String? + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + id_linked_user String? @db.Uuid +} + /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments model tcg_tickets { id_tcg_ticket String @id(map: "pk_tcg_tickets") @db.Uuid @@ -697,6 +594,20 @@ model tcg_tickets { @@index([id_tcg_user], map: "fk_tcg_ticket_tcg_user") } +/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments +model tcg_users { + id_tcg_user String @id(map: "pk_tcg_users") @db.Uuid + name String? + email_address String? + remote_id String? + remote_platform String? + teams String[] + created_at DateTime? @db.Timestamp(6) + modified_at DateTime? @db.Timestamp(6) + id_linked_user String? @db.Uuid + tcg_comments tcg_comments[] +} + /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments model value { id_value String @id(map: "pk_value") @db.Uuid @@ -731,3 +642,92 @@ model webhook_delivery_attempts { @@index([id_event], map: "fk_webhook_delivery_attempt_eventid") @@index([id_webhooks_reponse], map: "fk_webhook_delivery_attempt_webhook_responseid") } + +model connector_sets { + id_connector_set String @id(map: "pk_project_connector") @db.Uuid + crm_hubspot Boolean + crm_zoho Boolean + crm_attio Boolean + crm_pipedrive Boolean + crm_zendesk Boolean + crm_close Boolean + tcg_zendesk Boolean + tcg_jira Boolean + tcg_gorgias Boolean + tcg_gitlab Boolean + tcg_front Boolean + projects projects[] +} + +/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments +model managed_webhooks { + id_managed_webhook String @id(map: "pk_managed_webhooks") @db.Uuid + active Boolean + id_connection String @db.Uuid + endpoint String @db.Uuid + api_version String? + active_events String[] + remote_signing_secret String? + modified_at DateTime @db.Timestamp(6) + created_at DateTime @db.Timestamp(6) +} + +model fs_drives { + id_fs_drive String @id(map: "pk_fs_drives") @db.Uuid + remote_created_at DateTime? @db.Timestamp(6) + drive_url String? + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + remote_id String? +} + +model fs_files { + id_fs_file String @id(map: "pk_fs_files") @db.Uuid + name String? + type String? + path String? + mime_type String? + size BigInt? + remote_id String? + id_fs_folder String? @db.Uuid + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + id_fs_permission String @db.Uuid + + @@index([id_fs_folder], map: "fk_fs_file_folderid") + @@index([id_fs_permission], map: "fk_fs_file_permissionid") +} + +model fs_folders { + id_fs_folder String @id(map: "pk_fs_folders") @db.Uuid + folder_url String? + size BigInt? + description String? + parent_folder String? @db.Uuid + remote_id String? + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + id_fs_drive String? @db.Uuid + id_fs_permission String @db.Uuid + + @@index([id_fs_drive], map: "fk_fs_folder_driveid") + @@index([id_fs_permission], map: "fk_fs_folder_permissionid") +} + +/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments +model fs_permissions { + id_fs_permission String @id(map: "pk_fs_permissions") @db.Uuid + remote_id String? + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) + user String @db.Uuid + group String @db.Uuid + type String[] + roles String[] +} + +model fs_shared_links { + id_fs_shared_link String @id(map: "pk_fs_shared_links") @db.Uuid + created_at DateTime @db.Timestamp(6) + modified_at DateTime @db.Timestamp(6) +} diff --git a/packages/api/scripts/connectorUpdate.js b/packages/api/scripts/connectorUpdate.js index 3cee6a1c0..f2582b431 100755 --- a/packages/api/scripts/connectorUpdate.js +++ b/packages/api/scripts/connectorUpdate.js @@ -157,9 +157,12 @@ function updateMappingsFile( ) { let fileContent = fs.readFileSync(mappingsFile, 'utf8'); + // Identify where the existing content before the first import starts, to preserve any comments or metadata at the start of the file const firstImportIndex = fileContent.indexOf('import '); const beforeFirstImport = firstImportIndex > -1 ? fileContent.substring(0, firstImportIndex) : ''; + + // Prepare sections of the file content for updates const afterFirstImport = firstImportIndex > -1 ? fileContent.substring(firstImportIndex) @@ -174,80 +177,67 @@ function updateMappingsFile( let newImports = ''; let newInstances = ''; let newMappings = ''; - newServiceDirs.forEach((newServiceName) => { - if ( - !(vertical === 'ticketing' && newServiceName.toLowerCase() === 'zendesk') - ) { + newServiceDirs + .filter( + (newServiceName) => + !( + vertical === 'ticketing' && newServiceName.toLowerCase() === 'zendesk' + ), + ) + .forEach((newServiceName) => { const serviceNameCapitalized = newServiceName.charAt(0).toUpperCase() + newServiceName.slice(1); const objectCapitalized = objectType.charAt(0).toUpperCase() + objectType.slice(1); + const mapperClassName = `${serviceNameCapitalized}${objectCapitalized}Mapper`; const mapperInstanceName = `${newServiceName.toLowerCase()}${objectCapitalized}Mapper`; + // Prepare the import statement and instance declaration const importStatement = `import { ${mapperClassName} } from '../services/${newServiceName}/mappers';\n`; const instanceDeclaration = `const ${mapperInstanceName} = new ${mapperClassName}();\n`; const mappingEntry = ` ${newServiceName.toLowerCase()}: {\n unify: ${mapperInstanceName}.unify.bind(${mapperInstanceName}),\n desunify: ${mapperInstanceName}.desunify.bind(${mapperInstanceName}),\n },\n`; + // Check and append new import if it's not already present if (!fileContent.includes(importStatement)) { newImports += importStatement; } + + // Append instance declaration if not already present before the mapping object if (!beforeMappingObject.includes(instanceDeclaration)) { newInstances += instanceDeclaration; } + + // Prepare and append new mapping entry if not already present in the mapping object if (!mappingObjectContent.includes(` ${newServiceName}: {`)) { newMappings += mappingEntry; } - } - }); + }); + // Combine updates with the original sections of the file content const updatedContentBeforeMapping = - beforeFirstImport + newImports + beforeMappingObject.trim(); + beforeFirstImport + + newImports + + beforeMappingObject.trim() + + '\n\n' + + newInstances; + + // Update the mapping object content with new mappings + const insertionPoint = mappingObjectContent.lastIndexOf('};'); const updatedMappingObjectContent = [ - mappingObjectContent.slice(0, mappingObjectContent.lastIndexOf('};')), + mappingObjectContent.slice(0, insertionPoint), newMappings, - mappingObjectContent.slice(mappingObjectContent.lastIndexOf('};')), + mappingObjectContent.slice(insertionPoint), ].join(''); + // Reassemble the complete updated file content const updatedFileContent = - updatedContentBeforeMapping + - '\n' + - newInstances + - updatedMappingObjectContent; + updatedContentBeforeMapping + updatedMappingObjectContent; + + // Write the updated content back to the file fs.writeFileSync(mappingsFile, updatedFileContent); } -function activateProviders(metadataFilePath, vertical, providerNames) { - let fileContent = fs.readFileSync(metadataFilePath, 'utf8'); - - providerNames.forEach((providerName) => { - // Define the pattern to find the service entry including the "active: false" line within the specified vertical - const pattern = new RegExp( - `'${vertical}': {([\\s\\S]*?)('${providerName}': {([\\s\\S]*?)}),?\\s*active: false`, - 'm', - ); - const match = fileContent.match(pattern); - - if (match && match[0]) { - // Replace "active: false" with "active: true" - const updatedServiceBlock = match[0].replace( - 'active: false', - 'active: true', - ); - - // Replace the original service block with the updated one in the file content - fileContent = fileContent.replace(pattern, updatedServiceBlock); - console.log( - `Service '${providerName}' in '${vertical}' activated successfully.`, - ); - } else { - console.error(`Service '${providerName}' not found in '${vertical}'.`); - } - }); - - // Write the updated content back to the file after all changes - fs.writeFileSync(metadataFilePath, fileContent); -} // Function to extract the array from a file function extractArrayFromFile(filePath, arrayName) { const fileContents = readFileContents(filePath); @@ -310,32 +300,24 @@ function updateEnumFile(enumFilePath, newServiceDirs, vertical) { const match = fileContent.match(enumRegex); if (match && match[1]) { - // Clean up and prepare the existing enum entries let enumEntries = match[1] .trim() .split(/\n/) - .map((entry) => entry.trim()) - .filter((entry) => entry.endsWith(',')) // Ensure all entries end with a comma - .map((entry) => entry.replace(/,$/, '')); // Remove commas for a clean slate - + .map((e) => e.trim()) + .filter((e) => e); const existingEntries = enumEntries.map((entry) => entry.split('=')[0].trim(), ); // Prepare new entries to be added newServiceDirs.forEach((serviceName) => { - const enumEntryName = serviceName.toUpperCase(); + const enumEntryName = serviceName.toUpperCase(); // Assuming the enum entry name is the uppercase service name if (!existingEntries.includes(enumEntryName)) { // Format the new enum entry, assuming you want the name and value to be the same - enumEntries.push(`${enumEntryName} = '${serviceName}'`); + enumEntries.push(`${enumEntryName} = '${serviceName}',`); } }); - // Add commas back to all entries except the last one - enumEntries = enumEntries.map((entry, index, array) => - index === array.length - 1 ? entry : `${entry},`, - ); - // Rebuild the enum content const updatedEnumContent = `export enum ${enumName} {\n ${enumEntries.join( '\n ', @@ -346,21 +328,19 @@ function updateEnumFile(enumFilePath, newServiceDirs, vertical) { // Write the updated content back to the file fs.writeFileSync(enumFilePath, fileContent); + //console.log(`Updated ${enumName} in ${enumFilePath}`); } else { console.error(`Could not find enum ${enumName} in file.`); } } +// New function to update init.sql function updateInitSQLFile(initSQLFile, newServiceDirs, vertical) { - // Read the content of the SQL file let fileContent = fs.readFileSync(initSQLFile, 'utf8'); - - // Find the insert point just before the PRIMARY KEY constraint const insertPoint = fileContent.indexOf( 'CONSTRAINT PK_project_connector PRIMARY KEY', ); - // Handle the case where the constraint is not found if (insertPoint === -1) { console.error( `Could not find the PRIMARY KEY constraint in ${initSQLFile}`, @@ -368,70 +348,65 @@ function updateInitSQLFile(initSQLFile, newServiceDirs, vertical) { return; } - // Prepare new column lines to be inserted - let newLines = newServiceDirs - .map((serviceName) => { - const columnName = `${vertical.toLowerCase()}_${serviceName.toLowerCase()}`; - return ` ${columnName} boolean NOT NULL,\n`; - }) - .join(''); - - // Insert the new column definitions just before the PRIMARY KEY constraint - fileContent = - fileContent.slice(0, insertPoint) + - newLines + - fileContent.slice(insertPoint); - - // Write the modified content back to the file + let newLines = ''; + newServiceDirs.forEach((serviceName) => { + const columnName = `${vertical.toLowerCase()}_${serviceName.toLowerCase()}`; + newLines += ` ${columnName} boolean NOT NULL,\n`; + }); + + fileContent = [ + fileContent.slice(0, insertPoint), + newLines, + fileContent.slice(insertPoint), + ].join(''); + fs.writeFileSync(initSQLFile, fileContent); } +// New function to update seed.sql function updateSeedSQLFile(seedSQLFile, newServiceDirs, vertical) { let fileContent = fs.readFileSync(seedSQLFile, 'utf8'); - // Regex to find the INSERT statement for connector_sets - const regex = /INSERT INTO connector_sets \(([^)]+)\) VALUES/g; - let match; - let lastMatch; - while ((match = regex.exec(fileContent)) !== null) { - lastMatch = match; // Store the last match + const tableInsertPoint = fileContent.indexOf('INSERT INTO connector_sets'); + if (tableInsertPoint === -1) { + console.error( + `Could not find the INSERT INTO connector_sets statement in ${seedSQLFile}`, + ); + return; } - if (!lastMatch) { - console.error('Could not find the INSERT INTO connector_sets statement.'); + const columnInsertPoint = fileContent.indexOf('(', tableInsertPoint); + const valuesInsertPoint = fileContent.indexOf('VALUES', columnInsertPoint); + const rowsInsertPoint = fileContent.indexOf('(', valuesInsertPoint); + + if ( + columnInsertPoint === -1 || + valuesInsertPoint === -1 || + rowsInsertPoint === -1 + ) { + console.error( + `Could not find the column or values insert points in ${seedSQLFile}`, + ); return; } - // Extracting columns and preparing to insert new ones - let columns = lastMatch[1].split(',').map((col) => col.trim()); - let newColumns = newServiceDirs.map( - (serviceName) => `${vertical.toLowerCase()}_${serviceName.toLowerCase()}`, - ); + let newColumns = ''; + let newValues = ''; + newServiceDirs.forEach((serviceName) => { + const columnName = `${vertical.toLowerCase()}_${serviceName.toLowerCase()}`; + newColumns += `${columnName}, `; + newValues += 'TRUE, '; + }); - // Filter out existing new columns to avoid duplication - newColumns = newColumns.filter((nc) => !columns.includes(nc)); - if (newColumns.length > 0) { - // Insert new columns before the closing parenthesis in the columns list - columns = [...columns, ...newColumns]; - let newColumnsSection = columns.join(', '); - - // Replace the old columns section with the new one - fileContent = fileContent.replace(lastMatch[1], newColumnsSection); - - // Update each VALUES section - fileContent = fileContent.replace(/VALUES(.*?);/gs, (match) => { - return match - .replace(/\),\s*\(/g, '),\n (') // Fix line formatting - .replace(/\([^\)]+\)/g, (values) => { - let newValues = newColumns.map(() => 'TRUE').join(', '); - return values.slice(0, -1) + ', ' + newValues + ')'; - }); - }); - } + const updatedFileContent = [ + fileContent.slice(0, columnInsertPoint + 1), + newColumns, + fileContent.slice(columnInsertPoint + 1, rowsInsertPoint + 1), + newValues, + fileContent.slice(rowsInsertPoint + 1), + ].join(''); - // Write the modified content back to the file - fs.writeFileSync(seedSQLFile, fileContent); - console.log('Seed SQL file has been updated successfully.'); + fs.writeFileSync(seedSQLFile, updatedFileContent); } // Main script logic @@ -511,16 +486,10 @@ function updateObjectTypes(baseDir, objectType, vertical) { // Update SQL files const initSQLFile = path.join(__dirname, './init.sql'); - updateInitSQLFile(initSQLFile, newProviders, slugFromCategory(vertical)); + updateInitSQLFile(initSQLFile, newServiceDirs, slugFromCategory(vertical)); const seedSQLFile = path.join(__dirname, './seed.sql'); - updateSeedSQLFile(seedSQLFile, newProviders, slugFromCategory(vertical)); - - const metadata_file = path.join( - __dirname, - '../../shared/src/connectors/metadata.ts', - ); - //activateProviders(metadata_file, vertical, newProviders); + updateSeedSQLFile(seedSQLFile, newServiceDirs, slugFromCategory(vertical)); } // Example usage for ticketing/team diff --git a/packages/api/scripts/init.sql b/packages/api/scripts/init.sql index aeb4df49f..c8fcd5ddb 100644 --- a/packages/api/scripts/init.sql +++ b/packages/api/scripts/init.sql @@ -423,7 +423,7 @@ CREATE TABLE connector_sets tcg_gorgias boolean NOT NULL, tcg_gitlab boolean NOT NULL, tcg_front boolean NOT NULL, -CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set ) + CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set ) ); @@ -432,6 +432,7 @@ CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set ) + -- ************************************** connection_strategies CREATE TABLE connection_strategies @@ -580,7 +581,6 @@ CREATE TABLE fs_folders CREATE INDEX FK_fs_folder_driveID ON fs_folders ( id_fs_drive -); CREATE INDEX FK_fs_folder_permissionID ON fs_folders ( diff --git a/packages/api/scripts/seed.sql b/packages/api/scripts/seed.sql index afb0d02d3..620985342 100644 --- a/packages/api/scripts/seed.sql +++ b/packages/api/scripts/seed.sql @@ -1,7 +1,7 @@ INSERT INTO users (id_user, identification_strategy, email, password_hash, first_name, last_name) VALUES ('0ce39030-2901-4c56-8db0-5e326182ec6b', 'b2c','local@panora.dev', '$2b$10$Y7Q8TWGyGuc5ecdIASbBsuXMo3q/Rs3/cnY.mLZP4tUgfGUOCUBlG', 'local', 'Panora'); -INSERT INTO connector_sets (id_connector_set, crm_attio, crm_close, crm_hubspot, crm_pipedrive, crm_zendesk, crm_zoho, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab) VALUES +INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab) VALUES ('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), ('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), ('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE); diff --git a/packages/api/src/@core/connections-strategies/connections-strategies.service.ts b/packages/api/src/@core/connections-strategies/connections-strategies.service.ts index c0f29f63f..94a905c59 100644 --- a/packages/api/src/@core/connections-strategies/connections-strategies.service.ts +++ b/packages/api/src/@core/connections-strategies/connections-strategies.service.ts @@ -99,7 +99,7 @@ export class ConnectionsStrategiesService { for (let i = 0; i < attributes.length; i++) { const attribute_slug = attributes[i]; const value = values[i]; - //create all attributes (for oauth => client_id, client_secret, subdomain ??) + //create all attributes (for oauth => client_id, client_secret) const attribute_ = await this.prisma.cs_attributes.create({ data: { id_cs_attribute: uuidv4(), diff --git a/packages/api/src/ticketing/@webhook/zendesk/handler.ts b/packages/api/src/ticketing/@webhook/zendesk/handler.ts index 31c5b05e6..87bdbafd3 100644 --- a/packages/api/src/ticketing/@webhook/zendesk/handler.ts +++ b/packages/api/src/ticketing/@webhook/zendesk/handler.ts @@ -81,13 +81,6 @@ export class ZendeskHandlerService { }, }; - this.logger.log( - `Logging data with token: ${this.cryptoService.decrypt( - conn.access_token, - )} to endpoint :${conn.account_url}/webhooks` + - JSON.stringify(body_data), - ); - this.logger.log('Creating basic webhook... '); const resp = await axios.post( @@ -220,6 +213,10 @@ export class ZendeskHandlerService { field: 'priority', operator: 'changed', }, + { + field: 'status', + value: 'changed', + }, { field: 'update_type', value: 'Create', diff --git a/packages/shared/src/connectors/enum.ts b/packages/shared/src/connectors/enum.ts index 60a861084..7c3a770e9 100644 --- a/packages/shared/src/connectors/enum.ts +++ b/packages/shared/src/connectors/enum.ts @@ -7,7 +7,7 @@ export enum CrmConnectors { CLOSE = 'close' } -export enum TicketingConnectors { +export enum TicketingConnectors { ZENDESK = 'zendesk', FRONT = 'front', GITHUB = 'github',