Skip to content

Commit

Permalink
🐛 Fix mjs file for sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jun 18, 2024
1 parent 2312f42 commit 106748c
Show file tree
Hide file tree
Showing 15 changed files with 560 additions and 27 deletions.
4 changes: 4 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ services:
FACTORIAL_HRIS_CLOUD_CLIENT_SECRET: ${FACTORIAL_ATS_CLOUD_CLIENT_SECRET}
PAYFIT_HRIS_CLOUD_CLIENT_ID: ${PAYFIT_HRIS_CLOUD_CLIENT_ID}
PAYFIT_HRIS_CLOUD_CLIENT_SECRET: ${PAYFIT_HRIS_CLOUD_CLIENT_SECRET}
NOTION_MANAGEMENT_CLOUD_CLIENT_ID: ${NOTION_MANAGEMENT_CLOUD_CLIENT_ID}
NOTION_MANAGEMENT_CLOUD_CLIENT_SECRET: ${NOTION_MANAGEMENT_CLOUD_CLIENT_SECRET}
SLACK_MANAGEMENT_CLOUD_CLIENT_ID: ${SLACK_MANAGEMENT_CLOUD_CLIENT_ID}
SLACK_MANAGEMENT_CLOUD_CLIENT_SECRET: ${SLACK_MANAGEMENT_CLOUD_CLIENT_SECRET}
restart: unless-stopped
ports:
- 3000:3000
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ services:
FACTORIAL_HRIS_CLOUD_CLIENT_SECRET: ${FACTORIAL_ATS_CLOUD_CLIENT_SECRET}
PAYFIT_HRIS_CLOUD_CLIENT_ID: ${PAYFIT_HRIS_CLOUD_CLIENT_ID}
PAYFIT_HRIS_CLOUD_CLIENT_SECRET: ${PAYFIT_HRIS_CLOUD_CLIENT_SECRET}

NOTION_MANAGEMENT_CLOUD_CLIENT_ID: ${NOTION_MANAGEMENT_CLOUD_CLIENT_ID}
NOTION_MANAGEMENT_CLOUD_CLIENT_SECRET: ${NOTION_MANAGEMENT_CLOUD_CLIENT_SECRET}
SLACK_MANAGEMENT_CLOUD_CLIENT_ID: ${SLACK_MANAGEMENT_CLOUD_CLIENT_ID}
SLACK_MANAGEMENT_CLOUD_CLIENT_SECRET: ${SLACK_MANAGEMENT_CLOUD_CLIENT_SECRET}
restart: unless-stopped
ports:
- 3000:3000
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ services:
FACTORIAL_HRIS_CLOUD_CLIENT_SECRET: ${FACTORIAL_ATS_CLOUD_CLIENT_SECRET}
PAYFIT_HRIS_CLOUD_CLIENT_ID: ${PAYFIT_HRIS_CLOUD_CLIENT_ID}
PAYFIT_HRIS_CLOUD_CLIENT_SECRET: ${PAYFIT_HRIS_CLOUD_CLIENT_SECRET}
NOTION_MANAGEMENT_CLOUD_CLIENT_ID: ${NOTION_MANAGEMENT_CLOUD_CLIENT_ID}
NOTION_MANAGEMENT_CLOUD_CLIENT_SECRET: ${NOTION_MANAGEMENT_CLOUD_CLIENT_SECRET}
SLACK_MANAGEMENT_CLOUD_CLIENT_ID: ${SLACK_MANAGEMENT_CLOUD_CLIENT_ID}
SLACK_MANAGEMENT_CLOUD_CLIENT_SECRET: ${SLACK_MANAGEMENT_CLOUD_CLIENT_SECRET}
restart: unless-stopped
ports:
- 3000:3000
Expand Down
4 changes: 2 additions & 2 deletions ngrok.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: 2
authtoken:
authtoken: NGROK_TOKEN
log_level: debug
log: stdout

tunnels:
api-tunnel:
proto: http
addr: 3000
domain:
domain: NGROK_DOMAIN
22 changes: 11 additions & 11 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -645,17 +645,17 @@ model webhook_delivery_attempts {

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
crm_zendesk Boolean
crm_close Boolean
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?
crm_zendesk Boolean?
crm_close Boolean?
projects projects[]
}

