Skip to content

Commit e3353d9

Browse files
ashutosh-revertjatinsandilya
authored andcommitted
feat: Implement Zoho OAuth via Revert
feat: Create Event and associated contacts (existing and non-existing) in Zoho CRM
1 parent 8ed46b3 commit e3353d9

File tree

17 files changed

+453
-0
lines changed

17 files changed

+453
-0
lines changed

packages/app-store/apps.keys-schemas.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { appKeysSchema as wordpress_zod_ts } from "./wordpress/zod";
4141
import { appKeysSchema as zapier_zod_ts } from "./zapier/zod";
4242
import { appKeysSchema as zoho_bigin_zod_ts } from "./zoho-bigin/zod";
4343
import { appKeysSchema as zohocalendar_zod_ts } from "./zohocalendar/zod";
44+
import { appKeysSchema as zohocrm_revert_zod_ts } from "./zohocrm-revert/zod";
4445
import { appKeysSchema as zohocrm_zod_ts } from "./zohocrm/zod";
4546
import { appKeysSchema as zoomvideo_zod_ts } from "./zoomvideo/zod";
4647

@@ -85,5 +86,6 @@ export const appKeysSchemas = {
8586
"zoho-bigin": zoho_bigin_zod_ts,
8687
zohocalendar: zohocalendar_zod_ts,
8788
zohocrm: zohocrm_zod_ts,
89+
"zohocrm-revert": zohocrm_revert_zod_ts,
8890
zoomvideo: zoomvideo_zod_ts,
8991
};

packages/app-store/apps.metadata.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import wordpress_config_json from "./wordpress/config.json";
8585
import { metadata as zapier__metadata_ts } from "./zapier/_metadata";
8686
import zoho_bigin_config_json from "./zoho-bigin/config.json";
8787
import zohocalendar_config_json from "./zohocalendar/config.json";
88+
import zohocrm_revert_config_json from "./zohocrm-revert/config.json";
8889
import zohocrm_config_json from "./zohocrm/config.json";
8990
import { metadata as zoomvideo__metadata_ts } from "./zoomvideo/_metadata";
9091

@@ -173,5 +174,6 @@ export const appStoreMetadata = {
173174
"zoho-bigin": zoho_bigin_config_json,
174175
zohocalendar: zohocalendar_config_json,
175176
zohocrm: zohocrm_config_json,
177+
"zohocrm-revert": zohocrm_revert_config_json,
176178
zoomvideo: zoomvideo__metadata_ts,
177179
};

packages/app-store/apps.schemas.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { appDataSchema as wordpress_zod_ts } from "./wordpress/zod";
4141
import { appDataSchema as zapier_zod_ts } from "./zapier/zod";
4242
import { appDataSchema as zoho_bigin_zod_ts } from "./zoho-bigin/zod";
4343
import { appDataSchema as zohocalendar_zod_ts } from "./zohocalendar/zod";
44+
import { appDataSchema as zohocrm_revert_zod_ts } from "./zohocrm-revert/zod";
4445
import { appDataSchema as zohocrm_zod_ts } from "./zohocrm/zod";
4546
import { appDataSchema as zoomvideo_zod_ts } from "./zoomvideo/zod";
4647

@@ -85,5 +86,6 @@ export const appDataSchemas = {
8586
"zoho-bigin": zoho_bigin_zod_ts,
8687
zohocalendar: zohocalendar_zod_ts,
8788
zohocrm: zohocrm_zod_ts,
89+
"zohocrm-revert": zohocrm_revert_zod_ts,
8890
zoomvideo: zoomvideo_zod_ts,
8991
};

packages/app-store/apps.server.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ export const apiHandlers = {
8686
"zoho-bigin": import("./zoho-bigin/api"),
8787
zohocalendar: import("./zohocalendar/api"),
8888
zohocrm: import("./zohocrm/api"),
89+
"zohocrm-revert": import("./zohocrm-revert/api"),
8990
zoomvideo: import("./zoomvideo/api"),
9091
};

