Skip to content

Commit

Permalink
feat: Implement Zoho OAuth via Revert
Browse files Browse the repository at this point in the history
feat: Create Event and associated contacts (existing and non-existing) in Zoho CRM
  • Loading branch information
ashutosh-revert authored and jatinsandilya committed Mar 25, 2024
1 parent dc4a805 commit 1a3cea5
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/app-store/apps.keys-schemas.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { appKeysSchema as wordpress_zod_ts } from "./wordpress/zod";
import { appKeysSchema as zapier_zod_ts } from "./zapier/zod";
import { appKeysSchema as zoho_bigin_zod_ts } from "./zoho-bigin/zod";
import { appKeysSchema as zohocalendar_zod_ts } from "./zohocalendar/zod";
import { appKeysSchema as zohocrm_revert_zod_ts } from "./zohocrm-revert/zod";
import { appKeysSchema as zohocrm_zod_ts } from "./zohocrm/zod";
import { appKeysSchema as zoomvideo_zod_ts } from "./zoomvideo/zod";

Expand Down Expand Up @@ -85,5 +86,6 @@ export const appKeysSchemas = {
"zoho-bigin": zoho_bigin_zod_ts,
zohocalendar: zohocalendar_zod_ts,
zohocrm: zohocrm_zod_ts,
"zohocrm-revert": zohocrm_revert_zod_ts,
zoomvideo: zoomvideo_zod_ts,
};
2 changes: 2 additions & 0 deletions packages/app-store/apps.metadata.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import wordpress_config_json from "./wordpress/config.json";
import { metadata as zapier__metadata_ts } from "./zapier/_metadata";
import zoho_bigin_config_json from "./zoho-bigin/config.json";
import zohocalendar_config_json from "./zohocalendar/config.json";
import zohocrm_revert_config_json from "./zohocrm-revert/config.json";
import zohocrm_config_json from "./zohocrm/config.json";
import { metadata as zoomvideo__metadata_ts } from "./zoomvideo/_metadata";

Expand Down Expand Up @@ -173,5 +174,6 @@ export const appStoreMetadata = {
"zoho-bigin": zoho_bigin_config_json,
zohocalendar: zohocalendar_config_json,
zohocrm: zohocrm_config_json,
"zohocrm-revert": zohocrm_revert_config_json,
zoomvideo: zoomvideo__metadata_ts,
};
2 changes: 2 additions & 0 deletions packages/app-store/apps.schemas.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { appDataSchema as wordpress_zod_ts } from "./wordpress/zod";
import { appDataSchema as zapier_zod_ts } from "./zapier/zod";
import { appDataSchema as zoho_bigin_zod_ts } from "./zoho-bigin/zod";
import { appDataSchema as zohocalendar_zod_ts } from "./zohocalendar/zod";
import { appDataSchema as zohocrm_revert_zod_ts } from "./zohocrm-revert/zod";
import { appDataSchema as zohocrm_zod_ts } from "./zohocrm/zod";
import { appDataSchema as zoomvideo_zod_ts } from "./zoomvideo/zod";

