Skip to content

fix: replace direct console.* calls with windowLogger in window package#1594

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1771608836-window-use-sdk-logger
Open

fix: replace direct console.* calls with windowLogger in window package#1594
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1771608836-window-use-sdk-logger

Conversation

@devin-ai-integration
Copy link
Contributor

Description

Replaces all 14 direct console.info() / console.error() calls in @crossmint/client-sdk-window with a new windowLogger (SdkLogger instance), so that these logs respect the consoleLogLevel setting (e.g. "silent").

Previously, the EventEmitter, HandshakeParent, and HandshakeChild classes logged directly to the console, bypassing the SDK logger system entirely.

This is part of a series of per-package PRs to route all SDK console output through SdkLogger. See related PRs: #1592 (wallets), #1593 (auth).

Files changed:

  • src/logger.ts — new file; creates windowLogger instance and initWindowLogger(apiKey) initializer
  • src/EventEmitter.ts — 10 console calls → windowLogger
  • src/handshake/Parent.ts — 2 console calls → windowLogger
  • src/handshake/Child.ts — 2 console calls → windowLogger
  • src/index.ts — exports windowLogger and initWindowLogger
  • package.json — adds @crossmint/common-sdk-base workspace dependency

⚠️ Items for reviewer attention

  1. initWindowLogger is exported but never called within this package. A consuming package (e.g. react-base provider) must call initWindowLogger(apiKey) for the logger to be fully initialized. Until then, SdkLogger falls back to raw console.* — meaning the silent behavior won't take effect for window logs until the init call is wired up upstream.
  2. New dependency: @crossmint/common-sdk-base is added to this previously minimal package (only had zod). Verify this is acceptable for bundle size.

Test plan

  • Lint passes (pnpm lint)
  • Manual verification: confirm no remaining direct console.* calls in packages/client/window/src/
  • No existing tests were broken (package has no test suite)

Package updates

  • @crossmint/client-sdk-window: patch (changeset added)

Link to Devin run: https://crossmint.devinenterprise.com/sessions/3befe224fd2b472594dafcd3fc100e7e
Requested by: @xmint-guille

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

🦋 Changeset detected

Latest commit: fa67bad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@crossmint/client-sdk-window Patch
@crossmint/client-sdk-base Patch
@crossmint/client-sdk-react-base Patch
@crossmint/client-sdk-rn-window Patch
@crossmint/client-sdk-react-ui Patch
@crossmint/wallets-sdk Patch
@crossmint/client-sdk-nextjs-starter Patch
@crossmint/client-sdk-auth Patch
@crossmint/client-sdk-react-native-ui Patch
@crossmint/client-sdk-verifiable-credentials Patch
@crossmint/client-sdk-smart-wallet Patch
@crossmint/common-sdk-auth Patch
expo-demo Patch
@crossmint/auth-ssr-nextjs-demo Patch
@crossmint/wallets-quickstart-devkit Patch
@crossmint/server-sdk Patch
crossmint-auth-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration
Copy link
Contributor Author

Original prompt from Guille
we introduced the following change here to supress logs in our sdks:
https://github.com/Crossmint/crossmint-sdk/commit/27194e5751fd4bb3afb190550382760f978d7a20

