* move SystemField to features * migrate workflow service * merge two tests for team repository * update imports and migrate team repository * migrate delegation credential repository * migrate credential repository * migrate entityPermissionUtils * migrate hashedLink service and repository * migrate membership service * update imports * remove file * migrate buildEventUrlFromBooking * migrate getAllUserBookings to features * update imports * update organizationMock * migrate slots * migrate date-ranges to schedules dir * migrate getAggregatedAvailability * fix * refactor * migrate useCreateEventType hook to features * migrate assignValueToUser * migrate validateUsername to auth features * migrate system field back to lib * migrate getLabelValueMapFromResponses back to lib * update imports * use relative path * fix type checks * fix * fix * fix tests * update gh codeowners * fix * fix
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import logger from "@calcom/lib/logger";
|
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
|
import { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
|
|
|
|
import AnalyticsManager from "./analyticsManager";
|
|
import { sendAnalyticsEventSchema } from "./schema";
|
|
|
|
const log = logger.getSubLogger({ prefix: [`[[tasker] sendAnalyticsEvent]`] });
|
|
|
|
export async function sendAnalyticsEvent(payload: string): Promise<void> {
|
|
try {
|
|
const parsedPayload = sendAnalyticsEventSchema.safeParse(JSON.parse(payload));
|
|
if (!parsedPayload.success) {
|
|
throw new Error(`malformed payload in sendAnalyticsEvent: ${parsedPayload.error}`);
|
|
}
|
|
|
|
const { credentialId, info } = parsedPayload.data;
|
|
const credential = await CredentialRepository.findFirstByIdWithKeyAndUser({ id: credentialId });
|
|
|
|
if (!credential) {
|
|
throw new Error("Invalid credential");
|
|
}
|
|
const manager = new AnalyticsManager(credential);
|
|
|
|
if (!manager) return;
|
|
|
|
await manager.sendEvent(info);
|
|
} catch (err) {
|
|
log.error(
|
|
`[Will retry] Error creating analytics event: error: ${safeStringify(err)} payload: ${safeStringify({
|
|
payload,
|
|
})}`
|
|
);
|
|
// Intentional rethrow to trigger retry
|
|
throw err;
|
|
}
|
|
}
|