520e711ca6
* perf: optimize analytics app imports to avoid loading entire app store - Add analytics service generation to app-store-cli build process - Generate analytics.services.generated.ts with only analytics apps (dub) - Update getAnalytics.ts to use AnalyticsServiceMap instead of full appStore - Add NEXT_PUBLIC_IS_E2E to turbo.json globalEnv for generated files - Reduces import footprint from 100+ apps to only analytics apps with AnalyticsService - Follows same pattern as calendar services optimization from PR #22450 Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * Reorder cli output * fix: follow getCalendar pattern in getAnalytics and maintain alphabetical order in turbo.json - Remove unnecessary object wrapping in getAnalytics.ts to match getCalendar.ts pattern - Move NEXT_PUBLIC_IS_E2E to correct alphabetical position in turbo.json globalEnv - Address PR feedback from keithwillcode Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> * chore: update yarn.lock after analytics optimization changes Co-Authored-By: keith@cal.com <keithwillcode@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import logger from "@calcom/lib/logger";
|
|
import type { AnalyticsService } from "@calcom/types/AnalyticsService";
|
|
import type { CredentialPayload } from "@calcom/types/Credential";
|
|
|
|
import { AnalyticsServiceMap } from "../analytics.services.generated";
|
|
|
|
const log = logger.getSubLogger({ prefix: ["AnalyticsManager"] });
|
|
|
|
export const getAnalyticsService = async ({
|
|
credential,
|
|
}: {
|
|
credential: CredentialPayload;
|
|
}): Promise<AnalyticsService | null> => {
|
|
if (!credential || !credential.key) return null;
|
|
const { type: analyticsType } = credential;
|
|
|
|
const analyticsName = analyticsType.split("_")[0];
|
|
|
|
const analyticsAppImportFn = AnalyticsServiceMap[analyticsName as keyof typeof AnalyticsServiceMap];
|
|
|
|
if (!analyticsAppImportFn) {
|
|
log.warn(`analytics app not implemented`);
|
|
return null;
|
|
}
|
|
|
|
const analyticsApp = await analyticsAppImportFn;
|
|
|
|
const AnalyticsService = analyticsApp.default;
|
|
|
|
if (!AnalyticsService || typeof AnalyticsService !== "function") {
|
|
log.warn(`analytics of type ${analyticsType} is not implemented`);
|
|
return null;
|
|
}
|
|
|
|
return new AnalyticsService(credential);
|
|
};
|