Skip to content

Commit

Permalink
Merge pull request #489 from panoratech/managed_webhooks
Browse files Browse the repository at this point in the history
🚧 WIP - Managed Webhooks
  • Loading branch information
naelob authored Jun 11, 2024
2 parents 1d40a63 + ddd3992 commit 5a98392
Show file tree
Hide file tree
Showing 79 changed files with 1,189 additions and 474 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ================================================
ENV=dev
DISTRIBUTION=selfhosted # selfhosted or managed
OAUTH_REDIRECT_BASE=http://localhost:3000
PANORA_BASE_API_URL=http://localhost:3000
JWT_SECRET=secret_jwt
ENCRYPT_CRYPTO_SECRET_KEY="0123456789abcdef0123456789abcdef"
#Managed only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
push: false
tags: panoradotdev/backend-api:selfhosted
build-args: |
OAUTH_REDIRECT_BASE=${{ env.OAUTH_REDIRECT_BASE }}
PANORA_BASE_API_URL=${{ env.PANORA_BASE_API_URL }}
DISTRIBUTION=${{ env.DISTRIBUTION }}
ENV=${{ ENV }}
DATABASE_URL=postgresql://${{env.POSTGRES_USER}}:${{secrets.POSTGRES_PASSWORD}}@${{env.POSTGRES_HOST}}:5432/${{env.POSTGRES_DB}}?ssl=false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.export.backend.selfhosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
push: true
tags: panoradotdev/backend-api:selfhosted
build-args: |
OAUTH_REDIRECT_BASE=${{ env.OAUTH_REDIRECT_BASE }}
PANORA_BASE_API_URL=${{ env.PANORA_BASE_API_URL }}
DISTRIBUTION=${{ env.DISTRIBUTION }}
ENV=${{ ENV }}
DATABASE_URL=postgresql://${{env.POSTGRES_USER}}:${{secrets.POSTGRES_PASSWORD}}@${{env.POSTGRES_HOST}}:5432/${{env.POSTGRES_DB}}?ssl=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function CatalogWidget() {
useEffect(() => {
if (data) {
const filteredData = Object.entries(data).reduce((acc, [key, value]) => {
if (key !== 'id_project' && key !== 'id_project_connector') {
if (key !== 'id_connector_set') {
acc[key] = Boolean(value);
}
return acc;
Expand Down
11 changes: 3 additions & 8 deletions apps/client-ts/src/hooks/get/useProjectConnectors.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import config from '@/lib/config';
import { useQuery } from '@tanstack/react-query';
import Cookies from 'js-cookie';

interface ProjectConnectorBase {
id_project: string;
id_project_connector: string;
}

interface ProjectConnector extends ProjectConnectorBase {
interface ProjectConnector {
id_connector_set: string;
[key: string]: boolean | string;
}

const useProjectConnectors = (id: string) => {
return useQuery({
queryKey: ['project-connectors'],
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:
PIPEDRIVE_CRM_CLOUD_CLIENT_SECRET: ${PIPEDRIVE_CRM_CLOUD_CLIENT_SECRET}
ZENDESK_CRM_CLOUD_CLIENT_ID: ${ZENDESK_CRM_CLOUD_CLIENT_ID}
ZENDESK_CRM_CLOUD_CLIENT_SECRET: ${ZENDESK_CRM_CLOUD_CLIENT_SECRET}
OAUTH_REDIRECT_BASE: ${OAUTH_REDIRECT_BASE}
PANORA_BASE_API_URL: ${PANORA_BASE_API_URL}
ZENDESK_TICKETING_CLOUD_CLIENT_ID: ${ZENDESK_TICKETING_CLOUD_CLIENT_ID}
ZENDESK_TICKETING_CLOUD_CLIENT_SECRET: ${ZENDESK_TICKETING_CLOUD_CLIENT_SECRET}
ZENDESK_TICKETING_CLOUD_SUBDOMAIN: ${ZENDESK_TICKETING_CLOUD_SUBDOMAIN}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:
PIPEDRIVE_CRM_CLOUD_CLIENT_SECRET: ${PIPEDRIVE_CRM_CLOUD_CLIENT_SECRET}
ZENDESK_CRM_CLOUD_CLIENT_ID: ${ZENDESK_CRM_CLOUD_CLIENT_ID}
ZENDESK_CRM_CLOUD_CLIENT_SECRET: ${ZENDESK_CRM_CLOUD_CLIENT_SECRET}
OAUTH_REDIRECT_BASE: ${OAUTH_REDIRECT_BASE}
PANORA_BASE_API_URL: ${PANORA_BASE_API_URL}
ZENDESK_TICKETING_CLOUD_CLIENT_ID: ${ZENDESK_TICKETING_CLOUD_CLIENT_ID}
ZENDESK_TICKETING_CLOUD_CLIENT_SECRET: ${ZENDESK_TICKETING_CLOUD_CLIENT_SECRET}
ZENDESK_TICKETING_CLOUD_SUBDOMAIN: ${ZENDESK_TICKETING_CLOUD_SUBDOMAIN}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ services:
PIPEDRIVE_CRM_CLOUD_CLIENT_SECRET: ${PIPEDRIVE_CRM_CLOUD_CLIENT_SECRET}
ZENDESK_CRM_CLOUD_CLIENT_ID: ${ZENDESK_CRM_CLOUD_CLIENT_ID}
ZENDESK_CRM_CLOUD_CLIENT_SECRET: ${ZENDESK_CRM_CLOUD_CLIENT_SECRET}
OAUTH_REDIRECT_BASE: ${OAUTH_REDIRECT_BASE}
PANORA_BASE_API_URL: ${PANORA_BASE_API_URL}
ZENDESK_TICKETING_CLOUD_CLIENT_ID: ${ZENDESK_TICKETING_CLOUD_CLIENT_ID}
ZENDESK_TICKETING_CLOUD_CLIENT_SECRET: ${ZENDESK_TICKETING_CLOUD_CLIENT_SECRET}
ZENDESK_TICKETING_CLOUD_SUBDOMAIN: ${ZENDESK_TICKETING_CLOUD_SUBDOMAIN}
Expand Down
4 changes: 3 additions & 1 deletion docs/open-source/contributors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ For the sake of this guide, let's map the common object `contact` under `crm` ca
- `types.ts` where the 3rd party specific API types are defined
- `mappers.ts` where the mapping between our unified common model and the 3rd party one is handled
<Info>After copying the following code you'll end up with linting/deps errors. It is fixed by our script at Step 2.</Info>

<Steps>
<Step title="Create the index.ts file">
It must implement the `IContactService` interface.
Expand Down Expand Up @@ -226,7 +228,7 @@ For the sake of this guide, let's map the common object `contact` under `crm` ca
</Step>

<Step title="Enable your new service">
After these 3 files are successfully created and filled, you are ready to to fix all dependencies/linting issues that you may have. <br/>
After these 3 files are successfully created and filled, you are ready to fix all dependencies/linting issues that you may have. <br/>
To make sure the service is enabled, dependencies and imports must be added. <br/>
We built a script that does it in seconds. You can execute the given command from the root directory of Panora.

Expand Down
1 change: 0 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"test:e2e": "jest --config ./test/jest-e2e.json",
"ci": "pnpm run lint && pnpm run build",
"copy-types-to-shared": "cp ./exports.ts ../shared/index.ts",
"prisma:seed": "ts-node ./scripts/seed.webapp.ts",
"validate-connectors": "node --experimental-detect-module ./scripts/connectorUpdate.js",
"prebuild-oauth-connector": "node --experimental-detect-module ./scripts/oauthConnector.js"
},
Expand Down
66 changes: 39 additions & 27 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -425,35 +425,20 @@ model linked_users {
@@index([id_project], map: "fk_proectid_linked_users")
}

model project_connectors {
id_project_connector String @id(map: "pk_project_connectors") @db.Uuid
id_project String @db.Uuid
crm_hubspot Boolean
crm_zoho Boolean
crm_zendesk Boolean
crm_pipedrive Boolean
crm_attio Boolean
tcg_zendesk Boolean
tcg_gorgias Boolean
tcg_front Boolean
tcg_jira Boolean
tcg_gitlab Boolean
projects projects @relation(fields: [id_project], references: [id_project], onDelete: NoAction, onUpdate: NoAction, map: "fk_project_connectors")
}

/// 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 projects {
id_project String @id(map: "pk_projects") @db.Uuid
name String
sync_mode String
pull_frequency BigInt?
redirect_url String?
id_user String @db.Uuid
api_keys api_keys[]
connections connections[]
linked_users linked_users[]
project_connectors project_connectors[]
users users @relation(fields: [id_user], references: [id_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_46_1")
id_project String @id(map: "pk_projects") @db.Uuid
name String
sync_mode String
pull_frequency BigInt?
redirect_url String?
id_user String @db.Uuid
id_connector_set String @db.Uuid
api_keys api_keys[]
connections connections[]
linked_users linked_users[]
users users @relation(fields: [id_user], references: [id_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_46_1")
connector_sets connector_sets @relation(fields: [id_connector_set], references: [id_connector_set], onDelete: NoAction, onUpdate: NoAction, map: "fk_project_connectorsetid")
}

/// 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
Expand Down Expand Up @@ -656,3 +641,30 @@ 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
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)
}
36 changes: 0 additions & 36 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ COMMENT ON COLUMN webhooks_reponses.http_status_code IS 'anything that is not 2x





-- ************************************** webhooks_payloads

CREATE TABLE webhooks_payloads
Expand Down Expand Up @@ -234,8 +232,6 @@ COMMENT ON COLUMN managed_webhooks.endpoint IS 'UUID that will be used in the fi





-- ************************************** fs_shared_links

CREATE TABLE fs_shared_links
Expand All @@ -247,12 +243,6 @@ CREATE TABLE fs_shared_links
);








-- ************************************** fs_permissions

CREATE TABLE fs_permissions
Expand Down Expand Up @@ -290,12 +280,6 @@ CREATE TABLE fs_drives
);








-- ************************************** entity

CREATE TABLE entity
Expand Down Expand Up @@ -380,12 +364,6 @@ CREATE TABLE crm_users
);








-- ************************************** crm_deals_stages

CREATE TABLE crm_deals_stages
Expand Down Expand Up @@ -413,7 +391,6 @@ CREATE TABLE connector_sets
(
id_connector_set uuid NOT NULL,
crm_hubspot boolean NOT NULL,
crm_freshsales boolean NOT NULL,
crm_zoho boolean NOT NULL,
crm_attio boolean NOT NULL,
crm_pipedrive boolean NOT NULL,
Expand All @@ -427,11 +404,6 @@ CREATE TABLE connector_sets








-- ************************************** connection_strategies

CREATE TABLE connection_strategies
Expand Down Expand Up @@ -558,8 +530,6 @@ ex 3600 for one hour';





-- ************************************** fs_folders

CREATE TABLE fs_folders
Expand Down Expand Up @@ -588,12 +558,6 @@ CREATE INDEX FK_fs_folder_permissionID ON fs_folders
);








-- ************************************** crm_contacts

CREATE TABLE crm_contacts
Expand Down
2 changes: 1 addition & 1 deletion packages/api/scripts/oauthConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ${providerUpper}ConnectionService implements I${verticalUpper}Conne
});
//reconstruct the redirect URI that was passed in the githubend it must be the same
const REDIRECT_URI = \`\${this.env.getOAuthRredirectBaseUrl()}/connections/oauth/callback\`;
const REDIRECT_URI = \`\${this.env.getPanoraBaseUrl()}/connections/oauth/callback\`;
const CREDENTIALS = (await this.cService.getCredentials(projectId, this.type)) as OAuth2AuthData;
const formData = new URLSearchParams({
Expand Down
24 changes: 4 additions & 20 deletions packages/api/scripts/seed.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
--INSERT INTO organizations (id_organization, name, stripe_customer_id) VALUES
-- ('55222419-795d-4183-8478-361626363e58', 'Acme Inc', 'cust_stripe_acme_56604f75-7bf8-4541-9ab4-5928aade4bb8' );

INSERT INTO users (id_user, identification_strategy, email, password_hash, first_name, last_name) VALUES
('0ce39030-2901-4c56-8db0-5e326182ec6b', 'b2c','[email protected]', '$2b$10$Y7Q8TWGyGuc5ecdIASbBsuXMo3q/Rs3/cnY.mLZP4tUgfGUOCUBlG', 'local', 'Panora');

-- First, insert connector sets
INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_freshsales, crm_zoho, crm_pipedrive, crm_attio, 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),
('852dfff8-ab63-4530-ae49-e4b2924407f8', 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);
INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, 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),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

-- Then, insert projects with a reference to the connector sets
INSERT INTO projects (id_project, name, sync_mode, id_user, id_connector_set) VALUES
('1e468c15-aa57-4448-aa2b-7fed640d1e3d', 'Project 1', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', '1709da40-17f7-4d3a-93a0-96dc5da6ddd7'),
('4c641a21-a7f8-4ffe-b7e8-e7d32db87557', 'Project 2', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', '852dfff8-ab63-4530-ae49-e4b2924407f8'),
('2b198012-c79c-4bb6-971e-9635830e8c15', 'Project 3', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', 'aed0f856-f802-4a79-8640-66d441581a99');

-- DO $$
-- DECLARE
--org_id UUID;
--BEGIN
--SELECT id_organization INTO org_id FROM organizations WHERE name = 'Acme Inc';
--INSERT INTO projects (id_project, name, id_organization, sync_mode) VALUES
--('1e468c15-aa57-4448-aa2b-7fed640d1e3d', 'Project 1', org_id, 'pool'),
--('4c641a21-a7f8-4ffe-b7e8-e7d32db87557', 'Project 2', org_id, 'pool'),
--('2b198012-c79c-4bb6-971e-9635830e8c15', 'Project 3', org_id, 'pool');
--END $$;
Loading

0 comments on commit 5a98392

Please sign in to comment.