feat: changed backend-pg to backend

This commit is contained in:
Akhil Mohan
2024-01-27 19:14:33 +05:30
parent d13eafcef7
commit 66d258f02b
792 changed files with 40298 additions and 40607 deletions
@@ -0,0 +1,68 @@
import { PostHog } from "posthog-node";
import { getConfig } from "@app/lib/config/env";
import { request } from "@app/lib/config/request";
import { logger } from "@app/lib/logger";
import { TPostHogEvent } from "./telemetry-types";
export type TTelemetryServiceFactory = ReturnType<typeof telemetryServiceFactory>;
// type TTelemetryServiceFactoryDep = {};
export const telemetryServiceFactory = () => {
const appCfg = getConfig();
if (appCfg.isProductionMode && !appCfg.TELEMETRY_ENABLED) {
// eslint-disable-next-line
console.log(`
To improve, Infisical collects telemetry data about general usage.
This helps us understand how the product is doing and guide our product development to create the best possible platform; it also helps us demonstrate growth as we support Infisical as open-source software.
To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environment variables.
`);
}
const postHog =
appCfg.isProductionMode && appCfg.TELEMETRY_ENABLED
? new PostHog(appCfg.POSTHOG_PROJECT_API_KEY, { host: appCfg.POSTHOG_HOST })
: undefined;
// used for email marketting email sending purpose
const sendLoopsEvent = async (email: string, firstName?: string, lastName?: string) => {
if (appCfg.isProductionMode && appCfg.LOOPS_API_KEY) {
try {
await request.post(
"https://app.loops.so/api/v1/events/send",
{
eventName: "Sign Up",
email,
firstName,
lastName
},
{
headers: {
Accept: "application/json",
Authorization: `Bearer ${appCfg.LOOPS_API_KEY}`
}
}
);
} catch (error) {
logger.error(error);
}
}
};
const sendPostHogEvents = async (event: TPostHogEvent) => {
if (postHog) {
postHog.capture({
event: event.event,
distinctId: event.distinctId,
properties: event.properties
});
}
};
return {
sendLoopsEvent,
sendPostHogEvents
};
};
@@ -0,0 +1,61 @@
export enum PostHogEventTypes {
SecretPush = "secrets pushed",
SecretPulled = "secrets pulled",
SecretCreated = "secrets added",
SecretUpdated = "secrets modified",
SecretDeleted = "secrets deleted",
AdminInit = "admin initialization",
UserSignedUp = "User Signed Up",
SecretRotated = "secrets rotated",
SecretScannerFull = "historical cloud secret scan",
SecretScannerPush = "cloud secret scan"
}
export type TSecretModifiedEvent = {
event:
| PostHogEventTypes.SecretPush
| PostHogEventTypes.SecretRotated
| PostHogEventTypes.SecretPulled
| PostHogEventTypes.SecretCreated
| PostHogEventTypes.SecretUpdated
| PostHogEventTypes.SecretDeleted;
properties: {
numberOfSecrets: number;
environment: string;
workspaceId: string;
secretPath: string;
channel?: string;
userAgent?: string;
};
};
export type TAdminInitEvent = {
event: PostHogEventTypes.AdminInit;
properties: {
email: string;
firstName: string;
lastName: string;
};
};
export type TUserSignedUpEvent = {
event: PostHogEventTypes.UserSignedUp;
properties: {
email: string;
attributionSource?: string;
};
};
export type TSecretScannerEvent = {
event: PostHogEventTypes.SecretScannerFull | PostHogEventTypes.SecretScannerPush;
properties: {
numberOfRisks: number;
};
};
export type TPostHogEvent = { distinctId: string } & (
| TSecretModifiedEvent
| TAdminInitEvent
| TUserSignedUpEvent
| TSecretScannerEvent
);