Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
499 changes: 70 additions & 429 deletions src/commands/posthog/setup.ts

Large diffs are not rendered by default.

51 changes: 0 additions & 51 deletions src/lib/api/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,57 +260,6 @@ export async function startPosthogCliFlow(
throw new CLIError('PostHog cli-start returned an unexpected response shape.');
}

export interface PosthogCliCredentials {
apiKey: string; // phc_
personalApiKey: string; // phx_
posthogProjectId: string | number;
region: string;
host: string;
status?: string;
}

/**
* GET /integrations/posthog/v1/cli-credentials?project_id=<id>
*
* Returns phx_ in addition to phc_ so the CLI can spawn
* `npx @posthog/wizard --ci --api-key <phx_>`. Same membership rules as
* /connection — gated by `authenticate` middleware on cloud-backend.
*/
export async function fetchPosthogCliCredentials(
projectId: string,
jwt: string,
apiUrl?: string,
): Promise<PosthogCliCredentials> {
const baseUrl = getPlatformApiUrl(apiUrl);
const url = `${baseUrl}/integrations/posthog/v1/cli-credentials?project_id=${encodeURIComponent(projectId)}`;

let res: Response;
try {
res = await fetchWithTimeout(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${jwt}`,
Accept: 'application/json',
},
});
} catch (err) {
throw new CLIError(`Failed to fetch CLI credentials: ${formatFetchError(err, url)}`);
}

if (!res.ok) {
const body = (await res.json().catch(() => ({}))) as { error?: string };
throw new CLIError(
`Failed to fetch CLI credentials (HTTP ${res.status}): ${body.error ?? res.statusText}`,
);
}

const data = (await res.json()) as Partial<PosthogCliCredentials>;
if (!data.apiKey || !data.personalApiKey || !data.posthogProjectId || !data.region || !data.host) {
throw new CLIError('CLI credentials response is missing required fields.');
}
return data as PosthogCliCredentials;
}

function sleep(ms: number, signal?: AbortSignal): Promise<void> {
return new Promise((resolve, reject) => {
if (signal?.aborted) {
Expand Down
174 changes: 0 additions & 174 deletions src/lib/framework-detect.test.ts

This file was deleted.

87 changes: 0 additions & 87 deletions src/lib/framework-detect.ts

This file was deleted.

55 changes: 0 additions & 55 deletions src/lib/package-manager.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/templates/posthog/astro/posthog-init.ts.txt

This file was deleted.

Loading
Loading