feat(db): mesh data model — meshes, members, invites, audit log
- pgSchema "mesh" with 4 tables isolating the peer mesh domain - Enums: visibility, transport, tier, role - audit_log is metadata-only (E2E encryption enforced at broker/client) - Cascade on mesh delete, soft-delete via archivedAt/revokedAt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
34
packages/monitoring/extension/src/providers/posthog/env.ts
Normal file
34
packages/monitoring/extension/src/providers/posthog/env.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/* eslint-disable turbo/no-undeclared-env-vars */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import { defineEnv } from "envin";
|
||||
import * as z from "zod";
|
||||
|
||||
import { envConfig } from "@turbostarter/shared/constants";
|
||||
|
||||
import type { Preset } from "envin/types";
|
||||
|
||||
export const preset = {
|
||||
id: "posthog",
|
||||
clientPrefix: "VITE_",
|
||||
client: {
|
||||
VITE_POSTHOG_KEY: z.string(),
|
||||
VITE_POSTHOG_HOST: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("https://us.i.posthog.com"),
|
||||
},
|
||||
} as const satisfies Preset;
|
||||
|
||||
export const env = defineEnv({
|
||||
...envConfig,
|
||||
...preset,
|
||||
env: {
|
||||
VITE_POSTHOG_KEY: import.meta.env.VITE_POSTHOG_KEY,
|
||||
VITE_POSTHOG_HOST: import.meta.env.VITE_POSTHOG_HOST,
|
||||
},
|
||||
skip:
|
||||
(!!import.meta.env.SKIP_ENV_VALIDATION &&
|
||||
["1", "true"].includes(import.meta.env.SKIP_ENV_VALIDATION)) ||
|
||||
["lint", "postinstall"].includes(import.meta.env.npm_lifecycle_event),
|
||||
});
|
||||
62
packages/monitoring/extension/src/providers/posthog/index.ts
Normal file
62
packages/monitoring/extension/src/providers/posthog/index.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { PostHog } from "posthog-js/dist/module.no-external";
|
||||
import { v7 as uuidv7 } from "uuid";
|
||||
|
||||
import { env } from "./env";
|
||||
|
||||
import type { MonitoringProviderStrategy } from "@turbostarter/monitoring";
|
||||
|
||||
const posthog = new PostHog();
|
||||
|
||||
export async function getSharedDistinctId() {
|
||||
const stored = await chrome.storage.local.get(["posthog_distinct_id"]);
|
||||
if (stored.posthog_distinct_id) {
|
||||
return stored.posthog_distinct_id as string;
|
||||
}
|
||||
|
||||
const distinctId = uuidv7();
|
||||
await chrome.storage.local.set({ posthog_distinct_id: distinctId });
|
||||
return distinctId;
|
||||
}
|
||||
|
||||
const init = async () => {
|
||||
if (posthog.__loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
const distinctID = await getSharedDistinctId();
|
||||
posthog.init(env.VITE_POSTHOG_KEY, {
|
||||
bootstrap: {
|
||||
distinctID,
|
||||
},
|
||||
api_host: env.VITE_POSTHOG_HOST,
|
||||
disable_external_dependency_loading: true,
|
||||
error_tracking: {
|
||||
captureExtensionExceptions: true,
|
||||
},
|
||||
persistence: "localStorage",
|
||||
});
|
||||
};
|
||||
|
||||
export const { captureException, identify, initialize } = {
|
||||
captureException: (exception) => {
|
||||
void (async () => {
|
||||
await init();
|
||||
posthog.captureException(exception);
|
||||
})();
|
||||
},
|
||||
identify: <T extends { id: string }>(user: T | null) => {
|
||||
void (async () => {
|
||||
await init();
|
||||
if (user) {
|
||||
posthog.identify(user.id);
|
||||
} else {
|
||||
posthog.reset();
|
||||
}
|
||||
})();
|
||||
},
|
||||
initialize: () => {
|
||||
void (async () => {
|
||||
await init();
|
||||
})();
|
||||
},
|
||||
} satisfies MonitoringProviderStrategy;
|
||||
Reference in New Issue
Block a user