Skip to content

Commit

Permalink
🚑 Fix with new docker
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Apr 14, 2024
1 parent 3fb2d3d commit a439592
Show file tree
Hide file tree
Showing 110 changed files with 2,363 additions and 907 deletions.
25 changes: 18 additions & 7 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ services:
JIRA_SERVICE_MGMT_TICKETING_CLIENT_SECRET: ${JIRA_SERVICE_MGMT_TICKETING_CLIENT_SECRET}
LINEAR_TICKETING_CLIENT_ID: ${LINEAR_TICKETING_CLIENT_ID}
LINEAR_TICKETING_CLIENT_SECRET: ${LINEAR_TICKETING_CLIENT_SECRET}
AFFINITY_CRM_CLIENT_ID: ${AFFINITY_CRM_CLIENT_ID}
AFFINITY_CRM_CLIENT_SECRET: ${AFFINITY_CRM_CLIENT_SECRET}
ACCELO_CRM_CLIENT_ID: ${ACCELO_CRM_CLIENT_ID}
ACCELO_CRM_CLIENT_SECRET: ${ACCELO_CRM_CLIENT_SECRET}
ACCELO_CRM_SUBDOMAIN: ${ACCELO_CRM_SUBDOMAIN}
Expand All @@ -77,20 +75,33 @@ services:
CLOSE_CRM_CLIENT_SECRET: ${CLOSE_CRM_CLIENT_SECRET}
COPPER_CRM_CLIENT_ID: ${COPPER_CRM_CLIENT_ID}
COPPER_CRM_CLIENT_SECRET: ${COPPER_CRM_CLIENT_SECRET}
INSIGHTLY_CRM_CLIENT_ID: ${INSIGHTLY_CRM_CLIENT_ID}
INSIGHTLY_CRM_CLIENT_SECRET: ${INSIGHTLY_CRM_CLIENT_SECRET}
KEAP_CRM_CLIENT_ID: ${KEAP_CRM_CLIENT_ID}
KEAP_CRM_CLIENT_SECRET: ${KEAP_CRM_CLIENT_SECRET}
SUGARCRM_CRM_CLIENT_ID: ${SUGARCRM_CRM_CLIENT_ID}
SUGARCRM_CRM_CLIENT_SECRET: ${SUGARCRM_CRM_CLIENT_SECRET}
SUGARCRM_CRM_SUBDOMAIN: ${SUGARCRM_CRM_SUBDOMAIN}
TEAMLEADER_CRM_CLIENT_ID: ${TEAMLEADER_CRM_CLIENT_ID}
TEAMLEADER_CRM_CLIENT_SECRET: ${TEAMLEADER_CRM_CLIENT_SECRET}
TEAMWORK_CRM_CLIENT_ID: ${TEAMWORK_CRM_CLIENT_ID}
TEAMWORK_CRM_CLIENT_SECRET: ${TEAMWORK_CRM_CLIENT_SECRET}
AHA_TICKETING_CLIENT_ID: ${AHA_TICKETING_CLIENT_ID}
AHA_TICKETING_CLIENT_SECRET: ${AHA_TICKETING_CLIENT_SECRET}
AHA_TICKETING_SUBDOMAIN: ${AHA_TICKETING_SUBDOMAIN}
WRIKE_TICKETING_CLOUD_CLIENT_ID: ${WRIKE_TICKETING_CLOUD_CLIENT_ID}
WRIKE_TICKETING_CLOUD_CLIENT_SECRET: ${WRIKE_TICKETING_CLOUD_CLIENT_SECRET}
ASANA_TICKETING_CLOUD_CLIENT_ID: ${ASANA_TICKETING_CLOUD_CLIENT_ID}
ASANA_TICKETING_CLOUD_CLIENT_SECRET: ${ASANA_TICKETING_CLOUD_CLIENT_SECRET}
PENNYLANE_ACCOUNTING_CLOUD_CLIENT_ID: ${PENNYLANE_ACCOUNTING_CLOUD_CLIENT_ID}
PENNYLANE_ACCOUNTING_CLOUD_CLIENT_SECRET: ${PENNYLANE_ACCOUNTING_CLOUD_CLIENT_SECRET}
FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_ID: ${FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_ID}
FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET: ${FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET}
FREEAGENT_ACCOUNTING_CLOUD_CLIENT_ID: ${FREEAGENT_ACCOUNTING_CLOUD_CLIENT_ID}
FREEAGENT_ACCOUNTING_CLOUD_CLIENT_SECRET: ${FREEAGENT_ACCOUNTING_CLOUD_CLIENT_SECRET}
SAGE_ACCOUNTING_CLOUD_CLIENT_ID: ${SAGE_ACCOUNTING_CLOUD_CLIENT_ID}
SAGE_ACCOUNTING_CLOUD_CLIENT_SECRET: ${SAGE_ACCOUNTING_CLOUD_CLIENT_SECRET}
MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_ID: ${MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_ID}
MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_SECRET: ${MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_SECRET}
QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_ID: ${QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_ID}
QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET: ${QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET}
WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_ID: ${WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_ID}
WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_SECRET: ${WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_SECRET}
restart:
unless-stopped
ports:
Expand Down
28 changes: 20 additions & 8 deletions docker-compose.source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ services:
JIRA_SERVICE_MGMT_TICKETING_CLIENT_SECRET: ${JIRA_SERVICE_MGMT_TICKETING_CLIENT_SECRET}
LINEAR_TICKETING_CLIENT_ID: ${LINEAR_TICKETING_CLIENT_ID}
LINEAR_TICKETING_CLIENT_SECRET: ${LINEAR_TICKETING_CLIENT_SECRET}
AFFINITY_CRM_CLIENT_ID: ${AFFINITY_CRM_CLIENT_ID}
AFFINITY_CRM_CLIENT_SECRET: ${AFFINITY_CRM_CLIENT_SECRET}
ACCELO_CRM_CLIENT_ID: ${ACCELO_CRM_CLIENT_ID}
ACCELO_CRM_CLIENT_SECRET: ${ACCELO_CRM_CLIENT_SECRET}
ACCELO_CRM_SUBDOMAIN: ${ACCELO_CRM_SUBDOMAIN}
Expand All @@ -77,20 +75,34 @@ services:
CLOSE_CRM_CLIENT_SECRET: ${CLOSE_CRM_CLIENT_SECRET}
COPPER_CRM_CLIENT_ID: ${COPPER_CRM_CLIENT_ID}
COPPER_CRM_CLIENT_SECRET: ${COPPER_CRM_CLIENT_SECRET}
INSIGHTLY_CRM_CLIENT_ID: ${INSIGHTLY_CRM_CLIENT_ID}
INSIGHTLY_CRM_CLIENT_SECRET: ${INSIGHTLY_CRM_CLIENT_SECRET}
KEAP_CRM_CLIENT_ID: ${KEAP_CRM_CLIENT_ID}
KEAP_CRM_CLIENT_SECRET: ${KEAP_CRM_CLIENT_SECRET}
SUGARCRM_CRM_CLIENT_ID: ${SUGARCRM_CRM_CLIENT_ID}
SUGARCRM_CRM_CLIENT_SECRET: ${SUGARCRM_CRM_CLIENT_SECRET}
SUGARCRM_CRM_SUBDOMAIN: ${SUGARCRM_CRM_SUBDOMAIN}
TEAMLEADER_CRM_CLIENT_ID: ${TEAMLEADER_CRM_CLIENT_ID}
TEAMLEADER_CRM_CLIENT_SECRET: ${TEAMLEADER_CRM_CLIENT_SECRET}
TEAMWORK_CRM_CLIENT_ID: ${TEAMWORK_CRM_CLIENT_ID}
TEAMWORK_CRM_CLIENT_SECRET: ${TEAMWORK_CRM_CLIENT_SECRET}
AHA_TICKETING_CLIENT_ID: ${AHA_TICKETING_CLIENT_ID}
AHA_TICKETING_CLIENT_SECRET: ${AHA_TICKETING_CLIENT_SECRET}
AHA_TICKETING_SUBDOMAIN: ${AHA_TICKETING_SUBDOMAIN}
AHA_TICKETING_SUBDOMAIN: ${AHA_TICKETING_SUBDOMAIN}
WRIKE_TICKETING_CLOUD_CLIENT_ID: ${WRIKE_TICKETING_CLOUD_CLIENT_ID}
WRIKE_TICKETING_CLOUD_CLIENT_SECRET: ${WRIKE_TICKETING_CLOUD_CLIENT_SECRET}
ASANA_TICKETING_CLOUD_CLIENT_ID: ${ASANA_TICKETING_CLOUD_CLIENT_ID}
ASANA_TICKETING_CLOUD_CLIENT_SECRET: ${ASANA_TICKETING_CLOUD_CLIENT_SECRET}
PENNYLANE_ACCOUNTING_CLOUD_CLIENT_ID: ${PENNYLANE_ACCOUNTING_CLOUD_CLIENT_ID}
PENNYLANE_ACCOUNTING_CLOUD_CLIENT_SECRET: ${PENNYLANE_ACCOUNTING_CLOUD_CLIENT_SECRET}
FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_ID: ${FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_ID}
FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET: ${FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET}
FREEAGENT_ACCOUNTING_CLOUD_CLIENT_ID: ${FREEAGENT_ACCOUNTING_CLOUD_CLIENT_ID}
FREEAGENT_ACCOUNTING_CLOUD_CLIENT_SECRET: ${FREEAGENT_ACCOUNTING_CLOUD_CLIENT_SECRET}
SAGE_ACCOUNTING_CLOUD_CLIENT_ID: ${SAGE_ACCOUNTING_CLOUD_CLIENT_ID}
SAGE_ACCOUNTING_CLOUD_CLIENT_SECRET: ${SAGE_ACCOUNTING_CLOUD_CLIENT_SECRET}
MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_ID: ${MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_ID}
MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_SECRET: ${MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_SECRET}
QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_ID: ${QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_ID}
QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET: ${QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET}
WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_ID: ${WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_ID}
WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_SECRET: ${WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_SECRET}