Expand Down
20 changes: 10 additions & 10 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,16 @@ CREATE TABLE connector_sets
(
id_connector_set uuid NOT NULL,
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
crm_zendesk boolean
crm_close 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,
crm_zendesk boolean,
crm_close boolean,
CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set )
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Module } from '@nestjs/common';
import { PrismaService } from '@@core/prisma/prisma.service';
import { LoggerService } from '@@core/logger/logger.service';
import { WebhookService } from '@@core/webhook/webhook.service';
import { WebhookModule } from '@@core/webhook/webhook.module';
import { EnvironmentService } from '@@core/environment/environment.service';
import { EncryptionService } from '@@core/encryption/encryption.service';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ManagementConnectionsService } from './services/management.connection.service';
import { ServiceRegistry } from './services/registry.service';
import { ConnectionUtils } from '../@utils';
import { NotionConnectionService } from './services/notion/notion.service';
import { SlackConnectionService } from './services/slack/slack.service';
@Module({
imports: [WebhookModule],
providers: [
ManagementConnectionsService,
LoggerService,
WebhookService,
EnvironmentService,
EncryptionService,
ServiceRegistry,
ConnectionsStrategiesService,
ConnectionUtils,
//PROVIDERS SERVICES
NotionConnectionService,
SlackConnectionService,
],
exports: [ManagementConnectionsService],
})
export class ManagementConnectionsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { Injectable } from '@nestjs/common';
import { ConnectionsError, throwTypedError } from '@@core/utils/errors';
import { LoggerService } from '@@core/logger/logger.service';
import { WebhookService } from '@@core/webhook/webhook.service';
import { connections as Connection } from '@prisma/client';
import { PrismaService } from '@@core/prisma/prisma.service';
import { v4 as uuidv4 } from 'uuid';
import { ServiceRegistry } from './registry.service';
import { CallbackParams, RefreshParams } from '@@core/connections/@utils/types';

@Injectable()
export class ManagementConnectionsService {
constructor(
private serviceRegistry: ServiceRegistry,
private webhook: WebhookService,
private logger: LoggerService,
private prisma: PrismaService,
) {
this.logger.setContext(ManagementConnectionsService.name);
}
//STEP 1:[FRONTEND STEP]
//create a frontend SDK snippet in which an authorization embedded link is set up so when users click
// on it to grant access => they grant US the access and then when confirmed
/*const authUrl =
'https://app.hubspot.com/oauth/authorize' +
`?client_id=${encodeURIComponent(CLIENT_ID)}` +
`&scope=${encodeURIComponent(SCOPES)}` +
`&redirect_uri=${encodeURIComponent(REDIRECT_URI)}`;*/ //oauth/callback

// oauth server calls this redirect callback
// WE WOULD HAVE CREATED A DEV ACCOUNT IN THE 5 CRMs (Panora dev account)
// we catch the tmp token and swap it against oauth2 server for access/refresh tokens
// to perform actions on his behalf
// this call pass 1. integrationID 2. CustomerId 3. Panora Api Key
async handleManagementCallBack(
providerName: string,
callbackOpts: CallbackParams,
type_strategy: 'oauth' | 'apikey' | 'basic',
) {
try {
const serviceName = providerName.toLowerCase();

const service = this.serviceRegistry.getService(serviceName);

if (!service) {
throw new ReferenceError(`Unknown provider, found ${providerName}`);
}
const data: Connection = await service.handleCallback(callbackOpts);
const event = await this.prisma.events.create({
data: {
id_event: uuidv4(),
status: 'success',
type: 'connection.created',
method: 'GET',
url: `/${type_strategy}/callback`,
provider: providerName.toLowerCase(),
direction: '0',
timestamp: new Date(),
id_linked_user: callbackOpts.linkedUserId,
},
});
//directly send the webhook
await this.webhook.handlePriorityWebhook(
data,
'connection.created',
callbackOpts.projectId,
event.id_event,
);
} catch (error) {
throwTypedError(
new ConnectionsError({
name: 'HANDLE_OAUTH_CALLBACK_CRM',
message:
'ManagementConnectionsService.handleManagementOAuthCallBack() call failed',
cause: error,
}),
this.logger,
);
}
}

async handleManagementTokensRefresh(
connectionId: string,
providerName: string,
refresh_token: string,
id_project: string,
account_url?: string,
) {
try {
const serviceName = providerName.toLowerCase();
const service = this.serviceRegistry.getService(serviceName);
if (!service) {
throw new ReferenceError(`Unknown provider, found ${providerName}`);
}
const refreshOpts: RefreshParams = {
connectionId: connectionId,
refreshToken: refresh_token,
account_url: account_url,
projectId: id_project,
};
const data = await service.handleTokenRefresh(refreshOpts);
} catch (error) {
throwTypedError(
new ConnectionsError({
name: 'HANDLE_OAUTH_REFRESH_MARKETINGAUTOMATION',
message:
'ManagementConnectionsService.handleManagementTokensRefresh() call failed',
cause: error,
}),
this.logger,
);
}
}
}
Loading

0 comments on commit 106748c

Please sign in to comment.