Expand Down Expand Up @@ -85,5 +86,6 @@ export const appDataSchemas = {
"zoho-bigin": zoho_bigin_zod_ts,
zohocalendar: zohocalendar_zod_ts,
zohocrm: zohocrm_zod_ts,
"zohocrm-revert": zohocrm_revert_zod_ts,
zoomvideo: zoomvideo_zod_ts,
};
1 change: 1 addition & 0 deletions packages/app-store/apps.server.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ export const apiHandlers = {
"zoho-bigin": import("./zoho-bigin/api"),
zohocalendar: import("./zohocalendar/api"),
zohocrm: import("./zohocrm/api"),
"zohocrm-revert": import("./zohocrm-revert/api"),
zoomvideo: import("./zoomvideo/api"),
};
1 change: 1 addition & 0 deletions packages/app-store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const appStore = {
salesforce: () => import("./salesforce"),
"salesforce-revert": () => import("./salesforce-revert"),
zohocrm: () => import("./zohocrm"),
"zohocrm-revert": () => import("./zohocrm-revert"),
sendgrid: () => import("./sendgrid"),
stripepayment: () => import("./stripepayment"),
tandemvideo: () => import("./tandemvideo"),
Expand Down
6 changes: 6 additions & 0 deletions packages/app-store/zohocrm-revert/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
items:
- 1.png
---

{DESCRIPTION}
58 changes: 58 additions & 0 deletions packages/app-store/zohocrm-revert/api/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { NextApiRequest, NextApiResponse } from "next";

import { createDefaultInstallation } from "@calcom/app-store/_utils/installation";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { HttpError } from "@calcom/lib/http-error";

import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
import appConfig from "../config.json";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== "GET") return res.status(405).json({ message: "Method not allowed" });
const appKeys = await getAppKeysFromSlug(appConfig.slug);

let client_id = "";
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
if (!client_id) return res.status(400).json({ message: "ZohoCRM client id missing." });

// Check that user is authenticated
req.session = await getServerSession({ req, res });
const { teamId } = req.query;
const user = req.session?.user;
if (!user) {
throw new HttpError({ statusCode: 401, message: "You must be logged in to do this" });
}
const userId = user.id;
await createDefaultInstallation({
appType: `${appConfig.slug}_other_calendar`,
user,
slug: appConfig.slug,
key: {},
teamId: Number(teamId),
});
const tenantId = teamId ? teamId : userId;
// @TODO check scopes before deployment
const scopes = [
"ZohoCRM.modules.ALL",
"ZohoCRM.settings.ALL",
"ZohoCRM.users.ALL",
"AaaServer.profile.READ",
];

const queryParams = {
scope: scopes.join(","),
client_id,
response_type: "code",
access_type: "offline",
redirect_uri: "http://localhost:3010/oauth-callback/zohocrm",
state: `{%22tenantId%22:%22${tenantId}%22,%22revertPublicToken%22:%22${process.env.REVERT_PUBLIC_TOKEN}%22}`,
};

const urlSearchParams = new URLSearchParams(queryParams);
const queryString = urlSearchParams.toString();

res.status(200).json({
url: `https://accounts.zoho.com/oauth/v2/auth?${queryString}`,
newTab: true,
});
}
19 changes: 19 additions & 0 deletions packages/app-store/zohocrm-revert/api/callback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { NextApiRequest, NextApiResponse } from "next";

import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";

import getInstalledAppPath from "../../_utils/getInstalledAppPath";
import { decodeOAuthState } from "../../_utils/oauth/decodeOAuthState";
import appConfig from "../config.json";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!req.session?.user?.id) {
return res.status(401).json({ message: "You must be logged in to do this" });
}

const state = decodeOAuthState(req);
res.redirect(
getSafeRedirectUrl(state?.returnTo) ??
getInstalledAppPath({ variant: appConfig.variant, slug: appConfig.slug })
);
}
2 changes: 2 additions & 0 deletions packages/app-store/zohocrm-revert/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as add } from "./add";
export { default as callback } from "./callback";
17 changes: 17 additions & 0 deletions packages/app-store/zohocrm-revert/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"/*": "Don't modify slug - If required, do it using cli edit command",
"name": "ZohoCRM",
"slug": "zohocrm-revert",
"type": "zohocrm-revert_other_calendar",
"logo": "icon.svg",
"url": "https://revert.dev",
"variant": "other",
"categories": ["crm"],
"publisher": "Revert.dev",
"email": "[email protected]",
"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",
"isTemplate": false,
"__createdUsingCli": true,
"__template": "basic",
"dirName": "zohocrm-revert"
}
2 changes: 2 additions & 0 deletions packages/app-store/zohocrm-revert/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as api from "./api";
export * as lib from "./lib";
Loading

0 comments on commit 1a3cea5

Please sign in to comment.