packages/app-store/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const appStore = {
2323
salesforce: () => import("./salesforce"),
2424
"salesforce-revert": () => import("./salesforce-revert"),
2525
zohocrm: () => import("./zohocrm"),
26+
"zohocrm-revert": () => import("./zohocrm-revert"),
2627
sendgrid: () => import("./sendgrid"),
2728
stripepayment: () => import("./stripepayment"),
2829
tandemvideo: () => import("./tandemvideo"),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
items:
3+
- 1.png
4+
---
5+
6+
{DESCRIPTION}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
3+
import { createDefaultInstallation } from "@calcom/app-store/_utils/installation";
4+
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
5+
import { HttpError } from "@calcom/lib/http-error";
6+
7+
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
8+
import appConfig from "../config.json";
9+
10+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
11+
if (req.method !== "GET") return res.status(405).json({ message: "Method not allowed" });
12+
const appKeys = await getAppKeysFromSlug(appConfig.slug);
13+
14+
let client_id = "";
15+
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
16+
if (!client_id) return res.status(400).json({ message: "ZohoCRM client id missing." });
17+
18+
// Check that user is authenticated
19+
req.session = await getServerSession({ req, res });
20+
const { teamId } = req.query;
21+
const user = req.session?.user;
22+
if (!user) {
23+
throw new HttpError({ statusCode: 401, message: "You must be logged in to do this" });
24+
}
25+
const userId = user.id;
26+
await createDefaultInstallation({
27+
appType: `${appConfig.slug}_other_calendar`,
28+
user,
29+
slug: appConfig.slug,
30+
key: {},
31+
teamId: Number(teamId),
32+
});
33+
const tenantId = teamId ? teamId : userId;
34+
// @TODO check scopes before deployment
35+
const scopes = [
36+
"ZohoCRM.modules.ALL",
37+
"ZohoCRM.settings.ALL",
38+
"ZohoCRM.users.ALL",
39+
"AaaServer.profile.READ",
40+
];
41+
42+
const queryParams = {
43+
scope: scopes.join(","),
44+
client_id,
45+
response_type: "code",
46+
access_type: "offline",
47+
redirect_uri: "http://localhost:3010/oauth-callback/zohocrm",
48+
state: `{%22tenantId%22:%22${tenantId}%22,%22revertPublicToken%22:%22${process.env.REVERT_PUBLIC_TOKEN}%22}`,
49+
};
50+
51+
const urlSearchParams = new URLSearchParams(queryParams);
52+
const queryString = urlSearchParams.toString();
53+
54+
res.status(200).json({
55+
url: `https://accounts.zoho.com/oauth/v2/auth?${queryString}`,
56+
newTab: true,
57+
});
58+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
3+
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
4+
5+
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
6+
import { decodeOAuthState } from "../../_utils/oauth/decodeOAuthState";
7+
import appConfig from "../config.json";
8+
9+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
10+
if (!req.session?.user?.id) {
11+
return res.status(401).json({ message: "You must be logged in to do this" });
12+
}
13+
14+
const state = decodeOAuthState(req);
15+
res.redirect(
16+
getSafeRedirectUrl(state?.returnTo) ??
17+
getInstalledAppPath({ variant: appConfig.variant, slug: appConfig.slug })
18+
);
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as add } from "./add";
2+
export { default as callback } from "./callback";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"/*": "Don't modify slug - If required, do it using cli edit command",
3+
"name": "ZohoCRM",
4+
"slug": "zohocrm-revert",
5+
"type": "zohocrm-revert_other_calendar",
6+
"logo": "icon.svg",
7+
"url": "https://revert.dev",
8+
"variant": "other",
9+
"categories": ["crm"],
10+
"publisher": "Revert.dev",
11+
"email": "[email protected]",
12+
"description": "Zoho CRM is a cloud-based application designed to help your salespeople sell smarter and faster by centralizing customer information, logging their interactions with your company, and automating many of the tasks salespeople do every day",
13+
"isTemplate": false,
14+
"__createdUsingCli": true,
15+
"__template": "basic",
16+
"dirName": "zohocrm-revert"
17+
}

0 commit comments

Comments
 (0)