* feat: installing the app works * Update yarn.lock * feat: /api/callback now gets user auth info from basecamp * feat: updated basecamp logo * feat: added project dropdown on event apps page * feat: basecamp event creation and deletion working * feat: basecamp event rescheduling now works * refactor(CalendarService): basecamp CaldendarService code clean up * refactor: code cleanup for basecamp app API * feat: updated event summary text sent to basecamp * chore: updated basecamp images and contact info * fix: fixed typescript errors and added logic to refresh tokens on event settings * refactor(CaldendarService): used refreshAccessToken from helpers.ts instead * chore: updated basecamp description * fix: fixed incorrect import * fix: accidentally deleted props to toggle app for event * chore: updated .env.appStore.example and added README for app * Update .env.appStore.example Co-authored-by: Leo Giovanetti <hello@leog.me> * feat: added basecamp userAgent in env instead of hardcoded value * feat: updated README to include how to set basecamp user agent env * fix: removed unused import * feat: used URLSearchParams to construct url params * fix: fixed typescript errors * chore: updated README to include an example on how to set basecamp user-agent * feat: using TRPC instead of REST * chore: removed old projects REST code --------- Co-authored-by: Leo Giovanetti <hello@leog.me>
25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { CredentialPayload } from "@calcom/types/Credential";
|
|
|
|
import type { BasecampToken } from "./CalendarService";
|
|
import { getBasecampKeys } from "./getBasecampKeys";
|
|
|
|
export const refreshAccessToken = async (credential: CredentialPayload) => {
|
|
const { client_id: clientId, client_secret: clientSecret, user_agent: userAgent } = await getBasecampKeys();
|
|
const credentialKey = credential.key as BasecampToken;
|
|
const tokenInfo = await fetch(
|
|
`https://launchpad.37signals.com/authorization/token?type=refresh&refresh_token=${credentialKey.refresh_token}&client_id=${clientId}&redirect_uri=${WEBAPP_URL}&client_secret=${clientSecret}`,
|
|
{ method: "POST", headers: { "User-Agent": userAgent } }
|
|
);
|
|
const tokenInfoJson = await tokenInfo.json();
|
|
tokenInfoJson["expires_at"] = Date.now() + 1000 * 3600 * 24 * 14;
|
|
const newCredential = await prisma.credential.update({
|
|
where: { id: credential.id },
|
|
data: {
|
|
key: { ...credentialKey, ...tokenInfoJson },
|
|
},
|
|
});
|
|
return newCredential.key;
|
|
};
|