Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix project connectors inside code #486

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions docs/open-source/contributors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ We made a docker file that builds Panora from sources, specifically to help you
</Info>
You have the option to manage a custom 3rd party OAuth App.

**Each custom 3rd party environment variable must be of the form `PROVIDER_VERTICAL_SOFTWAREMODE_ATTRIBUTE` where**
**Each custom 3rd party environment variable must be of the form `PROVIDER_category_SOFTWAREMODE_ATTRIBUTE` where**

- `PROVIDER` is any 3rd party name
- `VERTICAL` is for example [CRM, TICKETING, MARKETINGAUTOMATION, ...]
- `category` is for example [CRM, TICKETING, MARKETINGAUTOMATION, ...]
Comment on lines +28 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify the environment variable format.

The explanation of the environment variable format is clear, but it might be helpful to provide a brief description or link to documentation on what each component (PROVIDER, category, SOFTWAREMODE, ATTRIBUTE) represents. This could improve understanding for new contributors.

- `SOFTWAREMODE` is [ CLOUD, ONPREMISE ]
- `ATTRIBUTE` is for example [ CLIENT_ID, CLIENT_SECRET, SUBDOMAIN, ... ]

Expand Down Expand Up @@ -64,7 +64,7 @@ Make sure you are inside `packages/api/src` where the server lives !

_Ie: Slack, Hubspot, Jira, Shopify ..._

First choose wisely which vertical the 3rd party belongs to among these:
First choose wisely which category the 3rd party belongs to among these:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comma for clarity.

- Ie: Slack, Hubspot, Jira, Shopify ...
+ Ie: Slack, Hubspot, Jira, Shopify, ...

This minor punctuation addition improves the readability of the list.

Committable suggestion was skipped due to low confidence.


- `crm`
- `ticketing`
Expand All @@ -74,14 +74,16 @@ First choose wisely which vertical the 3rd party belongs to among these:
- `hris`
- `marketingautomation`

You can find all categories inside [`packages/shared/src/categories.ts`](https://github.com/panoratech/Panora/blob/main/packages/shared/src/categories.ts).

<Info>
For the sake of the guide, now on we'll consider adding a 3rd party belonging
to the `crm` vertical.
to the `crm` category.
</Info>

# Step 1: Ensure 3rd party metadata is set

Look into the `packages/shared/src/utils.ts` file and check if the provider you want to build has its metadata set inside the `CONNECTORS_METADATA` object.
Look into the `packages/shared/src/connectors/metadata.ts` file and check if the provider you want to build has its metadata set inside the `CONNECTORS_METADATA` object.

It should be available (if not [contact us](https://app.cal.com/rflih/30)) with `active` field set to `false` meaning the integration has not been built.

Expand All @@ -96,7 +98,7 @@ Actually an integration is built in 2 parts :

_Ie: Contact, Ticket, Deal, Company ..._

For the sake of this guide, let's map the common object `contact` under `crm` vertical to _my3rdParty_ (in reality it would be a real 3rd party name).
For the sake of this guide, let's map the common object `contact` under `crm` category to _my3rdParty_ (in reality it would be a real 3rd party name).

<Info>
**An integration is considered valid when all common objects have been mapped.
Expand Down Expand Up @@ -229,7 +231,7 @@ For the sake of this guide, let's map the common object `contact` under `crm` ve
We built a script that does it in seconds. You can execute the given command from the root directory of Panora.

```bash
cd packages/api && pnpm install && pnpm run validate-connectors --vertical="crm" --objectType="contact"
cd packages/api && pnpm install && pnpm run validate-connectors --category="crm" --objectType="contact"
```

The script will automatically scan the `/crm/contact/services` folder and detect any new service folder so all dependencies and imports are updated across the codebase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
private prisma: PrismaService,
private crypto: EncryptionService,
private configService: ConfigService,
) { }
) {}

async isCustomCredentials(projectId: string, type: string) {
const res = await this.prisma.connection_strategies.findFirst({
Expand Down Expand Up @@ -85,7 +85,7 @@
data_type: 'string', //TODO
},
});
const value_ = await this.prisma.cs_values.create({

Check warning on line 88 in packages/api/src/@core/connections-strategies/connections-strategies.service.ts

View workflow job for this annotation

GitHub Actions / Build and Test (18.x)

'value_' is assigned a value but never used
data: {
id_cs_value: uuidv4(),
value: this.crypto.encrypt(value),
Expand Down Expand Up @@ -230,8 +230,9 @@
data = {
...data,
SCOPE:
CONNECTORS_METADATA[vertical.toLowerCase()][provider.toLowerCase()]
.scopes,
CONNECTORS_METADATA[vertical.toLowerCase()][
provider.toLowerCase()
].scopes,
};
}
/*const isSubdomain = needsSubdomain(
Expand Down Expand Up @@ -337,14 +338,14 @@
values: string[],
) {
try {
console.log("In updateAPI xzx")
console.log('In updateAPI xzx');
const cs = await this.prisma.connection_strategies.findFirst({
where: {
id_connection_strategy: id_cs,
},
});
if (!cs) throw new Error('No connection strategies found !');
const updateCS = await this.prisma.connection_strategies.update({

Check warning on line 348 in packages/api/src/@core/connections-strategies/connections-strategies.service.ts

View workflow job for this annotation

GitHub Actions / Build and Test (18.x)

'updateCS' is assigned a value but never used
where: {
id_connection_strategy: id_cs,
},
Expand All @@ -371,7 +372,7 @@
data_type: 'string', //TODO
},
});
const value_ = await this.prisma.cs_values.updateMany({

Check warning on line 375 in packages/api/src/@core/connections-strategies/connections-strategies.service.ts

View workflow job for this annotation

GitHub Actions / Build and Test (18.x)

'value_' is assigned a value but never used
where: {
id_cs_attribute: id_cs_attribute,
},
Expand All @@ -382,8 +383,8 @@
}
return cs;
} catch (error) {
console.log("Error xzx")
console.log(error)
console.log('Error xzx');
console.log(error);
throw new Error('Update Failed');
}
}
Expand Down
27 changes: 27 additions & 0 deletions packages/api/src/@core/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { LoggerService } from '../logger/logger.service';
import { CreateProjectDto } from './dto/create-project.dto';
import { v4 as uuidv4 } from 'uuid';
import { handleServiceError } from '@@core/utils/errors';
import {
ConnectorCategory,
CONNECTORS_METADATA,
providersArray,
slugFromCategory,
} from '@panora/shared';

@Injectable()
export class ProjectsService {
Expand Down Expand Up @@ -43,6 +49,27 @@ export class ProjectsService {
//id_organization: id_organization,
},
});

const ACTIVE_CONNECTORS = providersArray();
// update project-connectors table for the project
const updateData: any = {
id_project_connector: uuidv4(),
id_project: res.id_project,
};

ACTIVE_CONNECTORS.forEach((connector) => {
if (connector.vertical) {
// Construct the property name using the vertical name
const propertyName = `${slugFromCategory(
connector.vertical as ConnectorCategory,
)}_`;
// Add the property to updateData with a value of true
updateData[propertyName + connector.name] = true;
}
});
await this.prisma.project_connectors.create({
data: updateData,
});
return res;
} catch (error) {
handleServiceError(error, this.logger);
Expand Down
Loading