Skip to content

Commit

Permalink
🐛 Fix connections code
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jun 19, 2024
1 parent 106748c commit 16d73c1
Show file tree
Hide file tree
Showing 82 changed files with 1,619 additions and 457 deletions.
8 changes: 7 additions & 1 deletion apps/magic-link/src/lib/ProviderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ProviderModal = () => {
provider: string;
category: string;
}>();
const [optionalApiUrlForLocal, setOptionalApiUrlForLocal] = useState<string>();
const [startFlow, setStartFlow] = useState(false);
const [preStartFlow, setPreStartFlow] = useState(false);
const [projectId, setProjectId] = useState("");
Expand Down Expand Up @@ -79,8 +80,8 @@ const ProviderModal = () => {
vertical: selectedProvider?.category!,
returnUrl: window.location.href,
projectId: projectId,
optionalApiUrl: optionalApiUrlForLocal,
linkedUserId: magicLink?.id_linked_user as string,
//optionalApiUrl: "https://prepared-wildcat-infinitely.ngrok-free.app", //CONNECTORS_METADATA[selectedProvider?.category!][selectedProvider?.provider!].options?.local_redirect_uri_in_https == true ? "https://prepared-wildcat-infinitely.ngrok-free.app": undefined,
onSuccess: () => {
console.log('OAuth successful');
setOpenSuccessDialog(true);
Expand Down Expand Up @@ -130,10 +131,15 @@ const ProviderModal = () => {

const handleWalletClick = (walletName: string, category: string) => {
setSelectedProvider({provider: walletName.toLowerCase(), category: category.toLowerCase()});
const options = CONNECTORS_METADATA[selectedProvider?.category!][selectedProvider?.provider!].options;
if(options && options.local_redirect_uri_in_https) {
setOptionalApiUrlForLocal('https://prepared-wildcat-infinitely.ngrok-free.app')
}
const logoPath = CONNECTORS_METADATA[category.toLowerCase()][walletName.toLowerCase()].logoPath;
setCurrentProviderLogoURL(logoPath);
setCurrentProvider(walletName.toLowerCase())
setPreStartFlow(true);
setOptionalApiUrlForLocal('')
};

const handleStartFlow = () => {
Expand Down
35 changes: 19 additions & 16 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ services:
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}
NAMELY_HRIS_CLOUD_CLIENT_ID: ${NAMELY_HRIS_CLOUD_CLIENT_ID}
NAMELY_HRIS_CLOUD_CLIENT_SECRET: ${NAMELY_HRIS_CLOUD_CLIENT_SECRET}
NAMELY_HRIS_CLOUD_SUBDOMAIN: ${NAMELY_HRIS_CLOUD_SUBDOMAIN}
restart: unless-stopped
ports:
- 3000:3000
Expand Down Expand Up @@ -225,22 +228,22 @@ services:
volumes:
- .:/app

# ngrok:
# image: ngrok/ngrok:latest
# restart: always
# command:
# - "start"
# - "--all"
# - "--config"
# - "/etc/ngrok.yml"
# volumes:
# - ./ngrok.yml:/etc/ngrok.yml
# ports:
# - 4040:4040
# depends_on:
# api:
# condition: service_healthy
# network_mode: "host"
ngrok:
image: ngrok/ngrok:latest
restart: always
command:
- "start"
- "--all"
- "--config"
- "/etc/ngrok.yml"
volumes:
- ./ngrok.yml:/etc/ngrok.yml
ports:
- 4040:4040
depends_on:
api:
condition: service_healthy
network_mode: "host"

docs:
build:
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ services:
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}
NAMELY_HRIS_CLOUD_CLIENT_ID: ${NAMELY_HRIS_CLOUD_CLIENT_ID}
NAMELY_HRIS_CLOUD_CLIENT_SECRET: ${NAMELY_HRIS_CLOUD_CLIENT_SECRET}
NAMELY_HRIS_CLOUD_SUBDOMAIN: ${NAMELY_HRIS_CLOUD_SUBDOMAIN}
restart: unless-stopped
ports:
- 3000:3000
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ services:
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}
NAMELY_HRIS_CLOUD_CLIENT_ID: ${NAMELY_HRIS_CLOUD_CLIENT_ID}
NAMELY_HRIS_CLOUD_CLIENT_SECRET: ${NAMELY_HRIS_CLOUD_CLIENT_SECRET}
NAMELY_HRIS_CLOUD_SUBDOMAIN: ${NAMELY_HRIS_CLOUD_SUBDOMAIN}
restart: unless-stopped
ports:
- 3000:3000
Expand Down
2 changes: 1 addition & 1 deletion ngrok.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 2
authtoken: NGROK_TOKEN
authtoken: NGROK_AUTH_TOKEN
log_level: debug
log: stdout

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,7 @@ export class ConnectionsStrategiesService {
return res;
}
} catch (error) {
throwTypedError(
new ConnectionStrategiesError({
name: 'GET_CREDENTIALS_ERROR',
message: 'ConnectionsStrategiesService.getCredentials() call failed',
cause: error,
}),
this.logger,
);
throw error;
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/@core/connections/@utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ export class ConnectionUtils {
}
return id_linked_user;
}