restart: unless-stopped
ports:
- 3000:3000
Expand Down
26 changes: 19 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ services:
JIRA_SERVICE_MGMT_TICKETING_CLIENT_SECRET: ${JIRA_SERVICE_MGMT_TICKETING_CLIENT_SECRET}
LINEAR_TICKETING_CLIENT_ID: ${LINEAR_TICKETING_CLIENT_ID}
LINEAR_TICKETING_CLIENT_SECRET: ${LINEAR_TICKETING_CLIENT_SECRET}
AFFINITY_CRM_CLIENT_ID: ${AFFINITY_CRM_CLIENT_ID}
AFFINITY_CRM_CLIENT_SECRET: ${AFFINITY_CRM_CLIENT_SECRET}
ACCELO_CRM_CLIENT_ID: ${ACCELO_CRM_CLIENT_ID}
ACCELO_CRM_CLIENT_SECRET: ${ACCELO_CRM_CLIENT_SECRET}
ACCELO_CRM_SUBDOMAIN: ${ACCELO_CRM_SUBDOMAIN}
Expand All @@ -72,20 +70,34 @@ services:
CLOSE_CRM_CLIENT_SECRET: ${CLOSE_CRM_CLIENT_SECRET}
COPPER_CRM_CLIENT_ID: ${COPPER_CRM_CLIENT_ID}
COPPER_CRM_CLIENT_SECRET: ${COPPER_CRM_CLIENT_SECRET}
INSIGHTLY_CRM_CLIENT_ID: ${INSIGHTLY_CRM_CLIENT_ID}
INSIGHTLY_CRM_CLIENT_SECRET: ${INSIGHTLY_CRM_CLIENT_SECRET}
KEAP_CRM_CLIENT_ID: ${KEAP_CRM_CLIENT_ID}
KEAP_CRM_CLIENT_SECRET: ${KEAP_CRM_CLIENT_SECRET}
SUGARCRM_CRM_CLIENT_ID: ${SUGARCRM_CRM_CLIENT_ID}
SUGARCRM_CRM_CLIENT_SECRET: ${SUGARCRM_CRM_CLIENT_SECRET}
SUGARCRM_CRM_SUBDOMAIN: ${SUGARCRM_CRM_SUBDOMAIN}
TEAMLEADER_CRM_CLIENT_ID: ${TEAMLEADER_CRM_CLIENT_ID}
TEAMLEADER_CRM_CLIENT_SECRET: ${TEAMLEADER_CRM_CLIENT_SECRET}
TEAMWORK_CRM_CLIENT_ID: ${TEAMWORK_CRM_CLIENT_ID}
TEAMWORK_CRM_CLIENT_SECRET: ${TEAMWORK_CRM_CLIENT_SECRET}
AHA_TICKETING_CLIENT_ID: ${AHA_TICKETING_CLIENT_ID}
AHA_TICKETING_CLIENT_SECRET: ${AHA_TICKETING_CLIENT_SECRET}
AHA_TICKETING_SUBDOMAIN: ${AHA_TICKETING_SUBDOMAIN}
WRIKE_TICKETING_CLOUD_CLIENT_ID: ${WRIKE_TICKETING_CLOUD_CLIENT_ID}
WRIKE_TICKETING_CLOUD_CLIENT_SECRET: ${WRIKE_TICKETING_CLOUD_CLIENT_SECRET}
ASANA_TICKETING_CLOUD_CLIENT_ID: ${ASANA_TICKETING_CLOUD_CLIENT_ID}
ASANA_TICKETING_CLOUD_CLIENT_SECRET: ${ASANA_TICKETING_CLOUD_CLIENT_SECRET}
PENNYLANE_ACCOUNTING_CLOUD_CLIENT_ID: ${PENNYLANE_ACCOUNTING_CLOUD_CLIENT_ID}
PENNYLANE_ACCOUNTING_CLOUD_CLIENT_SECRET: ${PENNYLANE_ACCOUNTING_CLOUD_CLIENT_SECRET}
FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_ID: ${FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_ID}
FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET: ${FRESHBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET}
FREEAGENT_ACCOUNTING_CLOUD_CLIENT_ID: ${FREEAGENT_ACCOUNTING_CLOUD_CLIENT_ID}
FREEAGENT_ACCOUNTING_CLOUD_CLIENT_SECRET: ${FREEAGENT_ACCOUNTING_CLOUD_CLIENT_SECRET}
SAGE_ACCOUNTING_CLOUD_CLIENT_ID: ${SAGE_ACCOUNTING_CLOUD_CLIENT_ID}
SAGE_ACCOUNTING_CLOUD_CLIENT_SECRET: ${SAGE_ACCOUNTING_CLOUD_CLIENT_SECRET}
MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_ID: ${MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_ID}
MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_SECRET: ${MONEYBIRD_ACCOUNTING_CLOUD_CLIENT_SECRET}
QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_ID: ${QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_ID}
QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET: ${QUICKBOOKS_ACCOUNTING_CLOUD_CLIENT_SECRET}
WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_ID: ${WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_ID}
WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_SECRET: ${WAVE_FINANCIAL_ACCOUNTING_CLOUD_CLIENT_SECRET}

