Elffuss BraidHub

kikocis/continue public

99fe51849b68 · 1.2 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 const url = new URL(
24 `proxy/analytics/${this.controlPlaneProxyInfo?.workspaceId}/capture`,
25 this.controlPlaneProxyInfo?.controlPlaneProxyUrl,
26 ).toString();
27 void fetch(url, {
28 method: "POST",
29 body: JSON.stringify({
30 event,
31 properties,
32 uniqueId: this.uniqueId,
33 }),
34 headers: {
35 Authorization: `Bearer ${await this.controlPlaneClient?.getAccessToken()}`,
36 },
37 });
38 }
39
40 async setup(
41 config: Analytics,
42 uniqueId: string,
43 controlPlaneProxyInfo?: ControlPlaneProxyInfo,
44 ): Promise<void> {
45 this.uniqueId = uniqueId;
46 this.controlPlaneProxyInfo = controlPlaneProxyInfo;
47 }
48
49 async shutdown(): Promise<void> {}
50}