-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: frontend_snippet > hubspot oauth flow
- Loading branch information
Showing
23 changed files
with
709 additions
and
35 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/api/src/@core/connections/connections.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Controller, Get, Query, Res } from '@nestjs/common'; | ||
import { Response } from 'express'; // Importing the Express Response type for type checking | ||
import { CrmConnectionsService } from './crm/services/crm-connection.service'; | ||
import { ProviderVertical, getProviderVertical } from '../utils/providers'; | ||
|
||
@Controller('connections') | ||
export class ConnectionsController { | ||
constructor(private readonly crmConnectionsService: CrmConnectionsService) {} | ||
|
||
@Get('oauth/callback') | ||
handleCallback( | ||
@Res() res: Response, | ||
@Query('projectId') projectId: string, | ||
@Query('linkedUserId') linkedUserId: string, | ||
@Query('providerName') providerName: string, | ||
@Query('code') code: string, | ||
@Query('returnUrl') returnUrl: string, | ||
@Query('accountURL') zohoAccountURL?: string, | ||
) { | ||
//TODO; ADD VERIFICATION OF PARAMS | ||
switch (getProviderVertical(providerName)) { | ||
case ProviderVertical.CRM: | ||
this.crmConnectionsService.handleCRMCallBack( | ||
projectId, | ||
linkedUserId, | ||
providerName, | ||
code, | ||
zohoAccountURL, | ||
); | ||
case ProviderVertical.ATS: | ||
break; | ||
case ProviderVertical.Accounting: | ||
break; | ||
case ProviderVertical.FileStorage: | ||
break; | ||
case ProviderVertical.HRIS: | ||
break; | ||
case ProviderVertical.MarketingAutomation: | ||
break; | ||
case ProviderVertical.Ticketing: | ||
break; | ||
case ProviderVertical.Unknown: | ||
break; | ||
} | ||
|
||
res.redirect(returnUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { CrmConnectionModule } from './crm/crm-connection.module'; | ||
import { ConnectionsController } from './connections.controller'; | ||
|
||
@Module({ | ||
controllers: [ConnectionsController], | ||
imports: [CrmConnectionModule], | ||
}) | ||
export class ConnectionsModule {} |
30 changes: 0 additions & 30 deletions
30
packages/api/src/@core/connections/crm/crm-connection.controller.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 function getProviderVertical(providerName: string): ProviderVertical { | ||
if (CRM_PROVIDERS.includes(providerName)) { | ||
return ProviderVertical.CRM; | ||
} | ||
if (HRIS_PROVIDERS.includes(providerName)) { | ||
return ProviderVertical.HRIS; | ||
} | ||
if (ATS_PROVIDERS.includes(providerName)) { | ||
return ProviderVertical.ATS; | ||
} | ||
if (ACCOUNTING_PROVIDERS.includes(providerName)) { | ||
return ProviderVertical.Accounting; | ||
} | ||
if (TICKETING_PROVIDERS.includes(providerName)) { | ||
return ProviderVertical.Ticketing; | ||
} | ||
if (MARKETING_AUTOMATION_PROVIDERS.includes(providerName)) { | ||
return ProviderVertical.MarketingAutomation; | ||
} | ||
if (FILE_STORAGE_PROVIDERS.includes(providerName)) { | ||
return ProviderVertical.FileStorage; | ||
} | ||
return ProviderVertical.Unknown; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CLIENT_ID= #hubspot client id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "frontend-snippet", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.15", | ||
"@types/react-dom": "^18.2.7", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"@vitejs/plugin-react": "^4.0.3", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.3", | ||
"typescript": "^5.0.2", | ||
"vite": "^4.4.5" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import './App.css' | ||
import useOAuth from './hooks/useOAuth'; | ||
|
||
const CLIENT_ID = import.meta.env.VITE_CLIENT_ID; // Replace with your OAuth client ID | ||
const SCOPES = 'crm.lists.read%20crm.objects.contacts.read%20crm.objects.contacts.write%20crm.objects.custom.read%20crm.objects.custom.write%20crm.objects.companies.write%20crm.schemas.contacts.read%20crm.objects.feedback_submissions.read%20crm.lists.write%20crm.objects.companies.read%20crm.objects.deals.read%20crm.objects.deals.write%20crm.schemas.contacts.write'; // Replace with your requested scopes | ||
const REDIRECT_URI = 'http://localhost:3000/oauth/callback'; // Replace with your redirect URI | ||
|
||
function App() { | ||
const { open, isReady } = useOAuth({ | ||
linkToken: 'ADD_GENERATED_LINK_TOKEN', // Replace with your link token | ||
clientId: CLIENT_ID!, | ||
scopes: SCOPES, | ||
redirectUri: REDIRECT_URI, | ||
onSuccess: () => console.log('OAuth successful') | ||
}); | ||
return ( | ||
<> | ||
<h1>Integrations Flow</h1> | ||
<div className="card"> | ||
<button disabled={!isReady} onClick={open}> | ||
Start OAuth Flow | ||
</button> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default App |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
type UseOAuthProps = { | ||
linkToken: string; | ||
clientId: string; // Your OAuth client ID | ||
scopes: string; // The scopes you are requesting | ||
redirectUri: string; // The redirect URI registered with the OAuth provider | ||
onSuccess: () => void; | ||
}; | ||
|
||
const useOAuth = ({ linkToken, clientId, scopes, redirectUri, onSuccess }: UseOAuthProps) => { | ||
const [isReady, setIsReady] = useState(false); | ||
|
||
useEffect(() => { | ||
// Perform any setup logic here | ||
setTimeout(() => setIsReady(true), 1000); // Simulating async operation | ||
}, []); | ||
|
||
const openModal = () => { | ||
//const authUrl = `https://app-eu1.hubspot.com/oauth/authorize?client_id=${encodeURIComponent(clientId)}&scope=${encodeURIComponent(scopes)}&redirect_uri=${encodeURIComponent(redirectUri)}`; | ||
const authUrl = `https://app-eu1.hubspot.com/oauth/authorize?client_id=${clientId}&redirect_uri=http://localhost:3000/oauth/callback&scope=crm.lists.read%20crm.lists.write` | ||
const width = 600, height = 600; | ||
const left = (window.innerWidth - width) / 2; | ||
const top = (window.innerHeight - height) / 2; | ||
window.open(authUrl, 'OAuth', `width=${width},height=${height},top=${top},left=${left}`); | ||
|
||
// Call the onSuccess function here if needed, or after the OAuth flow is completed | ||
}; | ||
|
||
return { open: openModal, isReady }; | ||
}; | ||
|
||
export default useOAuth; |
Oops, something went wrong.