Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upgrade jsforce to 3.6.2 and use jsforce-node #18363

Merged
merged 30 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
24286be
Upgrade jsforce to 3.6.2
joeauyeung Dec 24, 2024
bb04415
Refactor connecting to Salesforce
joeauyeung Dec 24, 2024
e3452d5
Revert yarn.lock changes
joeauyeung Dec 24, 2024
c11c047
Migrate callback endpoint
joeauyeung Dec 25, 2024
eb4fd61
Add jsforce node dependency
joeauyeung Dec 27, 2024
7fa275e
Migrate add endpoint
joeauyeung Dec 27, 2024
035ebd0
Import
joeauyeung Dec 27, 2024
2a9f57d
Import package into crmService
joeauyeung Dec 27, 2024
852ceec
Use new package types
joeauyeung Dec 27, 2024
e8e6c40
Merge branch 'main' into upgrade-jsforce-v3
joeauyeung Dec 27, 2024
e91cf12
Type fix
joeauyeung Dec 27, 2024
9cf6e8e
Update vite config
joeauyeung Dec 27, 2024
fd8a890
Merge branch 'main' into upgrade-jsforce-v3
emrysal Dec 31, 2024
6626a11
Push updated lockfile
emrysal Dec 31, 2024
457456e
Attempt to bump platform/libraries to unlock jsforce
emrysal Dec 31, 2024
3ecc60f
Also update lockfile, naturally
emrysal Dec 31, 2024
230dd25
Merge branch 'main' into upgrade-jsforce-v3
ThyMinimalDev Jan 6, 2025
24cb1cd
Merge branch 'main' into upgrade-jsforce-v3
ThyMinimalDev Jan 7, 2025
fd88f2a
bump platform libraries
ThyMinimalDev Jan 7, 2025
0f23f7b
Update vite.config
joeauyeung Jan 7, 2025
7206b8a
Merge branch 'main' into upgrade-jsforce-v3
joeauyeung Jan 7, 2025
ab7dfed
Merge branch 'main' into upgrade-jsforce-v3
zomars Jan 7, 2025
1dfc850
Add jsforce to vite config
joeauyeung Jan 8, 2025
5d3b6bc
Merge branch 'upgrade-jsforce-v3' of https://github.com/calcom/cal.co…
joeauyeung Jan 8, 2025
cb2cd06
Merge branch 'main' into upgrade-jsforce-v3
joeauyeung Jan 8, 2025
f4b0782
fixup! Merge branch 'main' into upgrade-jsforce-v3
ThyMinimalDev Jan 8, 2025
8904ec2
fixup! fixup! Merge branch 'main' into upgrade-jsforce-v3
ThyMinimalDev Jan 8, 2025
0562882
Merge branch 'main' into upgrade-jsforce-v3
joeauyeung Jan 8, 2025
a6463ed
Merge branch 'main' into upgrade-jsforce-v3
anikdhabal Jan 9, 2025
6455f51
Merge branch 'main' into upgrade-jsforce-v3
joeauyeung Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"googleapis": "^84.0.0",
"helmet": "^7.1.0",
"ioredis": "^5.3.2",
"jsforce": "^1.11.0",
"luxon": "^3.4.4",
"nest-winston": "^1.9.4",
"next-auth": "^4.22.1",
Expand Down
28 changes: 9 additions & 19 deletions help/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,11 @@
]
},
{
"group": "Calendars",
"icon": "<i class='fa-light fa-calendar' style='color: #cfd2d8;'></i>",
"iconType": "custom",
"pages": [
"calendars/how-to-add-google-calendar",
"calendars/how-to-add-apple-calendar"
]
},
"group": "Calendars",
"icon": "<i class='fa-light fa-calendar' style='color: #cfd2d8;'></i>",
"iconType": "custom",
"pages": ["calendars/how-to-add-google-calendar", "calendars/how-to-add-apple-calendar"]
},
{
"group": "Event Types",
"icon": "calendar",
Expand Down Expand Up @@ -135,11 +132,7 @@
"group": "Bookings",
"icon": "calendar-check",
"iconType": "solid",
"pages": [
"bookings/no-show",
"bookings/paid-bookings",
"bookings/prefill-fields"
]
"pages": ["bookings/no-show", "bookings/paid-bookings", "bookings/prefill-fields"]
},
{
"group": "Embedding",
Expand All @@ -158,10 +151,7 @@
"group": "Auth and Provisioning",
"icon": "user-lock",
"iconType": "solid",
"pages": [
"auth-and-provision/scim-okta",
"auth-and-provision/oidc-with-okta"
]
"pages": ["auth-and-provision/scim-okta", "auth-and-provision/oidc-with-okta"]
},
{
"group": "Apps and Integrations",
Expand All @@ -176,7 +166,7 @@
"apps-and-integrations/how-to-build-an-app",
"apps-and-integrations/syncing-third-party"
]
},
}
]
}
],
Expand All @@ -185,4 +175,4 @@
"linkedin": "https://www.linkedin.com/company/cal-com/",
"discord": "https://discord.com/invite/calcom"
}
}
}
12 changes: 8 additions & 4 deletions packages/app-store/salesforce/api/add.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jsforce from "jsforce";
import jsforce from "@jsforce/jsforce-node";
import type { NextApiRequest, NextApiResponse } from "next";

