refactor: circular deps between app store and lib [5] (#23936)
* getBulkEventTypes * 2 eventtypes related utils to features * locationsResolver * checkForEmptyAssignment * mv defaultEvents to features * update imports * PrismaAppRepository * mv currencyConversions from appstore to lib * useAppsData * videoClient * analytics files * fix * mv * prettier * use named import
This commit is contained in:
1 parent
dfdda8a5b8
commit
76332a759b
75 files changed
+182
-192
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { getAnalyticsService } from "@calcom/app-store/_utils/getAnalytics";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { AnalyticsService, SendEventProps } from "@calcom/types/AnalyticsService";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["AnalyticsManager"] });
|
||||
export default class AnalyticsManager {
|
||||
analyticsService: AnalyticsService | null | undefined = null;
|
||||
credential: CredentialPayload;
|
||||
|
||||
constructor(credential: CredentialPayload) {
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
private async getAnalyticsService(credential: CredentialPayload) {
|
||||
if (this.analyticsService) return this.analyticsService;
|
||||
const analyticsService = await getAnalyticsService({ credential });
|
||||
this.analyticsService = analyticsService;
|
||||
|
||||
if (!this.analyticsService) {
|
||||
log.error("Analytics service initialization failed");
|
||||
}
|
||||
|
||||
return analyticsService;
|
||||
}
|
||||
|
||||
public async sendEvent(props: SendEventProps) {
|
||||
const analyticsService = await this.getAnalyticsService(this.credential);
|
||||
if (!analyticsService) return;
|
||||
|
||||
return await analyticsService.sendEvent(props);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
|
||||
import { tasker } from "../../../tasker";
|
||||
|
||||
interface HandleAnalyticsEventsProps {
|
||||
credentials: CredentialForCalendarService[];
|
||||
rawBookingData: Record<string, any>;
|
||||
bookingInfo: {
|
||||
email: string;
|
||||
name: string;
|
||||
eventName: string;
|
||||
};
|
||||
isTeamEventType: boolean;
|
||||
}
|
||||
|
||||
export const handleAnalyticsEvents = async ({
|
||||
credentials,
|
||||
rawBookingData,
|
||||
bookingInfo,
|
||||
isTeamEventType,
|
||||
}: HandleAnalyticsEventsProps) => {
|
||||
const { dub_id } = await rawBookingData;
|
||||
|
||||
if (!dub_id || typeof dub_id !== "string") return;
|
||||
|
||||
const dubCredential = credentials.find((cred) => {
|
||||
if (cred.appId !== "dub") return false;
|
||||
if (isTeamEventType && !cred.teamId) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!dubCredential) return;
|
||||
|
||||
try {
|
||||
await tasker.create("sendAnalyticsEvent", {
|
||||
credentialId: dubCredential.id,
|
||||
info: {
|
||||
id: dub_id,
|
||||
...bookingInfo,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error sending dub lead: ", err);
|
||||
}
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
import AnalyticsManager from "@calcom/lib/analyticsManager/analyticsManager";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { CredentialRepository } from "@calcom/lib/server/repository/credential";
|
||||
|
||||
import AnalyticsManager from "./analyticsManager";
|
||||
import { sendAnalyticsEventSchema } from "./schema";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: [`[[tasker] sendAnalyticsEvent]`] });
|
||||
|
||||
Reference in new issue
Block a user