Skip to content

Commit

Permalink
prefix all boolean event properties with "is"
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Sep 10, 2024
1 parent 0942809 commit 1026f46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/create-cloudflare/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ export type Event =
/**
* Whether the user was already logged in before running the CLI
*/
alreadyLoggedIn?: boolean;
isAlreadyLoggedIn?: boolean;

/**
* Whether the user successfully going through the login process if they were not already logged in
*/
newLoginSuccessful?: boolean;
isLoginSuccessful?: boolean;

/**
* The duration of the prompt since it started in milliseconds (ms)
Expand Down Expand Up @@ -526,12 +526,12 @@ export type Event =
/**
* Whether the user was already logged in before running the CLI
*/
alreadyLoggedIn?: boolean;
isAlreadyLoggedIn?: boolean;

/**
* Whether the user successfully going through the login process if they were not already logged in
*/
newLoginSuccessful?: boolean;
isLoginSuccessful?: boolean;

/**
* The error that caused the session to be crashed
Expand Down Expand Up @@ -590,12 +590,12 @@ export type Event =
/**
* Whether the user was already logged in before running the CLI
*/
alreadyLoggedIn?: boolean;
isAlreadyLoggedIn?: boolean;

/**
* Whether the user successfully going through the login process if they were not already logged in
*/
newLoginSuccessful?: boolean;
isLoginSuccessful?: boolean;

/**
* The duration of the prompt since it started in milliseconds (ms)
Expand Down
8 changes: 7 additions & 1 deletion packages/create-cloudflare/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import type { Event } from "./event";
type EventPrefix<Suffix extends string> =
Event["name"] extends `${infer Name} ${Suffix}` ? Name : never;

// A type to get all possible keys of a union type
type KeysOfUnion<Obj> = Obj extends Obj ? keyof Obj : never;

// A type to extract the properties of an event based on the name
type EventProperties<EventName extends Event["name"]> = Extract<
Event,
Expand Down Expand Up @@ -222,7 +225,10 @@ export function createReporter() {
}

// To be used within `collectAsyncMetrics` to update the properties object sent to sparrow
function setEventProperty(key: string, value: unknown) {
function setEventProperty<Key extends KeysOfUnion<Event["properties"]>>(
key: Key,
value: unknown,
) {
const store = als.getStore();

// Throw only on test environment to avoid breaking the CLI
Expand Down
10 changes: 5 additions & 5 deletions packages/create-cloudflare/src/wrangler/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export const wranglerLogin = async (ctx: C3Context) => {
s.start(
`Logging into Cloudflare ${dim("checking authentication status")}`,
);
const alreadyLoggedIn = await isLoggedIn();
s.stop(brandColor(alreadyLoggedIn ? "logged in" : "not logged in"));
const isAlreadyLoggedIn = await isLoggedIn();
s.stop(brandColor(isAlreadyLoggedIn ? "logged in" : "not logged in"));

reporter.setEventProperty("alreadyLoggedIn", alreadyLoggedIn);
reporter.setEventProperty("isAlreadyLoggedIn", isAlreadyLoggedIn);

if (alreadyLoggedIn) {
if (isAlreadyLoggedIn) {
return true;
}

Expand All @@ -83,7 +83,7 @@ export const wranglerLogin = async (ctx: C3Context) => {
const verb = success ? "allowed" : "denied";
s.stop(`${brandColor(verb)} ${dim("via `wrangler login`")}`);

reporter.setEventProperty("newLoginSuccessful", success);
reporter.setEventProperty("isLoginSuccessful", success);

return success;
},
Expand Down

0 comments on commit 1026f46

Please sign in to comment.