import { WEBAPP_URL_FOR_OAUTH } from "@calcom/lib/constants";
Expand All @@ -16,13 +16,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (!consumer_key) return res.status(400).json({ message: "Salesforce client id missing." });

const salesforceClient = new jsforce.Connection({
clientId: consumer_key,
redirectUri: `${WEBAPP_URL_FOR_OAUTH}/api/integrations/salesforce/callback`,
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: encodeOAuthState(req),
...(state && { state }),
});
res.status(200).json({ url });
}
10 changes: 6 additions & 4 deletions packages/app-store/salesforce/api/callback.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jsforce from "jsforce";
import jsforce from "@jsforce/jsforce-node";
import type { NextApiRequest, NextApiResponse } from "next";

import { WEBAPP_URL_FOR_OAUTH } from "@calcom/lib/constants";
Expand Down Expand Up @@ -33,9 +33,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (!consumer_secret) return res.status(400).json({ message: "Salesforce consumer secret missing." });

const conn = new jsforce.Connection({
clientId: consumer_key,
clientSecret: consumer_secret,
redirectUri: `${WEBAPP_URL_FOR_OAUTH}/api/integrations/salesforce/callback`,
oauth2: {
clientId: consumer_key,
clientSecret: consumer_secret,
redirectUri: `${WEBAPP_URL_FOR_OAUTH}/api/integrations/salesforce/callback`,
},
});

const salesforceTokenInfo = await conn.oauth2.requestToken(code as string);
Expand Down
24 changes: 15 additions & 9 deletions packages/app-store/salesforce/lib/CrmService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TokenResponse } from "jsforce";
import jsforce from "jsforce";
import type { TokenResponse, Connection, Field } from "@jsforce/jsforce-node";
import jsforce from "@jsforce/jsforce-node";
import { RRule } from "rrule";
import { z } from "zod";

Expand Down Expand Up @@ -64,7 +64,7 @@ const salesforceTokenSchema = z.object({

export default class SalesforceCRMService implements CRM {
private integrationName = "";
private conn!: Promise<jsforce.Connection>;
private conn!: Promise<Connection>;
private log: typeof logger;
private calWarnings: string[] = [];
private appOptions: any;
Expand All @@ -87,6 +87,10 @@ export default class SalesforceCRMService implements CRM {
private getClient = async (credential: CredentialPayload) => {
const { consumer_key, consumer_secret } = await getSalesforceAppKeys();
const credentialKey = credential.key as unknown as ExtendedTokenResponse;

if (!credentialKey.refresh_token)
throw new Error(`Refresh token is missing for credential ${credential.id}`);

try {
/* XXX: This code results in 'Bad Request', which indicates something is wrong with our salesforce integration.
Needs further investigation ASAP */
Expand Down Expand Up @@ -121,9 +125,11 @@ export default class SalesforceCRMService implements CRM {
}

return new jsforce.Connection({
clientId: consumer_key,
clientSecret: consumer_secret,
redirectUri: `${WEBAPP_URL}/api/integrations/salesforce/callback`,
oauth2: {
clientId: consumer_key,
clientSecret: consumer_secret,
redirectUri: `${WEBAPP_URL}/api/integrations/salesforce/callback`,
},
instanceUrl: credentialKey.instance_url,
accessToken: credentialKey.access_token,
refreshToken: credentialKey.refresh_token,
Expand Down Expand Up @@ -768,7 +774,7 @@ export default class SalesforceCRMService implements CRM {
const conn = await this.conn;

const fieldSet = new Set(fieldsToTest);
const foundFields: jsforce.Field[] = [];
const foundFields: Field[] = [];

try {
const salesforceEntity = await conn.describe(sobject);
Expand Down Expand Up @@ -953,7 +959,7 @@ export default class SalesforceCRMService implements CRM {
organizerEmail,
calEventResponses,
}: {
existingFields: jsforce.Field[];
existingFields: Field[];
personRecord: Record<string, any>;
onBookingWriteToRecordFields: Record<string, any>;
startTime: string;
Expand Down Expand Up @@ -1113,7 +1119,7 @@ export default class SalesforceCRMService implements CRM {

private async fetchPersonRecord(
contactId: string,
existingFields: jsforce.Field[],
existingFields: Field[],
personRecordType: SalesforceRecordEnum
): Promise<Record<string, any> | null> {
const conn = await this.conn;
Expand Down
5 changes: 2 additions & 3 deletions packages/app-store/salesforce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"dependencies": {
"@calcom/lib": "*",
"@calcom/prisma": "*",
"jsforce": "^1.11.0"
"@jsforce/jsforce-node": "^3.6.3"
},
"devDependencies": {
"@calcom/types": "*",
"@types/jsforce": "^1.11.0"
"@calcom/types": "*"
}
}
2 changes: 2 additions & 0 deletions packages/platform/libraries/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default defineConfig({
"lru-cache",
"next-auth/jwt",
"memory-cache",
"@jsforce/jsforce-node",
"jsforce",
"axios",
"qs",
Expand Down Expand Up @@ -137,6 +138,7 @@ export default defineConfig({
"lru-cache": "lru-cache",
"next-auth/jwt": "next-auth/jwt",
"memory-cache": "memory-cache",
"@jsforce-node": "@jsforce/jsforce-node",
jsforce: "jsforce",
axios: "axios",
qs: "qs",
Expand Down
Loading
Loading