applyPanoraDelimiter(values: string[]): string {
return values.join('panoradelimiter');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@ export class AccountingConnectionsService {
event.id_event,
);
} catch (error) {
throwTypedError(
new ConnectionsError({
name: 'HANDLE_OAUTH_CALLBACK_CRM',
message:
'AccountingConnectionsService.handleAccountingOAuthCallBack() call failed',
cause: error,
}),
this.logger,
);
throw error;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class FreeagentConnectionService
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url:
CONNECTORS_METADATA['accounting']['freeagent'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['freeagent'].urls
.apiUrl as string,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -119,8 +119,8 @@ export class FreeagentConnectionService
provider_slug: 'freeagent',
vertical: 'accounting',
token_type: 'oauth',
account_url:
CONNECTORS_METADATA['accounting']['freeagent'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['freeagent'].urls
.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export class FreshbooksConnectionService
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url:
CONNECTORS_METADATA['accounting']['freshbooks'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['freshbooks'].urls
.apiUrl as string,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -121,8 +121,8 @@ export class FreshbooksConnectionService
provider_slug: 'freshbooks',
vertical: 'accounting',
token_type: 'oauth',
account_url:
CONNECTORS_METADATA['accounting']['freshbooks'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['freshbooks'].urls
.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class MoneybirdConnectionService
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url:
CONNECTORS_METADATA['accounting']['moneybird'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['moneybird'].urls
.apiUrl as string,
status: 'valid',
created_at: new Date(),
},
Expand All @@ -116,8 +116,8 @@ export class MoneybirdConnectionService
provider_slug: 'moneybird',
vertical: 'accounting',
token_type: 'oauth',
account_url:
CONNECTORS_METADATA['accounting']['moneybird'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['moneybird'].urls
.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
status: 'valid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export class PennylaneConnectionService
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url:
CONNECTORS_METADATA['accounting']['pennylane'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['pennylane'].urls
.apiUrl as string,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -120,8 +120,8 @@ export class PennylaneConnectionService
provider_slug: 'pennylane',
vertical: 'accounting',
token_type: 'oauth',
account_url:
CONNECTORS_METADATA['accounting']['pennylane'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['pennylane'].urls
.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class QuickbooksConnectionService
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url:
CONNECTORS_METADATA['accounting']['quickbooks'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['quickbooks'].urls
.apiUrl as string,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -119,8 +119,8 @@ export class QuickbooksConnectionService
provider_slug: 'quickbooks',
vertical: 'accounting',
token_type: 'oauth',
account_url:
CONNECTORS_METADATA['accounting']['quickbooks'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['quickbooks'].urls
.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export class SageConnectionService implements IAccountingConnectionService {
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url: CONNECTORS_METADATA['accounting']['sage'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['sage'].urls
.apiUrl as string,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -117,7 +118,8 @@ export class SageConnectionService implements IAccountingConnectionService {
provider_slug: 'sage',
vertical: 'accounting',
token_type: 'oauth',
account_url: CONNECTORS_METADATA['accounting']['sage'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['sage'].urls
.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export class WaveFinancialConnectionService
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url:
CONNECTORS_METADATA['accounting']['wave_financial'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['wave_financial']
.urls.apiUrl as string,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -124,8 +124,8 @@ export class WaveFinancialConnectionService
provider_slug: 'wave_financial',
vertical: 'accounting',
token_type: 'oauth',
account_url:
CONNECTORS_METADATA['accounting']['wave_financial'].urls.apiUrl,
account_url: CONNECTORS_METADATA['accounting']['wave_financial']
.urls.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export class XeroConnectionService implements IAccountingConnectionService {
code: code,
redirect_uri: REDIRECT_URI,
});
this.logger.log(
`data 64 is ${Buffer.from(
`${CREDENTIALS.CLIENT_ID}:${CREDENTIALS.CLIENT_SECRET}`,
).toString('base64')}`,
);
const res = await axios.post(
'https://identity.xero.com/connect/token',
formData.toString(),
Expand Down Expand Up @@ -130,7 +135,9 @@ export class XeroConnectionService implements IAccountingConnectionService {
);

//Important Note: Xero asks for a tenantId for which the token is valid for so we append it as a param and it MUST be extracted when making the calls in unified requests
const CUSTOM_ACCOUNT_URL = `${CONNECTORS_METADATA['accounting']['xero'].urls.apiUrl}?xeroTenantId=${res_.data[0].tenantId}`;
const CUSTOM_ACCOUNT_URL = `${
CONNECTORS_METADATA['accounting']['xero'].urls.apiUrl as string
}?xeroTenantId=${res_.data[0].tenantId}`;

let db_res;
const connection_token = uuidv4();
Expand Down Expand Up @@ -183,18 +190,6 @@ export class XeroConnectionService implements IAccountingConnectionService {
}
return db_res;
} catch (error) {
/*throwTypedError(
new ConnectionsError({
name: 'HANDLE_OAUTH_CALLBACK_ACCOUNTING',
message: `XeroConnectionService.handleCallback() call failed ---> ${format3rdPartyError(
'xero',
Action.oauthCallback,
ActionType.POST,
)}`,
cause: error,
}),
this.logger,
);*/
throw error;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { ConnectionsStrategiesService } from '@@core/connections-strategies/conn
import { ConnectionUtils } from '../@utils';
import { GreenhouseConnectionService } from './services/greenhouse/greenhouse.service';
import { AtsConnectionsService } from './services/ats.connection.service';
import { ServiceRegistry } from './registry.service';
import { LeverConnectionService } from './services/lever/lever.service';
import { JobadderConnectionService } from './services/jobadder/jobadder.service';
import { WorkdayConnectionService } from './services/workday/workday.service';
import { AshbyConnectionService } from './services/ashby/ashby.service';
import { ServiceRegistry } from './services/registry.service';
import { BamboohrConnectionService } from './services/bamboohr/bamboohr.service';

@Module({
imports: [WebhookModule],
Expand All @@ -27,6 +30,9 @@ import { JobadderConnectionService } from './services/jobadder/jobadder.service'
GreenhouseConnectionService,
LeverConnectionService,
JobadderConnectionService,
WorkdayConnectionService,
AshbyConnectionService,
BamboohrConnectionService,
],
exports: [AtsConnectionsService],
})
Expand Down
Loading

0 comments on commit 16d73c1

Please sign in to comment.