From 0e556a8452d28a1137017d75ff0c61360cfe75eb Mon Sep 17 00:00:00 2001 From: Rachid F <109089247+rflihxyz@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:18:34 +0000 Subject: [PATCH 1/4] :card_file_box: Removed table webhooks_scope, using a field in webhooks_endpoints --- packages/api/scripts/init.sql | 59 ++++++++++------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/packages/api/scripts/init.sql b/packages/api/scripts/init.sql index d55e3d17e..cb279d2b5 100644 --- a/packages/api/scripts/init.sql +++ b/packages/api/scripts/init.sql @@ -33,23 +33,28 @@ CREATE TABLE webhooks_payloads --- ************************************** webhook_scope +-- ************************************** webhook_endpoints -CREATE TABLE webhook_scope +CREATE TABLE webhook_endpoints ( - id_webhook_scope uuid NOT NULL, - last_update timestamp NULL, - "crm.contact.created" boolean NOT NULL, - "crm.contact.updated" boolean NOT NULL, - "crm.contact.removed" boolean NOT NULL, - "crm.contact.pulled" boolean NOT NULL, - "connection.created" boolean NOT NULL, - "connection.deleted" boolean NOT NULL, - CONSTRAINT PK_webhook_scope PRIMARY KEY ( id_webhook_scope ) + id_webhook_endpoint uuid NOT NULL, + endpoint_description text NULL, + url text NOT NULL, + secret text NOT NULL, + active boolean NOT NULL, + created_at timestamp NOT NULL, + "scope" text NULL, + id_project uuid NOT NULL, + last_update timestamp NULL, + CONSTRAINT PK_webhook_endpoint PRIMARY KEY ( id_webhook_endpoint ) ); +COMMENT ON COLUMN webhook_endpoints.endpoint_description IS 'An optional description of what the webhook is used for'; +COMMENT ON COLUMN webhook_endpoints.secret IS 'a shared secret for secure communication'; +COMMENT ON COLUMN webhook_endpoints.active IS 'a flag indicating whether the webhook is active or not'; +COMMENT ON COLUMN webhook_endpoints."scope" IS 'stringified array with events,'; @@ -172,38 +177,6 @@ CREATE TABLE crm_deals_stages --- ************************************** webhook_endpoints - -CREATE TABLE webhook_endpoints -( - id_webhook_endpoint uuid NOT NULL, - endpoint_description text NULL, - url text NOT NULL, - secret text NOT NULL, - active boolean NOT NULL, - created_at timestamp NOT NULL, - id_project uuid NOT NULL, - last_update timestamp NULL, - id_webhook_scope uuid NULL, - CONSTRAINT PK_webhook_endpoint PRIMARY KEY ( id_webhook_endpoint ), - CONSTRAINT FK_38 FOREIGN KEY ( id_webhook_scope ) REFERENCES webhook_scope ( id_webhook_scope ) -); - -CREATE INDEX FK_we_webhook_scope_ID ON webhook_endpoints -( - id_webhook_scope -); - - - -COMMENT ON COLUMN webhook_endpoints.endpoint_description IS 'An optional description of what the webhook is used for'; -COMMENT ON COLUMN webhook_endpoints.secret IS 'a shared secret for secure communication'; -COMMENT ON COLUMN webhook_endpoints.active IS 'a flag indicating whether the webhook is active or not'; - - - - - -- ************************************** users CREATE TABLE users From ef05bade9b1c1ec124a4d07f849cd456b6b4a168 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Wed, 20 Dec 2023 01:15:25 +0100 Subject: [PATCH 2/4] docker compose update --- docker-compose.yml | 2 ++ packages/api/Dockerfile | 12 ------------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 98541803b..1affbc85c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,6 +35,7 @@ services: DISTRIBUTION: ${DISTRIBUTION} JWT_SECRET: ${JWT_SECRET} REDIS_HOST: redis + ENCRYPT_CRYPTO_SECRET_KEY: ${ENCRYPT_CRYPTO_SECRET_KEY} HUBSPOT_CLIENT_ID: ${HUBSPOT_CLIENT_ID} HUBSPOT_CLIENT_SECRET: ${HUBSPOT_CLIENT_SECRET} ZOHOCRM_CLIENT_ID: ${ZOHOCRM_CLIENT_ID} @@ -43,6 +44,7 @@ services: PIPEDRIVE_CLIENT_SECRET: ${PIPEDRIVE_CLIENT_SECRET} ZENDESK_CLIENT_ID: ${ZENDESK_CLIENT_ID} ZENDESK_CLIENT_SECRET: ${ZENDESK_CLIENT_SECRET} + OAUTH_REDIRECT_BASE: ${OAUTH_REDIRECT_BASE} restart: diff --git a/packages/api/Dockerfile b/packages/api/Dockerfile index f28bdc18e..b4a7a50f0 100644 --- a/packages/api/Dockerfile +++ b/packages/api/Dockerfile @@ -47,18 +47,6 @@ WORKDIR /app COPY --from=installer ./app . - - -ENV HUBSPOT_CLIENT_ID="$HUBSPOT_CLIENT_ID" -ENV HUBSPOT_CLIENT_SECRET="$HUBSPOT_CLIENT_SECRET" -ENV ZOHOCRM_CLIENT_ID="$ZOHOCRM_CLIENT_ID" -ENV ZOHOCRM_CLIENT_SECRET="$ZOHOCRM_CLIENT_SECRET" -ENV PIPEDRIVE_CLIENT_ID="$PIPEDRIVE_CLIENT_ID" -ENV PIPEDRIVE_CLIENT_SECRET="$PIPEDRIVE_CLIENT_SECRET" -ENV ZENDESK_CLIENT_ID="$ZENDESK_CLIENT_ID" -ENV ZENDESK_CLIENT_SECRET="$ZENDESK_CLIENT_SECRET" -ENV OAUTH_REDIRECT_BASE="$OAUTH_REDIRECT_BASE" - # Launching the backend # Maintain the root api folder as context (Breaking) CMD cd /app/packages/api && node dist/src/main.js \ No newline at end of file From 14647462804ed50e85f7f3c4d05e26fdf031dc4e Mon Sep 17 00:00:00 2001 From: Rachid F Date: Wed, 20 Dec 2023 15:06:56 +0100 Subject: [PATCH 3/4] :memo: Update docs update docs --- packages/api/src/@core/utils/crypto.ts | 21 +++++++++++++++++++ packages/api/src/app.service.ts | 6 ++++++ .../api/src/crm/contact/contact.controller.ts | 6 +++--- .../src/crm/contact/types/model.unified.ts | 4 ++-- packages/api/swagger/swagger-spec.json | 16 +++++++++++--- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/packages/api/src/@core/utils/crypto.ts b/packages/api/src/@core/utils/crypto.ts index 95d297b96..89dbdfa31 100644 --- a/packages/api/src/@core/utils/crypto.ts +++ b/packages/api/src/@core/utils/crypto.ts @@ -39,3 +39,24 @@ export function decrypt(encryptedData: string): string { throw new Error('Decrypting error... ' + error); } } + +export function decryptTwo(encryptedData: Buffer): string { + try { + const dataString = encryptedData.toString('utf-8'); + const textParts = dataString.split(':'); + // Extract the IV from the first half of the value + const ivFromText = Buffer.from(textParts.shift() as string, 'hex'); + // Extract the encrypted text without the IV + const encryptedText = textParts.join(':'); + const decipher = crypto.createDecipheriv( + 'aes-256-cbc', + Buffer.from(secretKey), + ivFromText, + ); + let decrypted = decipher.update(encryptedText, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + return decrypted; + } catch (error) { + throw new Error('Decrypting error... ' + error); + } +} diff --git a/packages/api/src/app.service.ts b/packages/api/src/app.service.ts index 257ce8cde..bbc6e1ff8 100644 --- a/packages/api/src/app.service.ts +++ b/packages/api/src/app.service.ts @@ -1,8 +1,14 @@ +import { decrypt, decryptTwo } from '@@core/utils/crypto'; import { Injectable } from '@nestjs/common'; @Injectable() export class AppService { getHello(): string { + console.log('*********************'); + console.log(process.env.REFRESH_TEST); + console.log(decryptTwo(Buffer.from(process.env.REFRESH_TEST || '', 'utf-8'))); + console.log('*********************'); + return 'Hello You Are On The Panora API!'; } } diff --git a/packages/api/src/crm/contact/contact.controller.ts b/packages/api/src/crm/contact/contact.controller.ts index 9df49bb89..c16a3271f 100644 --- a/packages/api/src/crm/contact/contact.controller.ts +++ b/packages/api/src/crm/contact/contact.controller.ts @@ -70,9 +70,9 @@ export class ContactController { summary: 'Create CRM Contact', description: 'Create a contact in any supported CRM', }) - @ApiQuery({ name: 'integrationId', required: true, type: String }) - @ApiQuery({ name: 'linkedUserId', required: true, type: String }) - @ApiQuery({ name: 'remote_data', required: false, type: Boolean }) + @ApiQuery({ name: 'integrationId', required: true, type: String, description: 'The integration ID', example: '6aa2acf3-c244-4f85-848b-13a57e7abf55' }) + @ApiQuery({ name: 'linkedUserId', required: true, type: String, description: 'The linked user ID', example: 'b008e199-eda9-4629-bd41-a01b6195864a' }) + @ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' }) @ApiBody({ type: UnifiedContactInput }) @ApiCustomResponse(ContactResponse) @Post() diff --git a/packages/api/src/crm/contact/types/model.unified.ts b/packages/api/src/crm/contact/types/model.unified.ts index 3e2dc41c0..e8004d954 100644 --- a/packages/api/src/crm/contact/types/model.unified.ts +++ b/packages/api/src/crm/contact/types/model.unified.ts @@ -2,9 +2,9 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Email, Phone } from '.'; export class UnifiedContactInput { - @ApiProperty() + @ApiProperty({ description: 'The first name of the contact' }) first_name: string; - @ApiProperty() + @ApiProperty({ description: 'The last name of the contact' }) last_name: string; @ApiProperty({ type: [Email] }) email_addresses: Email[]; diff --git a/packages/api/swagger/swagger-spec.json b/packages/api/swagger/swagger-spec.json index bab393170..8eeb584fc 100644 --- a/packages/api/swagger/swagger-spec.json +++ b/packages/api/swagger/swagger-spec.json @@ -699,6 +699,8 @@ "name": "integrationId", "required": true, "in": "query", + "description": "The integration ID", + "example": "6aa2acf3-c244-4f85-848b-13a57e7abf55", "schema": { "type": "string" } @@ -707,6 +709,8 @@ "name": "linkedUserId", "required": true, "in": "query", + "description": "The linked user ID", + "example": "b008e199-eda9-4629-bd41-a01b6195864a", "schema": { "type": "string" } @@ -715,6 +719,7 @@ "name": "remote_data", "required": false, "in": "query", + "description": "Set to true to include data from the original CRM software.", "schema": { "type": "boolean" } @@ -984,7 +989,10 @@ "type": "string" }, "scope": { - "type": "string" + "type": "array", + "items": { + "type": "string" + } } }, "required": [ @@ -1239,10 +1247,12 @@ "type": "object", "properties": { "first_name": { - "type": "string" + "type": "string", + "description": "The first name of the contact" }, "last_name": { - "type": "string" + "type": "string", + "description": "The last name of the contact" }, "email_addresses": { "type": "array", From ef30d603c3e6d1a1da1060401115c552cd40d5b9 Mon Sep 17 00:00:00 2001 From: Rachid F Date: Wed, 20 Dec 2023 15:20:14 +0100 Subject: [PATCH 4/4] :memo: Adding exmaples for GET crm/contact query --- packages/api/src/crm/contact/contact.controller.ts | 6 +++--- packages/api/swagger/swagger-spec.json | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/api/src/crm/contact/contact.controller.ts b/packages/api/src/crm/contact/contact.controller.ts index c16a3271f..2da12677f 100644 --- a/packages/api/src/crm/contact/contact.controller.ts +++ b/packages/api/src/crm/contact/contact.controller.ts @@ -34,7 +34,7 @@ export class ContactController { }) @ApiQuery({ name: 'integrationId', required: true, type: String }) @ApiQuery({ name: 'linkedUserId', required: true, type: String }) - @ApiQuery({ name: 'remote_data', required: false, type: Boolean }) + @ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' }) @ApiCustomResponse(ContactResponse) @Get() getContacts( @@ -55,7 +55,7 @@ export class ContactController { description: 'Retrive a contact in any supported CRM', }) @ApiParam({ name: 'id', required: true, type: String }) - @ApiQuery({ name: 'remote_data', required: false, type: Boolean }) + @ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' }) @ApiCustomResponse(ContactResponse) @Get(':id') getContact( @@ -96,7 +96,7 @@ export class ContactController { }) @ApiQuery({ name: 'integrationId', required: true, type: String }) @ApiQuery({ name: 'linkedUserId', required: true, type: String }) - @ApiQuery({ name: 'remote_data', required: false, type: Boolean }) + @ApiQuery({ name: 'remote_data', required: false, type: Boolean, description: 'Set to true to include data from the original CRM software.' }) @ApiBody({ type: UnifiedContactInput, isArray: true }) @ApiCustomResponse(ContactResponse) @Post('batch') diff --git a/packages/api/swagger/swagger-spec.json b/packages/api/swagger/swagger-spec.json index 8eeb584fc..cafb9af39 100644 --- a/packages/api/swagger/swagger-spec.json +++ b/packages/api/swagger/swagger-spec.json @@ -658,6 +658,7 @@ "name": "remote_data", "required": false, "in": "query", + "description": "Set to true to include data from the original CRM software.", "schema": { "type": "boolean" } @@ -803,6 +804,7 @@ "name": "remote_data", "required": false, "in": "query", + "description": "Set to true to include data from the original CRM software.", "schema": { "type": "boolean" } @@ -861,6 +863,7 @@ "name": "remote_data", "required": false, "in": "query", + "description": "Set to true to include data from the original CRM software.", "schema": { "type": "boolean" }