File tree 19 files changed +94
-73
lines changed
19 files changed +94
-73
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @clerk/shared ' : patch
3
+ ' @clerk/types ' : patch
4
+ ' @clerk/elements ' : patch
5
+ ---
6
+
7
+ The following are all internal changes and not relevant to any end-user:
8
+
9
+ Create type interface for ` TelemetryCollector ` on ` @clerk/types ` . This allows to assign ` telemetry ` on the main Clerk SDK object, while inheriting from the actual ` TelemetryCollector ` implementation.
Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ export class Clerk implements ClerkInterface {
151
151
public organization : OrganizationResource | null | undefined ;
152
152
public user : UserResource | null | undefined ;
153
153
public __internal_country ?: string | null ;
154
- public telemetry ? : TelemetryCollector ;
154
+ public telemetry : TelemetryCollector | undefined ;
155
155
156
156
protected internal_last_error : ClerkAPIError | null = null ;
157
157
Original file line number Diff line number Diff line change
1
+ import { useClerk } from '@clerk/clerk-react' ;
1
2
import { eventComponentMounted } from '@clerk/shared/telemetry' ;
2
3
import type { Autocomplete } from '@clerk/types' ;
3
4
import { composeEventHandlers } from '@radix-ui/primitive' ;
@@ -35,7 +36,6 @@ import {
35
36
} from '~/internals/machines/form/form.context' ;
36
37
import { usePassword } from '~/react/hooks/use-password.hook' ;
37
38
import type { ErrorMessagesKey } from '~/react/utils/generate-password-error-text' ;
38
- import { useTelemetry } from '~/react/utils/telemetry' ;
39
39
40
40
import type { OTPInputProps } from './otp' ;
41
41
import { OTP_LENGTH_DEFAULT , OTPInput } from './otp' ;
@@ -530,9 +530,9 @@ type FormInputProps =
530
530
*/
531
531
const Input = React . forwardRef < React . ElementRef < typeof RadixControl > , FormInputProps > (
532
532
( props : FormInputProps , forwardedRef ) => {
533
- const telemetry = useTelemetry ( ) ;
533
+ const clerk = useClerk ( ) ;
534
534
535
- telemetry ?. record (
535
+ clerk . telemetry ?. record (
536
536
eventComponentMounted ( 'Elements_Input' , {
537
537
type : props . type ?? false ,
538
538
// @ts -expect-error - Depending on type the props can be different
Original file line number Diff line number Diff line change
1
+ import { useClerk } from '@clerk/clerk-react' ;
1
2
import { eventComponentMounted } from '@clerk/shared/telemetry' ;
2
3
import type { OAuthProvider , SamlStrategy } from '@clerk/types' ;
3
4
import * as React from 'react' ;
@@ -18,7 +19,6 @@ import type { TSignUpStep } from '~/react/sign-up/step';
18
19
import { SIGN_UP_STEPS } from '~/react/sign-up/step' ;
19
20
import { SignUpVerificationCtx } from '~/react/sign-up/verifications' ;
20
21
import { mapScopeToStrategy } from '~/react/utils/map-scope-to-strategy' ;
21
- import { useTelemetry } from '~/react/utils/telemetry' ;
22
22
23
23
type Strategy = OAuthProvider | SamlStrategy | 'metamask' ;
24
24
type LoadingScope < T extends TSignInStep | TSignUpStep > = 'global' | `step:${T } ` | `provider:${Strategy } ` | undefined ;
@@ -82,9 +82,9 @@ function isSignUpScope(scope: LoadingScope<TSignInStep | TSignUpStep>): scope is
82
82
* </SignIn.Step>
83
83
*/
84
84
export function Loading ( { children, scope } : LoadingProps ) {
85
- const telemetry = useTelemetry ( ) ;
85
+ const clerk = useClerk ( ) ;
86
86
87
- telemetry ?. record ( eventComponentMounted ( 'Elements_Loading' , { scope : scope ?? false } ) ) ;
87
+ clerk . telemetry ?. record ( eventComponentMounted ( 'Elements_Loading' , { scope : scope ?? false } ) ) ;
88
88
89
89
const signInRouterRef = SignInRouterCtx . useActorRef ( true ) ;
90
90
const signUpRouterRef = SignUpRouterCtx . useActorRef ( true ) ;
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import { SignInRouterMachine } from '~/internals/machines/sign-in';
10
10
import { consoleInspector } from '~/internals/utils/inspector' ;
11
11
import { Router , useClerkRouter , useNextRouter } from '~/react/router' ;
12
12
import { SignInRouterCtx } from '~/react/sign-in/context' ;
13
- import { useTelemetry } from '~/react/utils/telemetry' ;
14
13
15
14
import { Form } from '../common/form' ;
16
15
@@ -83,9 +82,9 @@ export function SignInRoot({
83
82
fallback = null ,
84
83
exampleMode,
85
84
} : SignInRootProps ) : JSX . Element | null {
86
- const telemetry = useTelemetry ( ) ;
85
+ const clerk = useClerk ( ) ;
87
86
88
- telemetry ?. record (
87
+ clerk . telemetry ?. record (
89
88
eventComponentMounted ( 'Elements_SignInRoot' , {
90
89
path,
91
90
fallback : Boolean ( fallback ) ,
Original file line number Diff line number Diff line change
1
+ import { useClerk } from '@clerk/clerk-react' ;
1
2
import { eventComponentMounted } from '@clerk/shared/telemetry' ;
2
3
3
4
import { ClerkElementsRuntimeError } from '~/internals/errors' ;
4
- import { useTelemetry } from '~/react/utils/telemetry' ;
5
5
6
6
import type { SignInChooseStrategyProps } from '../choose-strategy' ;
7
7
import { SignInChooseStrategy , SignInForgotPassword } from '../choose-strategy' ;
@@ -46,9 +46,9 @@ export type SignInStepProps =
46
46
* </SignIn.Root>
47
47
*/
48
48
export function SignInStep ( props : SignInStepProps ) {
49
- const telemetry = useTelemetry ( ) ;
49
+ const clerk = useClerk ( ) ;
50
50
51
- telemetry ?. record ( eventComponentMounted ( 'Elements_SignInStep' , { name : props . name } ) ) ;
51
+ clerk . telemetry ?. record ( eventComponentMounted ( 'Elements_SignInStep' , { name : props . name } ) ) ;
52
52
53
53
switch ( props . name ) {
54
54
case SIGN_IN_STEPS [ 'start' ] :
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import { SignUpRouterMachine } from '~/internals/machines/sign-up';
11
11
import { consoleInspector } from '~/internals/utils/inspector' ;
12
12
import { Router , useClerkRouter , useNextRouter } from '~/react/router' ;
13
13
import { SignUpRouterCtx } from '~/react/sign-up/context' ;
14
- import { useTelemetry } from '~/react/utils/telemetry' ;
15
14
16
15
import { Form } from '../common/form' ;
17
16
@@ -80,9 +79,9 @@ export function SignUpRoot({
80
79
fallback = null ,
81
80
exampleMode,
82
81
} : SignUpRootProps ) : JSX . Element | null {
83
- const telemetry = useTelemetry ( ) ;
82
+ const clerk = useClerk ( ) ;
84
83
85
- telemetry ?. record (
84
+ clerk . telemetry ?. record (
86
85
eventComponentMounted ( 'Elements_SignUpRoot' , {
87
86
path,
88
87
fallback : Boolean ( fallback ) ,
Original file line number Diff line number Diff line change
1
+ import { useClerk } from '@clerk/clerk-react' ;
1
2
import { eventComponentMounted } from '@clerk/shared/telemetry' ;
2
3
3
4
import { ClerkElementsRuntimeError } from '~/internals/errors' ;
4
- import { useTelemetry } from '~/react/utils/telemetry' ;
5
5
6
6
import type { SignUpContinueProps } from './continue' ;
7
7
import { SignUpContinue } from './continue' ;
@@ -39,9 +39,9 @@ export type SignUpStepProps =
39
39
* </SignUp.Root>
40
40
*/
41
41
export function SignUpStep ( props : SignUpStepProps ) {
42
- const telemetry = useTelemetry ( ) ;
42
+ const clerk = useClerk ( ) ;
43
43
44
- telemetry ?. record ( eventComponentMounted ( 'Elements_SignUpStep' , { name : props . name } ) ) ;
44
+ clerk . telemetry ?. record ( eventComponentMounted ( 'Elements_SignUpStep' , { name : props . name } ) ) ;
45
45
46
46
switch ( props . name ) {
47
47
case SIGN_UP_STEPS . start :
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 10
10
*
11
11
* For more information, please see the telemetry documentation page: https://clerk.com/docs/telemetry
12
12
*/
13
- import type { InstanceType } from '@clerk/types' ;
13
+ import type {
14
+ InstanceType ,
15
+ TelemetryCollector as TelemetryCollectorInterface ,
16
+ TelemetryEvent ,
17
+ TelemetryEventRaw ,
18
+ } from '@clerk/types' ;
14
19
15
20
import { parsePublishableKey } from '../keys' ;
16
21
import { isTruthy } from '../underscore' ;
17
22
import { TelemetryEventThrottler } from './throttler' ;
18
- import type { TelemetryCollectorOptions , TelemetryEvent , TelemetryEventRaw } from './types' ;
23
+ import type { TelemetryCollectorOptions } from './types' ;
19
24
20
25
type TelemetryCollectorConfig = Pick <
21
26
TelemetryCollectorOptions ,
@@ -42,7 +47,7 @@ const DEFAULT_CONFIG: Partial<TelemetryCollectorConfig> = {
42
47
endpoint : 'https://clerk-telemetry.com' ,
43
48
} ;
44
49
45
- export class TelemetryCollector {
50
+ export class TelemetryCollector implements TelemetryCollectorInterface {
46
51
#config: Required < TelemetryCollectorConfig > ;
47
52
#eventThrottler: TelemetryEventThrottler ;
48
53
#metadata: TelemetryMetadata = { } as TelemetryMetadata ;
Original file line number Diff line number Diff line change 1
- import type { TelemetryEventRaw } from '.. /types' ;
1
+ import type { TelemetryEventRaw } from '@clerk /types' ;
2
2
3
3
const EVENT_COMPONENT_MOUNTED = 'COMPONENT_MOUNTED' as const ;
4
4
const EVENT_SAMPLING_RATE = 0.1 ;
Original file line number Diff line number Diff line change 1
- import type { TelemetryEventRaw } from '.. /types' ;
1
+ import type { TelemetryEventRaw } from '@clerk /types' ;
2
2
3
3
const EVENT_METHOD_CALLED = 'METHOD_CALLED' as const ;
4
4
Original file line number Diff line number Diff line change 1
- import type { TelemetryEvent } from '. /types' ;
1
+ import type { TelemetryEvent } from '@clerk /types' ;
2
2
3
3
type TtlInMilliseconds = number ;
4
4
Original file line number Diff line number Diff line change 1
- import type { InstanceType } from '@clerk/types' ;
2
-
3
1
export type TelemetryCollectorOptions = {
4
2
/**
5
3
* If true, telemetry will not be collected.
@@ -38,38 +36,3 @@ export type TelemetryCollectorOptions = {
38
36
*/
39
37
sdkVersion ?: string ;
40
38
} ;
41
-
42
- export type TelemetryEvent = {
43
- event : string ;
44
- /**
45
- * publishableKey
46
- */
47
- pk ?: string ;
48
- /**
49
- * secretKey
50
- */
51
- sk ?: string ;
52
- /**
53
- * instanceType
54
- */
55
- it : InstanceType ;
56
- /**
57
- * clerkVersion
58
- */
59
- cv : string ;
60
- /**
61
- * SDK
62
- */
63
- sdk ?: string ;
64
- /**
65
- * SDK Version
66
- */
67
- sdkv ?: string ;
68
- payload : Record < string , string | number | boolean > ;
69
- } ;
70
-
71
- export type TelemetryEventRaw < Payload = TelemetryEvent [ 'payload' ] > = {
72
- event : TelemetryEvent [ 'event' ] ;
73
- eventSamplingRate ?: number ;
74
- payload : Payload ;
75
- } ;
Original file line number Diff line number Diff line change
1
+ import type { TelemetryCollector } from 'telemetry' ;
2
+
1
3
import type {
2
4
Appearance ,
3
5
CreateOrganizationTheme ,
@@ -11,6 +13,7 @@ import type {
11
13
} from './appearance' ;
12
14
import type { ClientResource } from './client' ;
13
15
import type { CustomPage } from './customPages' ;
16
+ import type { InstanceType } from './instance' ;
14
17
import type { DisplayThemeJSON } from './json' ;
15
18
import type { LocalizationResource } from './localization' ;
16
19
import type { OAuthProvider , OAuthScope } from './oauth' ;
@@ -30,8 +33,6 @@ import type { ActiveSessionResource } from './session';
30
33
import type { UserResource } from './user' ;
31
34
import type { Autocomplete , DeepPartial , DeepSnakeToCamel } from './utils' ;
32
35
33
- export type InstanceType = 'production' | 'development' ;
34
-
35
36
export type SDKMetadata = {
36
37
name : string ;
37
38
version : string ;
@@ -114,6 +115,8 @@ export interface Clerk {
114
115
/** Current User. */
115
116
user : UserResource | null | undefined ;
116
117
118
+ telemetry : TelemetryCollector | undefined ;
119
+
117
120
/**
118
121
* Signs out the current user on single-session instances, or all users on multi-session instances
119
122
* @param signOutCallback - Optional A callback that runs after sign out completes.
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export * from './factors';
15
15
export * from './identificationLink' ;
16
16
export * from './identifiers' ;
17
17
export * from './image' ;
18
+ export * from './instance' ;
18
19
export * from './json' ;
19
20
export * from './jwt' ;
20
21
export * from './key' ;
@@ -45,6 +46,7 @@ export * from './strategies';
45
46
export * from './theme' ;
46
47
export * from './token' ;
47
48
export * from './totp' ;
49
+ export * from './telemetry' ;
48
50
export * from './user' ;
49
51
export * from './userOrganizationInvitation' ;
50
52
export * from './userSettings' ;
Original file line number Diff line number Diff line change
1
+ export type InstanceType = 'production' | 'development' ;
Original file line number Diff line number Diff line change 1
- import type { InstanceType } from './clerk ' ;
1
+ import type { InstanceType } from './instance ' ;
2
2
3
3
export type PublishableKey = {
4
4
frontendApi : string ;
Original file line number Diff line number Diff line change
1
+ import type { InstanceType } from 'instance' ;
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ export type TelemetryEvent = {
7
+ event : string ;
8
+ /**
9
+ * publishableKey
10
+ */
11
+ pk ?: string ;
12
+ /**
13
+ * secretKey
14
+ */
15
+ sk ?: string ;
16
+ /**
17
+ * instanceType
18
+ */
19
+ it : InstanceType ;
20
+ /**
21
+ * clerkVersion
22
+ */
23
+ cv : string ;
24
+ /**
25
+ * SDK
26
+ */
27
+ sdk ?: string ;
28
+ /**
29
+ * SDK Version
30
+ */
31
+ sdkv ?: string ;
32
+ payload : Record < string , string | number | boolean > ;
33
+ } ;
34
+
35
+ /**
36
+ * @internal
37
+ */
38
+ export type TelemetryEventRaw < Payload = TelemetryEvent [ 'payload' ] > = {
39
+ event : TelemetryEvent [ 'event' ] ;
40
+ eventSamplingRate ?: number ;
41
+ payload : Payload ;
42
+ } ;
43
+
44
+ export interface TelemetryCollector {
45
+ isEnabled : boolean ;
46
+ isDebug : boolean ;
47
+ record ( event : TelemetryEventRaw ) : void ;
48
+ }
You can’t perform that action at this time.
0 commit comments