restart:
unless-stopped
ports:
Expand Down
20 changes: 13 additions & 7 deletions packages/api/scripts/oauthConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ import { ConnectionsStrategiesService } from '@@core/connections-strategies/conn
export type ${providerUpper}OAuthResponse = {
access_token: string;
refresh_token: string;
expires_at: string;
expires_in: string;
token_type: string;
};
@Injectable()
Expand Down Expand Up @@ -126,7 +127,7 @@ export class ${providerUpper}ConnectionService implements I${verticalUpper}Conne
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url: "",
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_at) * 1000,
new Date().getTime() + Number(data.expires_ina) * 1000,
),
status: 'valid',
created_at: new Date(),
Expand All @@ -144,7 +145,7 @@ export class ${providerUpper}ConnectionService implements I${verticalUpper}Conne
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_at) * 1000,
new Date().getTime() + Number(data.expires_ina) * 1000,
),
status: 'valid',
created_at: new Date(),
Expand All @@ -170,11 +171,16 @@ export class ${providerUpper}ConnectionService implements I${verticalUpper}Conne
grant_type: 'refresh_token',
refresh_token: this.cryptoService.decrypt(refreshToken),
});
const { connectionId, refreshToken, projectId } = opts;
const CREDENTIALS = (await this.cService.getCredentials(
projectId,
this.type,
)) as OAuth2AuthData;
const formData = new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: this.cryptoService.decrypt(refreshToken),
});
const res = await axios.post(
"",
formData.toString(),
Expand All @@ -198,7 +204,7 @@ export class ${providerUpper}ConnectionService implements I${verticalUpper}Conne
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_at) * 1000,
new Date().getTime() + Number(data.expires_ina) * 1000,
),
},
});
Expand Down Expand Up @@ -286,7 +292,7 @@ function addProviderToDockerCompose(provider, vertical, dockerComposePath) {

function handleUpdate(vertical, provider) {
createServiceFile(vertical, provider);
addProviderToEnvironmentService(provider, envServiceFilePath);
//addProviderToEnvironmentService(provider, envServiceFilePath);
for (const path of paths) {
addProviderToDockerCompose(provider, vertical, path);
}
Expand All @@ -298,7 +304,7 @@ if (import.meta.url === process.argv[1]) {
const vertical = args[0];
const provider = args[1];
createServiceFile(vertical, provider);
addProviderToEnvironmentService(provider, envServiceFilePath);
//addProviderToEnvironmentService(provider, envServiceFilePath);
for (const path of paths) {
addProviderToDockerCompose(argv.provider, path);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 { ServiceRegistry } from './services/registry.service';
import { AccountingConnectionsService } from './services/accounting.connection.service';
import { PennylaneConnectionService } from './services/pennylane/pennylane.service';
import { FreeagentConnectionService } from './services/freeagent/freeagent.service';
import { FreshbooksConnectionService } from './services/freshbooks/freshbooks.service';
import { MoneybirdConnectionService } from './services/moneybird/moneybird.service';
import { QuickbooksConnectionService } from './services/quickbooks/quickbooks.service';
import { SageConnectionService } from './services/sage/sage.service';
import { WaveFinancialConnectionService } from './services/wave_financial/wave_financial.service';

@Module({
imports: [WebhookModule],
providers: [
AccountingConnectionsService,
PrismaService,
LoggerService,
WebhookService,
EnvironmentService,
EncryptionService,
ServiceRegistry,
ConnectionsStrategiesService,
//PROVIDERS SERVICES,
PennylaneConnectionService,
FreeagentConnectionService,
FreshbooksConnectionService,
MoneybirdConnectionService,
QuickbooksConnectionService,
SageConnectionService,
WaveFinancialConnectionService,
],
exports: [AccountingConnectionsService],
})
export class AccountingConnectionModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Injectable } from '@nestjs/common';
import { NotFoundError, handleServiceError } 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 { CallbackParams, RefreshParams } from '../types';
import { ServiceRegistry } from './registry.service';

@Injectable()
export class AccountingConnectionsService {
constructor(
private serviceRegistry: ServiceRegistry,
private webhook: WebhookService,
private logger: LoggerService,
private prisma: PrismaService,
) {
this.logger.setContext(AccountingConnectionsService.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 handleAccountingCallBack(
projectId: string,
linkedUserId: string,
providerName: string,
code: string,
) {
try {
const serviceName = providerName.toLowerCase();
const service = this.serviceRegistry.getService(serviceName);

if (!service) {
throw new NotFoundError(`Unknown provider, found ${providerName}`);
}
const callbackOpts: CallbackParams = {
linkedUserId: linkedUserId,
projectId: projectId,
code: code,
};
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: '/oauth/callback',
provider: providerName.toLowerCase(),
direction: '0',
timestamp: new Date(),
id_linked_user: linkedUserId,
},
});
//directly send the webhook
await this.webhook.handlePriorityWebhook(
data,
'connection.created',
projectId,
event.id_event,
);
} catch (error) {
handleServiceError(error, this.logger);
}
}

async handleAccountingTokensRefresh(
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 NotFoundError(`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) {
handleServiceError(error, this.logger);
}
}
}
Loading

0 comments on commit a439592

Please sign in to comment.