Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/panoratech/Panora
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 20, 2023
2 parents 28724be + fca393c commit dec7bb1
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 66 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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:
Expand Down
12 changes: 0 additions & 12 deletions packages/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 16 additions & 43 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,';



Expand Down Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions packages/api/src/@core/utils/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as crypto from 'crypto';
import config from './config';

const secretKey = config.ENCRYPT_CRYPTO_SECRET_KEY;
const iv = crypto.randomBytes(16);

export function encrypt(data: string): string {
try {
const cipher = crypto.createCipheriv(
'aes-256-cbc',
Buffer.from(secretKey, 'utf-8'),
iv,
);
let encrypted = cipher.update(data, 'utf8', 'hex');
encrypted += cipher.final('hex');
const encryptedWithIv = iv.toString('hex') + ':' + encrypted; // Prepend IV to the encrypted data
return encryptedWithIv;
} catch (error) {
throw new Error('Encrypting error... ' + error);
}
}

export function decrypt(encryptedData: string): string {
try {
const textParts = encryptedData.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);
}
}

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);
}
}
1 change: 0 additions & 1 deletion packages/api/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { EnvironmentService } from '@@core/environment/environment.service';
import { Injectable } from '@nestjs/common';

@Injectable()
Expand Down
12 changes: 6 additions & 6 deletions packages/api/src/crm/contact/contact.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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()
Expand All @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/crm/contact/types/model.unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
14 changes: 12 additions & 2 deletions packages/api/swagger/swagger-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -699,6 +700,8 @@
"name": "integrationId",
"required": true,
"in": "query",
"description": "The integration ID",
"example": "6aa2acf3-c244-4f85-848b-13a57e7abf55",
"schema": {
"type": "string"
}
Expand All @@ -707,6 +710,8 @@
"name": "linkedUserId",
"required": true,
"in": "query",
"description": "The linked user ID",
"example": "b008e199-eda9-4629-bd41-a01b6195864a",
"schema": {
"type": "string"
}
Expand All @@ -715,6 +720,7 @@
"name": "remote_data",
"required": false,
"in": "query",
"description": "Set to true to include data from the original CRM software.",
"schema": {
"type": "boolean"
}
Expand Down Expand Up @@ -798,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"
}
Expand Down Expand Up @@ -856,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"
}
Expand Down Expand Up @@ -1242,10 +1250,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",
Expand Down

0 comments on commit dec7bb1

Please sign in to comment.