-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shared): Adjust types to enforce the event structure from event …
…factory methods
- Loading branch information
Showing
6 changed files
with
92 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { TelemetryCollector, type TelemetryCollectorOptions } from './telemetry/collector'; | ||
export { TelemetryCollector } from './telemetry/collector'; | ||
export type { TelemetryCollectorOptions } from './telemetry/types'; | ||
|
||
export * from './telemetry/events'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
import type { TelemetryEventRaw } from '../types'; | ||
|
||
const EVENT_COMPONENT_MOUNTED = 'COMPONENT_MOUNTED' as const; | ||
|
||
type EventComponentMounted = { | ||
component: string; | ||
appearanceProp: boolean; | ||
elements: boolean; | ||
variables: boolean; | ||
baseTheme: boolean; | ||
}; | ||
|
||
/** | ||
* Fired when one of the Clerk components is mounted. | ||
*/ | ||
export function eventComponentMounted( | ||
component: string, | ||
props?: Record<string, unknown>, | ||
): { event: typeof EVENT_COMPONENT_MOUNTED; payload: EventComponentMounted } { | ||
props?: Record<string, any>, | ||
): TelemetryEventRaw<EventComponentMounted> { | ||
return { | ||
event: EVENT_COMPONENT_MOUNTED, | ||
payload: { | ||
component, | ||
appearanceProp: Boolean(props?.appearance), | ||
baseTheme: Boolean(props?.appearance?.baseTheme), | ||
elements: Boolean(props?.appearance?.elements), | ||
variables: Boolean(props?.appearance?.variables), | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { InstanceType } from '@clerk/types'; | ||
|
||
export type TelemetryCollectorOptions = { | ||
/** | ||
* If true, telemetry will not be collected. | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* If true, telemetry will not be sent, but collected events will be logged to the console. | ||
*/ | ||
debug?: boolean; | ||
/** | ||
* Sampling rate, 0-1 | ||
*/ | ||
samplingRate?: number; | ||
/** | ||
* Set a custom buffer size to control how often events are sent | ||
*/ | ||
maxBufferSize?: number; | ||
/** | ||
* The publishableKey to associate with the collected events. | ||
*/ | ||
publishableKey?: string; | ||
/** | ||
* The secretKey to associate with the collected events. | ||
*/ | ||
secretKey?: string; | ||
/** | ||
* The current clerk-js version. | ||
*/ | ||
clerkVersion?: string; | ||
/** | ||
* The SDK being used, e.g. `@clerk/nextjs` or `@clerk/remix`. | ||
*/ | ||
sdk?: string; | ||
/** | ||
* The version of the SDK being used. | ||
*/ | ||
sdkVersion?: string; | ||
}; | ||
|
||
export type TelemetryEvent = { | ||
event: string; | ||
/** | ||
* publishableKey | ||
*/ | ||
pk?: string; | ||
/** | ||
* secretKey | ||
*/ | ||
sk?: string; | ||
/** | ||
* instanceType | ||
*/ | ||
it: InstanceType; | ||
/** | ||
* clerkVersion | ||
*/ | ||
cv: string; | ||
/** | ||
* SDK | ||
*/ | ||
sdk?: string; | ||
/** | ||
* SDK Version | ||
*/ | ||
sdkv?: string; | ||
payload: Record<string, string | number | boolean>; | ||
}; | ||
|
||
export type TelemetryEventRaw<Payload = TelemetryEvent['payload']> = { | ||
event: TelemetryEvent['event']; | ||
payload: Payload; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters