-
Notifications
You must be signed in to change notification settings - Fork 371
feat(clerk-js): Introduce debugLogger #6452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jacekradko
wants to merge
39
commits into
main
Choose a base branch
from
feat/debug-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,548
−29
Open
Changes from 25 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ab3cde4
feat(clerk-js): Introduce debugLogger
jacekradko 4931533
small fixes
jacekradko f9a6a97
Merge branch 'main' into feat/debug-module
jacekradko d24c0e8
changeset
jacekradko 0f1803d
coderabbit
jacekradko 3ba5c80
Merge branch 'main' into feat/debug-module
jacekradko 775fccb
fix build
jacekradko b6f886a
wip
jacekradko eaeacb8
safe initializations
jacekradko c3e6e52
wip
jacekradko bd86e19
pr feedback
jacekradko a7cfc1f
pr feedback
jacekradko 806688a
Merge branch 'main' into feat/debug-module
jacekradko 9c234a4
Merge branch 'main' into feat/debug-module
jacekradko 496cd4c
Integrate telemetry collector
jacekradko aedc788
correct telemetry endpoint
jacekradko 9828a80
tests
jacekradko 32ce445
wip
jacekradko 053efaf
Merge branch 'main' into feat/debug-module
jacekradko 59b998e
fix lint and test
jacekradko 7c311cc
wip
jacekradko 4bcf294
Merge branch 'main' into feat/debug-module
jacekradko 441061e
wip
jacekradko d79b5db
Merge branch 'main' into feat/debug-module
jacekradko 2170de0
refactor flush methods to avoid stacking requests
jacekradko 7604e58
remove redundant try/catch
jacekradko cfc5a05
consistent flush logic
jacekradko 2f4b36b
Resolve merge conflicts: bundlewatch thresholds, TelemetryCollector l…
jacekradko 5ff7b86
wip
jacekradko 1562ebf
Merge branch 'main' into feat/debug-module
jacekradko f532cf0
wip
jacekradko 55bda4e
Merge branch 'main' into feat/debug-module
jacekradko 243f598
pr feedback
jacekradko b25d4d4
pr feedback
jacekradko a1994c4
wip
jacekradko fa0cffd
Merge branch 'main' into feat/debug-module
jacekradko e544597
fix lint
jacekradko c7798ff
Merge branch 'main' into feat/debug-module
jacekradko 275ba94
wip
jacekradko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Introduce debugLogger for internal debugging support |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -160,6 +160,32 @@ type SetActiveHook = (intent?: 'sign-out') => void | Promise<void>; | |
|
||
export type ClerkCoreBroadcastChannelEvent = { type: 'signout' }; | ||
|
||
/** | ||
* Interface for the debug logger with all available logging methods | ||
*/ | ||
interface DebugLoggerInterface { | ||
debug(message: string, context?: Record<string, unknown>, source?: string): void; | ||
error(message: string, context?: Record<string, unknown>, source?: string): void; | ||
info(message: string, context?: Record<string, unknown>, source?: string): void; | ||
trace(message: string, context?: Record<string, unknown>, source?: string): void; | ||
warn(message: string, context?: Record<string, unknown>, source?: string): void; | ||
} | ||
|
||
/** | ||
* Type guard to check if an object implements the DebugLoggerInterface | ||
*/ | ||
function _isDebugLogger(obj: unknown): obj is DebugLoggerInterface { | ||
return ( | ||
typeof obj === 'object' && | ||
obj !== null && | ||
typeof (obj as DebugLoggerInterface).debug === 'function' && | ||
typeof (obj as DebugLoggerInterface).error === 'function' && | ||
typeof (obj as DebugLoggerInterface).info === 'function' && | ||
typeof (obj as DebugLoggerInterface).trace === 'function' && | ||
typeof (obj as DebugLoggerInterface).warn === 'function' | ||
); | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
Clerk?: Clerk; | ||
|
@@ -199,8 +225,8 @@ export class Clerk implements ClerkInterface { | |
public static sdkMetadata: SDKMetadata = { | ||
name: __PKG_NAME__, | ||
version: __PKG_VERSION__, | ||
environment: process.env.NODE_ENV || 'production', | ||
}; | ||
|
||
private static _billing: CommerceBillingNamespace; | ||
private static _apiKeys: APIKeysNamespace; | ||
private _checkout: ClerkInterface['__experimental_checkout'] | undefined; | ||
|
@@ -211,6 +237,7 @@ export class Clerk implements ClerkInterface { | |
public user: UserResource | null | undefined; | ||
public __internal_country?: string | null; | ||
public telemetry: TelemetryCollector | undefined; | ||
public debugLogger?: DebugLoggerInterface; // Properly typed debug logger interface | ||
|
||
protected internal_last_error: ClerkAPIError | null = null; | ||
// converted to protected environment to support `updateEnvironment` type assertion | ||
|
@@ -1503,6 +1530,7 @@ export class Clerk implements ClerkInterface { | |
const customNavigate = | ||
options?.replace && this.#options.routerReplace ? this.#options.routerReplace : this.#options.routerPush; | ||
|
||
this.debugLogger?.info(`Clerk is navigating to: ${toURL}`); | ||
if (this.#options.routerDebug) { | ||
console.log(`Clerk is navigating to: ${toURL}`); | ||
} | ||
|
@@ -2227,6 +2255,23 @@ export class Clerk implements ClerkInterface { | |
|
||
public updateEnvironment(environment: EnvironmentResource): asserts this is { environment: EnvironmentResource } { | ||
this.environment = environment; | ||
|
||
// Initialize debug module if client_debug_mode is enabled | ||
if (environment.clientDebugMode) { | ||
this.#initializeDebugModule(); | ||
} | ||
} | ||
|
||
async #initializeDebugModule(): Promise<void> { | ||
try { | ||
const { getDebugLogger } = await import('./modules/debug'); | ||
const logger = await getDebugLogger({}); | ||
if (_isDebugLogger(logger)) { | ||
this.debugLogger = logger; | ||
} | ||
} catch (error) { | ||
console.error('Failed to initialize debug module:', error); | ||
} | ||
} | ||
|
||
__internal_setCountry = (country: string | null) => { | ||
|
@@ -2870,4 +2915,13 @@ export class Clerk implements ClerkInterface { | |
|
||
return allowedProtocols; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public static async __internal_resetDebugLogger(): Promise<void> { | ||
// This method is now handled by the debug module itself | ||
const { __internal_resetDebugLogger } = await import('./modules/debug'); | ||
__internal_resetDebugLogger(); | ||
} | ||
Comment on lines
+2942
to
+2949
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove this and rely on the method from the module? |
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be in
load()
after we fetch environment