i've tried this with the following code snippet, and I can still see logs once I'm logged in:
```ts
"use client";

import {
  CrossmintProvider,
  CrossmintAuthProvider,
  CrossmintWalletProvider,
  useAuth,
  useWallet,
} from "@crossmint/client-sdk-react-ui";

function WalletUser() {
  const { login, user } = useAuth();
  const { wallet, status } = useWallet();

  return (
    <div>
      {user == null ? (
        <button onClick={login}>Sign In</button>
      ) : (
        <p>
          Wallet: {wallet?.address} ({status})
        </p>
      )}
    </div>
  );
}

export default function Page() {
  return (
    <CrossmintProvider
      apiKey={process.env.NEXT_PUBLIC_CLIENT_API_KEY ?? ""}
      consoleLogLevel="silent"
    >
      <CrossmintAuthProvider>
        <CrossmintWalletProvider
          createOnLogin={{
            chain: "polygon-amoy",
            signer: { type: "email" },
          }}
        >
          <WalletUser />
        </CrossmintWalletProvider>
      </CrossmintAuthProvider>
    </CrossmintProvider>
  );
}

can you determine the issue and propose a PR in case it's feasible to maintain the silent logs flag in every part of our sdks?

</details>

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +16 to +20
const { environment, projectId } = validationResult;
windowLogger.init({
packageName: "@crossmint/client-sdk-window",
environment,
projectId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packageVersion is missing from init params

The wallets package's initWalletsLogger passes both packageName and packageVersion to logger.init() (packages/wallets/src/logger/init.ts:30-31). This implementation should follow the same pattern for consistency and better log traceability.

Suggested change
const { environment, projectId } = validationResult;
windowLogger.init({
packageName: "@crossmint/client-sdk-window",
environment,
projectId,
const { environment, projectId } = validationResult;
windowLogger.init({
packageName: "@crossmint/client-sdk-window",
packageVersion: "1.0.9", // Consider importing from package.json via a constants file
environment,
projectId,
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/window/src/logger.ts
Line: 16-20

Comment:
`packageVersion` is missing from init params

The wallets package's `initWalletsLogger` passes both `packageName` and `packageVersion` to logger.init() (packages/wallets/src/logger/init.ts:30-31). This implementation should follow the same pattern for consistency and better log traceability.

```suggestion
    const { environment, projectId } = validationResult;
    windowLogger.init({
        packageName: "@crossmint/client-sdk-window",
        packageVersion: "1.0.9", // Consider importing from package.json via a constants file
        environment,
        projectId,
    });
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +22 to +29

const platform = detectPlatform();
if (platform === "browser") {
const sink = new BrowserDatadogSink(environment);
windowLogger.addSink(sink);
} else if (platform === "server") {
const sink = new ServerDatadogSink(environment);
windowLogger.addSink(sink);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use switch statement for consistency with wallets package pattern

The wallets package's initWalletsLogger uses a switch statement for platform handling (packages/wallets/src/logger/init.ts:38-61), which is more consistent and makes it easier to add future platforms like react-native.

Suggested change
const platform = detectPlatform();
if (platform === "browser") {
const sink = new BrowserDatadogSink(environment);
windowLogger.addSink(sink);
} else if (platform === "server") {
const sink = new ServerDatadogSink(environment);
windowLogger.addSink(sink);
const platform = detectPlatform();
switch (platform) {
case "browser": {
const sink = new BrowserDatadogSink(environment);
windowLogger.addSink(sink);
break;
}
case "server": {
const sink = new ServerDatadogSink(environment);
windowLogger.addSink(sink);
break;
}
default: {
// Unknown platform - only use console sink
break;
}
}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/window/src/logger.ts
Line: 22-29

Comment:
use switch statement for consistency with wallets package pattern

The wallets package's `initWalletsLogger` uses a switch statement for platform handling (packages/wallets/src/logger/init.ts:38-61), which is more consistent and makes it easier to add future platforms like react-native.

```suggestion
    const platform = detectPlatform();
    switch (platform) {
        case "browser": {
            const sink = new BrowserDatadogSink(environment);
            windowLogger.addSink(sink);
            break;
        }
        case "server": {
            const sink = new ServerDatadogSink(environment);
            windowLogger.addSink(sink);
            break;
        }
        default: {
            // Unknown platform - only use console sink
            break;
        }
    }
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +11 to +14
export function initWindowLogger(apiKey: string): void {
const validationResult = validateAPIKey(apiKey);
if (!validationResult.isValid) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

silently returning on invalid API key is inconsistent with the wallets package pattern

The wallets package's initWalletsLogger at packages/wallets/src/logger/init.ts:24-26 throws an error when the API key is invalid, while this implementation silently returns. This inconsistency could make debugging harder since users won't know why logging isn't working. Consider throwing an error with the validation message instead.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/window/src/logger.ts
Line: 11-14

Comment:
silently returning on invalid API key is inconsistent with the wallets package pattern

The wallets package's `initWalletsLogger` at packages/wallets/src/logger/init.ts:24-26 throws an error when the API key is invalid, while this implementation silently returns. This inconsistency could make debugging harder since users won't know why logging isn't working. Consider throwing an error with the validation message instead.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant