* Upgrade jsforce to 3.6.2 * Refactor connecting to Salesforce * Revert yarn.lock changes * Migrate callback endpoint * Add jsforce node dependency * Migrate add endpoint * Import * Import package into crmService * Use new package types * Type fix * Update vite config * Push updated lockfile * Attempt to bump platform/libraries to unlock jsforce * Also update lockfile, naturally * bump platform libraries * Update vite.config * Add jsforce to vite config * fixup! Merge branch 'main' into upgrade-jsforce-v3 * fixup! fixup! Merge branch 'main' into upgrade-jsforce-v3 --------- Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Morgan Vernay <morgan@cal.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import jsforce from "@jsforce/jsforce-node";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { WEBAPP_URL_FOR_OAUTH } from "@calcom/lib/constants";
|
|
|
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
|
import { encodeOAuthState } from "../../_utils/oauth/encodeOAuthState";
|
|
|
|
let consumer_key = "";
|
|
|
|
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("salesforce");
|
|
if (typeof appKeys.consumer_key === "string") consumer_key = appKeys.consumer_key;
|
|
if (!consumer_key) return res.status(400).json({ message: "Salesforce client id missing." });
|
|
|
|
const salesforceClient = new jsforce.Connection({
|
|
oauth2: {
|
|
clientId: consumer_key,
|
|
redirectUri: `${WEBAPP_URL_FOR_OAUTH}/api/integrations/salesforce/callback`,
|
|
},
|
|
});
|
|
|
|
const state = encodeOAuthState(req);
|
|
|
|
const url = salesforceClient.oauth2.getAuthorizationUrl({
|
|
scope: "refresh_token full",
|
|
...(state && { state }),
|
|
});
|
|
res.status(200).json({ url });
|
|
}
|