Skip to content

Commit

Permalink
✨ New features in api
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed May 23, 2024
1 parent b7ff242 commit 7d65840
Show file tree
Hide file tree
Showing 35 changed files with 326 additions and 64 deletions.
34 changes: 19 additions & 15 deletions apps/client-ts/src/components/Configuration/Catalog/CopySnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export const CopySnippet = () => {

const handleCopyLeft = () => {
navigator.clipboard.writeText(
`<DynamicCatalog>
projectId={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'}
returnUrl={'https://acme.inc'}
linkedUserId={'b860d6c1-28f9-485c-86cd-fb09e60f10a2'}
</DynamicCatalog>`
`<PanoraDynamicCatalog
category={"crm"}
projectId={"c9a1b1f8-466d-442d-a95e-11cdd00baf49"}
returnUrl={"https://acme.inc"}
linkedUserId={"b860d6c1-28f9-485c-86cd-fb09e60f10a2"}
/>`
);
toast.success("Code snippet copied", {
action: {
Expand All @@ -45,13 +46,13 @@ export const CopySnippet = () => {

const handleCopyRight = () => {
navigator.clipboard.writeText(
`<PanoraProviderCard>
name={'hubspot'}
vertical={'crm'}
projectId={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'}
returnUrl={'https://acme.inc'}
linkedUserId={'b860d6c1-28f9-485c-86cd-fb09e60f10a2'}
</PanoraProviderCard>`
`<PanoraProviderCard
name={"hubspot"}
category={"crm"}
projectId={"c9a1b1f8-466d-442d-a95e-11cdd00baf49"}
returnUrl={"https://acme.inc"}
linkedUserId={"b860d6c1-28f9-485c-86cd-fb09e60f10a2"}
/>`
);
toast.success("Code snippet copied", {
action: {
Expand Down Expand Up @@ -120,9 +121,12 @@ export const CopySnippet = () => {
<span className="flex flex-col gap-2">
<span className="flex-1">
<span>
{`<DynamicCatalog>`}
{`<PanoraDynamicCatalog>`}
</span>
</span>
<span className="pl-4">
<span className="text-green-800">category</span>{`=crm`}
</span>
<span className="pl-4">
<span className="text-cyan-600">projectId</span>{`={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'}`}
</span>
Expand All @@ -134,7 +138,7 @@ export const CopySnippet = () => {
</span>
<span className="flex-1">
<span>
{`</DynamicCatalog>`}
{`</PanoraDynamicCatalog>`}
</span>
</span>
</span>
Expand Down Expand Up @@ -181,7 +185,7 @@ export const CopySnippet = () => {
<span className="text-lime-500">name</span>{`={'hubspot'}`}
</span>
<span className="pl-4">
<span className="text-fuchsia-200">vertical</span>{`={'crm'}`}
<span className="text-fuchsia-200">category</span>{`={'crm'}`}
</span>
<span className="pl-4">
<span className="text-cyan-600">projectId</span>{`={'c9a1b1f8-466d-442d-a95e-11cdd00baf49'}`}
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/embed-catalog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ icon: "square-terminal"
linkedUserId={"b860d6c1-28f9-485c-86cd-fb09e60f10a2"} # the linked id of the user if already created in Panora system or user's info in your system
/>
)
}
}
```
</CodeGroup>
#### Import the whole connector catalog
Expand Down
30 changes: 28 additions & 2 deletions packages/api/src/@core/connections/@utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrismaClient } from '@prisma/client';
import { WebhookService } from '@@core/webhook/webhook.service';
import { v4 as uuidv4 } from 'uuid';

export type ConnectionMetadata = {
linkedUserId: string;
Expand All @@ -8,7 +8,6 @@ export type ConnectionMetadata = {

export class ConnectionUtils {
private readonly prisma: PrismaClient;
private readonly webhookService: WebhookService;

constructor() {
this.prisma = new PrismaClient();
Expand All @@ -35,4 +34,31 @@ export class ConnectionUtils {
throw new Error(error);
}
}

async getLinkedUserId(
projectId: string,
linkedUserId: string,
): Promise<string> {
const linked_user = await this.prisma.linked_users.findFirst({
where: {
id_linked_user: linkedUserId,
},
});
let id_linked_user: string;
if (!linked_user) {
//create a linked-user out of remote_id
const res = await this.prisma.linked_users.create({
data: {
id_linked_user: uuidv4(),
id_project: projectId,
linked_user_origin_id: linkedUserId,
alias: '',
},
});
id_linked_user = res.id_linked_user;
} else {
id_linked_user = linkedUserId;
}
return id_linked_user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';

export type FreeagentOAuthResponse = {
access_token: string;
Expand All @@ -29,6 +30,7 @@ export class FreeagentConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand Down Expand Up @@ -124,7 +126,12 @@ export class FreeagentConnectionService
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: linkedUserId },
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';

export type FreshbooksOAuthResponse = {
access_token: string;
Expand All @@ -29,6 +30,7 @@ export class FreshbooksConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand Down Expand Up @@ -123,7 +125,12 @@ export class FreshbooksConnectionService
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: linkedUserId },
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';

export type MoneybirdOAuthResponse = {
access_token: string;
Expand All @@ -30,6 +31,7 @@ export class MoneybirdConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand Down Expand Up @@ -94,7 +96,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,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -110,7 +113,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,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand All @@ -122,7 +126,12 @@ export class MoneybirdConnectionService
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: linkedUserId },
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';

export type PennylaneOAuthResponse = {
access_token: string;
Expand All @@ -28,6 +29,7 @@ export class PennylaneConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand Down Expand Up @@ -92,7 +94,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,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_in) * 1000,
),
Expand All @@ -108,7 +111,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,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
Expand All @@ -120,7 +124,12 @@ export class PennylaneConnectionService
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: linkedUserId },
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';

export type QuickbooksOAuthResponse = {
access_token: string;
Expand All @@ -29,6 +30,7 @@ export class QuickbooksConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand Down Expand Up @@ -124,7 +126,12 @@ export class QuickbooksConnectionService
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: linkedUserId },
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';

export type SageOAuthResponse = {
access_token: string;
Expand All @@ -29,6 +30,7 @@ export type SageOAuthResponse = {
@Injectable()
export class SageConnectionService implements IAccountingConnectionService {
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand Down Expand Up @@ -121,7 +123,12 @@ export class SageConnectionService implements IAccountingConnectionService {
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: linkedUserId },
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';

export type WaveFinancialOAuthResponse = {
access_token: string;
Expand All @@ -31,6 +32,7 @@ export class WaveFinancialConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand Down Expand Up @@ -129,7 +131,12 @@ export class WaveFinancialConnectionService
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: linkedUserId },
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
Expand Down
Loading

0 comments on commit 7d65840

Please sign in to comment.