* Add example app to test credential sync * Fixes * Changes to normalize flow of GoogleCalendar and Zoom * Add unit tests * PR Feedback * credential-sync-more-tests-and-more-apps * Fix yarn.lock * Clear cache * Add test * Fix yarn.lock * Fix 204 handling * Fix yarn.lock --------- Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
25 lines
794 B
TypeScript
25 lines
794 B
TypeScript
import logger from "@calcom/lib/logger";
|
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
|
import type { CredentialPayload } from "@calcom/types/Credential";
|
|
|
|
import { OAuth2TokenResponseInDbSchema } from "./universalSchema";
|
|
|
|
export function getTokenObjectFromCredential(credential: CredentialPayload) {
|
|
const parsedTokenResponse = OAuth2TokenResponseInDbSchema.safeParse(credential.key);
|
|
|
|
if (!parsedTokenResponse.success) {
|
|
logger.debug(
|
|
"GoogleCalendarService-getTokenObjectFromCredential",
|
|
safeStringify(parsedTokenResponse.error.issues)
|
|
);
|
|
throw new Error("Could not parse credential.key");
|
|
}
|
|
|
|
const tokenResponse = parsedTokenResponse.data;
|
|
if (!tokenResponse) {
|
|
throw new Error("credential.key is not set");
|
|
}
|
|
|
|
return tokenResponse;
|
|
}
|