Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/cli-attribution-stamp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"clerk": minor
---

Stamp authenticated CLI app creation with `from_source=cli` so apps created through Clerk CLI flows are attributable in Clerk's analytics. The value is set on the PLAPI request body and persists to `applications.from_source`. Requires matching PLAPI support to be deployed server-side.
2 changes: 1 addition & 1 deletion packages/cli-core/src/lib/plapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe("plapi", () => {
await createApplication("My App");
expect(capturedMethod).toBe("POST");
expect(capturedUrl).toBe("https://api.clerk.com/v1/platform/applications");
expect(JSON.parse(capturedBody)).toEqual({ name: "My App" });
expect(JSON.parse(capturedBody)).toEqual({ name: "My App", from_source: "cli" });
});

test("sends Content-Type and Authorization headers", async () => {
Expand Down
17 changes: 16 additions & 1 deletion packages/cli-core/src/lib/plapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ import { CliError, PlapiError, ERROR_CODE } from "./errors.ts";
import { loggedFetch } from "./fetch.ts";
import { log } from "./log.ts";

/**
* Canonical attribution marker written to `applications.from_source` when the
* CLI creates an application through PLAPI. Surfaces in BigQuery via
* `dim_applications.from_source` for growth analytics. Do not change without
* coordinating with the growth-data team - the value is consumed by dbt
* models and dashboards downstream.
*/
const CLI_FROM_SOURCE = "cli";

/**
* Validate that a key has the expected prefix and suggest the correct key type
* if the user mixed them up.
*/
export function validateKeyPrefix(key: string, expected: "ak_" | "sk_"): void {
if (key.startsWith(expected)) return;

Expand Down Expand Up @@ -167,7 +180,9 @@ export const patchInstanceConfig = (

export async function createApplication(name: string): Promise<Application> {
const url = new URL("/v1/platform/applications", getPlapiBaseUrl());
const response = await plapiFetch("POST", url, { body: JSON.stringify({ name }) });
const response = await plapiFetch("POST", url, {
body: JSON.stringify({ name, from_source: CLI_FROM_SOURCE }),
});
return response.json() as Promise<Application>;
}

Expand Down
Loading