Skip to content

Commit 51ad66f

Browse files
committed
fix: ensure right scopes
1 parent 42dd10c commit 51ad66f

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

packages/app-store/hubspot-revert/api/add.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
3333
teamId: Number(teamId),
3434
});
3535
const tenantId = teamId ? teamId : userId;
36-
const scopes = ["crm.objects.contacts.read", "crm.objects.contacts.write"];
36+
const scopes = [
37+
"crm.objects.contacts.read",
38+
"crm.objects.contacts.write",
39+
"crm.objects.marketing_events.read",
40+
"crm.objects.marketing_events.write",
41+
];
3742
res.status(200).json({
3843
url: `https://app.hubspot.com/oauth/authorize?client_id=${
3944
appKeys.client_id

packages/app-store/hubspot-revert/lib/CalendarService.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type ContactCreateResult = {
3434
};
3535
};
3636

37-
export default class HubspotRevertCalendarService implements Calendar {
37+
export default class HubSpotRevertCalendarService implements Calendar {
3838
private log: typeof logger;
3939
private tenantId: string;
4040
private revertApiKey: string;
@@ -78,26 +78,22 @@ export default class HubspotRevertCalendarService implements Calendar {
7878
};
7979

8080
private contactSearch = async (event: CalendarEvent) => {
81-
const attendeeEmails = event.attendees.map((attendee) => attendee.email);
82-
8381
const headers = new Headers();
8482
headers.append("x-revert-api-token", this.revertApiKey);
8583
headers.append("x-revert-t-id", this.tenantId);
8684
headers.append("Content-Type", "application/json");
8785

8886
const bodyRaw = JSON.stringify({
8987
searchCriteria: {
90-
filterGroups: [
91-
{
92-
filters: [
93-
{
94-
propertyName: "email",
95-
operator: "IN",
96-
values: attendeeEmails,
97-
},
98-
],
99-
},
100-
],
88+
filterGroups: event.attendees.map((attendee) => ({
89+
filters: [
90+
{
91+
value: attendee.email,
92+
propertyName: "email",
93+
operator: "EQ",
94+
},
95+
],
96+
})),
10197
},
10298
});
10399

@@ -124,7 +120,7 @@ export default class HubspotRevertCalendarService implements Calendar {
124120
}`;
125121
};
126122

127-
private createHubspotEvent = async (event: CalendarEvent, contacts: CalendarEvent["attendees"]) => {
123+
private createHubSpotEvent = async (event: CalendarEvent, contacts: CalendarEvent["attendees"]) => {
128124
const eventPayload = {
129125
subject: event.title,
130126
startDateTime: event.startTime,
@@ -187,7 +183,7 @@ export default class HubspotRevertCalendarService implements Calendar {
187183
};
188184

189185
async handleEventCreation(event: CalendarEvent, contacts: CalendarEvent["attendees"]) {
190-
const meetingEvent = await (await this.createHubspotEvent(event, contacts)).json();
186+
const meetingEvent = await (await this.createHubSpotEvent(event, contacts)).json();
191187
if (meetingEvent && meetingEvent.status === "ok") {
192188
this.log.debug("event:creation:ok", { meetingEvent });
193189
return Promise.resolve({
@@ -200,7 +196,7 @@ export default class HubspotRevertCalendarService implements Calendar {
200196
});
201197
}
202198
this.log.debug("meeting:creation:notOk", { meetingEvent, event, contacts });
203-
return Promise.reject("Something went wrong when creating a meeting in PipedriveCRM");
199+
return Promise.reject("Something went wrong when creating a meeting in HubSpot CRM");
204200
}
205201

206202
async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> {
@@ -221,7 +217,7 @@ export default class HubspotRevertCalendarService implements Calendar {
221217
});
222218
return await this.handleEventCreation(event, existingPeople);
223219
} else {
224-
// Some attendees don't exist in PipedriveCRM
220+
// Some attendees don't exist in HubSpot CRM
225221
// Get the existing contacts' email to filter out
226222
this.log.debug("contact:search:notAll", { event, contacts });
227223
const existingContacts = contacts.results.map((contact) => contact.email);
@@ -231,7 +227,7 @@ export default class HubspotRevertCalendarService implements Calendar {
231227
(attendee) => !existingContacts.includes(attendee.email)
232228
);
233229
this.log.debug("contact:filter:nonExisting", { nonExistingContacts });
234-
// Only create contacts in PipedriveCRM that were not present in the previous contact search
230+
// Only create contacts in HubSpot CRM that were not present in the previous contact search
235231
const createdContacts = await this.createContacts(nonExistingContacts);
236232
this.log.debug("contact:created", { createdContacts });
237233
// Continue with event creation and association only when all contacts are present in hubspot
@@ -265,7 +261,7 @@ export default class HubspotRevertCalendarService implements Calendar {
265261
return await this.handleEventCreation(event, allContacts);
266262
}
267263
return Promise.reject({
268-
calError: "Something went wrong when creating non-existing attendees in PipedriveCRM",
264+
calError: "Something went wrong when creating non-existing attendees in HubSpot CRM",
269265
});
270266
}
271267
} else {
@@ -287,7 +283,7 @@ export default class HubspotRevertCalendarService implements Calendar {
287283
}
288284
}
289285
return Promise.reject({
290-
calError: "Something went wrong when searching/creating the attendees in PipedriveCRM",
286+
calError: "Something went wrong when searching/creating the attendees in HubSpot CRM",
291287
});
292288
}
293289

@@ -315,7 +311,7 @@ export default class HubspotRevertCalendarService implements Calendar {
315311
});
316312
}
317313
this.log.debug("meeting:updation:notOk", { meetingEvent, event });
318-
return Promise.reject("Something went wrong when updating a meeting in PipedriveCRM");
314+
return Promise.reject("Something went wrong when updating a meeting in HubSpot CRM");
319315
}
320316

321317
async deleteEvent(uid: string): Promise<void> {

packages/app-store/zohocrm-revert/api/add.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
3131
teamId: Number(teamId),
3232
});
3333
const tenantId = teamId ? teamId : userId;
34-
// @TODO check scopes before deployment
3534
const scopes = ["ZohoCRM.modules.ALL", "ZohoCRM.users.READ", "AaaServer.profile.READ"];
3635

3736
const queryParams = {

0 commit comments

Comments
 (0)