Skip to content

Commit

Permalink
✨ Shared-types
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 6, 2023
1 parent 1a56346 commit aeee8c3
Show file tree
Hide file tree
Showing 19 changed files with 346 additions and 76 deletions.
3 changes: 2 additions & 1 deletion apps/frontend-snippet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"react-dom": "^18.2.0",
"react-loader-spinner": "^5.4.5",
"tailwind-scrollbar-hide": "^1.1.7",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"shared-types": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
16 changes: 0 additions & 16 deletions apps/frontend-snippet/src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
export enum CRM_PROVIDERS {
ZOHO = 'zoho',
ZENDESK = 'zendesk',
HUBSPOT = 'hubspot',
PIPEDRIVE = 'pipedrive',
FRESHSALES = 'freshsales',
}

export enum ACCOUNTING_PROVIDERS {
PENNYLANE = 'pennylane',
FRESHBOOKS = 'freshbooks',
CLEARBOOKS = 'clearbooks',
FREEAGENT = 'freeagent',
SAGE = 'sage',
}

type ProviderConfig = {
clientId: string;
scopes: string;
Expand Down
8 changes: 3 additions & 5 deletions apps/frontend-snippet/src/lib/ProviderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { useEffect, useState } from 'react';
import { TailSpin } from 'react-loader-spinner'
import useOAuth from '../hooks/useOAuth';
import { findProviderByName, providersArray } from '../helpers/utils';

const categories = ['CRM', 'Ticketing', 'Marketing Automation','ATS', 'Accounting', 'File Storage', 'HR & Payroll'];

import {categoriesVerticals} from 'shared-types';

const LoadingOverlay = ({ providerName }: { providerName: string }) => {
const provider = findProviderByName(providerName);
Expand Down Expand Up @@ -35,7 +33,7 @@ const LoadingOverlay = ({ providerName }: { providerName: string }) => {
};

const ProviderModal = () => {
const [selectedCategory, setSelectedCategory] = useState(categories[0]); // Default to the first category
const [selectedCategory, setSelectedCategory] = useState(categoriesVerticals[0] as string); // Default to the first category
const [selectedProvider, setSelectedProvider] = useState('');
const [loading, setLoading] = useState<{
status: boolean; provider: string
Expand Down Expand Up @@ -104,7 +102,7 @@ const ProviderModal = () => {
{!loading.status ?
<div className="p-4 max-h-[32rem] overflow-auto scrollbar-hide">
<div className="flex mb-4 outline-none flex-wrap">
{categories.map((category, index) => (
{categoriesVerticals.map((category, index) => (
<button
key={index}
className={`px-3 py-1 mb-2 mr-1 rounded-full text-xs font-medium transition duration-150 ${selectedCategory === category ? 'bg-indigo-600 hover:bg-indigo-500 ' : 'bg-neutral-700 hover:bg-neutral-600'}`}
Expand Down
3 changes: 2 additions & 1 deletion apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4",
"zustand": "^4.4.7",
"api": "workspace:*"
"api": "workspace:*",
"shared-types": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.3.1",
Expand Down
5 changes: 2 additions & 3 deletions apps/webapp/src/hooks/useProviderProperties.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import config from '@/utils/config';
import { useQuery } from '@tanstack/react-query';
//import { getProviderVertical } from 'api';
import { getProviderVertical } from 'shared-types';

const useProviderProperties = (linkedUserId: string, providerId: string, standardObject: string) => {
return useQuery({
queryKey: ['providerProperties', linkedUserId, providerId, standardObject],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
queryFn: async (): Promise<Record<string, any>[]> => {
//${getProviderVertical(providerId).toLowerCase()}
const response = await fetch(`${config.API_URL}/crm/${standardObject.toLowerCase()}/properties?linkedUserId=${linkedUserId}&providerId=${providerId}`);
const response = await fetch(`${config.API_URL}/${getProviderVertical(providerId).toLowerCase()}/${standardObject.toLowerCase()}/properties?linkedUserId=${linkedUserId}&providerId=${providerId}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
Expand Down
2 changes: 0 additions & 2 deletions packages/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from '@prisma/client';
//export * from './src/@core/utils/types';
//export { getProviderVertical } from './src/@core/utils/providers';
3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"pino-pretty": "^10.2.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"shared-types": "workspace:*"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/@core/connections/connections.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Controller, Get, Query, Res } from '@nestjs/common';
import { Response } from 'express';
import { CrmConnectionsService } from './crm/services/crm-connection.service';
import { ProviderVertical, getProviderVertical } from '@@core/utils/providers';
import { LoggerService } from '@@core/logger/logger.service';
import { handleServiceError } from '@@core/utils/errors';
import { PrismaService } from '@@core/prisma/prisma.service';

import { ProviderVertical, getProviderVertical } from 'shared-types';
@Controller('connections')
export class ConnectionsController {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/@core/passthrough/passthrough.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@nestjs/common';
import { PassThroughRequestDto } from './dto/passthrough.dto';
import { getProviderVertical } from '@@core/utils/providers';
import { domains } from '@@core/utils/types';
import { PassThroughResponse } from './types';
import axios, { AxiosResponse } from 'axios';
import { PrismaService } from '@@core/prisma/prisma.service';
import { v4 as uuidv4 } from 'uuid';
import { decrypt } from '@@core/utils/crypto';
import { getProviderVertical } from 'shared-types';

@Injectable()
export class PassthroughService {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/@core/utils/unification/desunify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CrmObject } from '@crm/@types';
import { ProviderVertical, getProviderVertical } from '../providers';
import { DesunifyReturnType, TargetObject, Unified } from '../types';
import { desunifyCrm } from '@crm/@unification';
import { ProviderVertical, getProviderVertical } from 'shared-types';

/* to insert data
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/@core/utils/unification/unify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CrmObject } from '@crm/@types';
import { ProviderVertical, getProviderVertical } from '../providers';
import { TargetObject, UnifyReturnType, UnifySourceType } from '../types';
import { unifyCrm } from '@crm/@unification';
import { ProviderVertical, getProviderVertical } from 'shared-types';

/* to fetch data
Expand Down
7 changes: 7 additions & 0 deletions packages/shared-types/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
};
9 changes: 9 additions & 0 deletions packages/shared-types/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"editor.formatOnPaste": true,
"editor.formatOnSave": true
}
2 changes: 2 additions & 0 deletions packages/shared-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './src/providers';
export * from './src/enum';
11 changes: 11 additions & 0 deletions packages/shared-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "shared-types",
"main": "index.ts",
"types": "index.ts",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"eslint": "^8.55.0",
"typescript": "^5.3.3"
}
}
27 changes: 27 additions & 0 deletions packages/shared-types/src/enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export enum ProviderVertical {
CRM = 'CRM',
HRIS = 'HRIS',
ATS = 'ATS',
Accounting = 'Accounting',
Ticketing = 'Ticketing',
MarketingAutomation = 'Marketing Automation',
FileStorage = 'File Storage',
Unknown = 'Unknown',
}

export enum CrmProviders {
ZOHO = 'zoho',
ZENDESK = 'zendesk',
HUBSPOT = 'hubspot',
PIPEDRIVE = 'pipedrive',
FRESHSALES = 'freshsales',
}

export enum AccountingProviders {
PENNYLANE = 'pennylane',
FRESHBOOKS = 'freshbooks',
CLEARBOOKS = 'clearbooks',
FREEAGENT = 'freeagent',
SAGE = 'sage',
}

Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import { ProviderVertical } from "./enum";

export const categoriesVerticals = Object.values(ProviderVertical);

export const CRM_PROVIDERS = [
'zoho',
'zendesk',
'hubspot',
'pipedrive',
'freshsales',
];
export const HRIS_PROVIDERS = [];
export const ATS_PROVIDERS = [];
export const ACCOUNTING_PROVIDERS = [];
export const TICKETING_PROVIDERS = [];
export const MARKETING_AUTOMATION_PROVIDERS = [];
export const FILE_STORAGE_PROVIDERS = [];

export enum ProviderVertical {
CRM = 'CRM',
HRIS = 'HRIS',
ATS = 'ATS',
Accounting = 'Accounting',
Ticketing = 'Ticketing',
MarketingAutomation = 'Marketing Automation',
FileStorage = 'File Storage',
Unknown = 'Unknown', // Used if the provider does not match any category
}
export const HRIS_PROVIDERS = [''];
export const ATS_PROVIDERS = [''];
export const ACCOUNTING_PROVIDERS = [''];
export const TICKETING_PROVIDERS = [''];
export const MARKETING_AUTOMATION_PROVIDERS = [''];
export const FILE_STORAGE_PROVIDERS = [''];


export function getProviderVertical(providerName: string): ProviderVertical {
if (CRM_PROVIDERS.includes(providerName)) {
return ProviderVertical.CRM;
Expand Down
14 changes: 14 additions & 0 deletions packages/shared-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"preserveWatchOutput": true,
"skipLibCheck": true,
"noEmit": true,
"strict": true
},
"exclude": ["node_modules"]
}
Loading

0 comments on commit aeee8c3

Please sign in to comment.