Elffuss BraidHub

kikocis/continue public

main · 1.3 KiBRawPermalink
1import { Analytics } from "@continuedev/config-types";
2import fetch from "node-fetch";
3
4import { ControlPlaneClient } from "../client.js";
5
6import {
7 ControlPlaneProxyInfo,
8 IAnalyticsProvider,
9} from "./IAnalyticsProvider.js";
10
11export default class ContinueProxyAnalyticsProvider
12 implements IAnalyticsProvider
13{
14 uniqueId?: string;
15 controlPlaneProxyInfo?: ControlPlaneProxyInfo;
16
17 controlPlaneClient?: ControlPlaneClient;
18
19 async capture(
20 event: string,
21 properties: { [key: string]: any },
22 ): Promise<void> {
23 if (!this.controlPlaneProxyInfo?.workspaceId) {
24 return;
25 }
26
27 const url = new URL(
28 `proxy/analytics/${this.controlPlaneProxyInfo.workspaceId}/capture`,
29 this.controlPlaneProxyInfo?.controlPlaneProxyUrl,
30 ).toString();
31 void fetch(url, {
32 method: "POST",
33 body: JSON.stringify({
34 event,
35 properties,
36 uniqueId: this.uniqueId,
37 }),
38 headers: {
39 Authorization: `Bearer ${await this.controlPlaneClient?.getAccessToken()}`,
40 },
41 });
42 }
43
44 async setup(
45 config: Analytics,
46 uniqueId: string,
47 controlPlaneProxyInfo?: ControlPlaneProxyInfo,
48 ): Promise<void> {
49 this.uniqueId = uniqueId;
50 this.controlPlaneProxyInfo = controlPlaneProxyInfo;
51 }
52
53 async shutdown(): Promise<void> {}
54}