Skip to content

Conversation

@Dhruwang
Copy link
Member

Add setNonce to types so that formbricks.setNonce() does not throw a type error

@Dhruwang Dhruwang requested a review from mattinannt November 11, 2025 05:56
@sonarqubecloud
Copy link

@coderabbitai
Copy link

coderabbitai bot commented Nov 11, 2025

Walkthrough

The pull request updates the JavaScript package with a version bump from 4.2.1 to 4.3.1. In the TypeScript type definitions for Formbricks, a new public method setNonce(nonce: string) was added that returns a Promise. Additionally, a minor formatting adjustment was made to the track method's parameter type definition by removing a trailing comma after the hiddenFields property, though the type structure remains unchanged.

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'added setNonce to types' directly and clearly summarizes the main change in the changeset: adding the setNonce method to the TFormbricks type definitions.
Description check ✅ Passed The description 'Add setNonce to types so that formbricks.setNonce() does not throw a type error' is directly related to the changeset and explains the purpose of adding the setNonce method.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44936b0 and d8a7db4.

📒 Files selected for processing (2)
  • packages/js/package.json (2 hunks)
  • packages/js/src/types/formbricks.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-24T17:04:00.743Z
Learnt from: pandeymangg
Repo: formbricks/js PR: 6
File: packages/js/src/lib/load-formbricks.test.ts:96-114
Timestamp: 2025-09-24T17:04:00.743Z
Learning: The formbricks/js project uses happy-dom as the test environment in Vitest configuration (packages/js/vite.config.ts), not jsdom. This configuration works well for DOM-dependent tests and is faster than jsdom.

Applied to files:

  • packages/js/package.json
📚 Learning: 2025-09-24T17:04:00.743Z
Learnt from: pandeymangg
Repo: formbricks/js PR: 6
File: packages/js/src/lib/load-formbricks.test.ts:96-114
Timestamp: 2025-09-24T17:04:00.743Z
Learning: The formbricks/js project uses happy-dom as the test environment in Vitest configuration, not jsdom. This is configured in packages/js/vite.config.ts and works well for DOM-dependent tests.

Applied to files:

  • packages/js/package.json
🔇 Additional comments (2)
packages/js/package.json (1)

4-4: LGTM! Appropriate version bump for the new feature.

The minor version bump from 4.2.1 to 4.3.1 is appropriate for adding the new setNonce public method, following semantic versioning conventions for backward-compatible functionality.

packages/js/src/types/formbricks.ts (1)

25-30: Minor formatting improvement.

The trailing comma was removed after the hiddenFields property. This is a formatting-only change with no functional impact on the type definition.

logout: () => Promise<void>;

registerRouteChange: () => Promise<void>;
setNonce: (nonce: string) => Promise<void>;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

New setNonce method added - verify implementation and tests.

The type signature looks correct and follows the pattern of other setter methods in the interface. However, please ensure:

  1. The implementation exists in the main Formbricks class
  2. Unit tests cover the new method
  3. The method correctly handles the nonce value for CSP compliance

Run the following script to verify the implementation and tests exist:


🏁 Script executed:

#!/bin/bash
# Description: Verify setNonce implementation and tests exist

echo "=== Searching for setNonce implementation ==="
ast-grep --pattern 'setNonce($$$) {
  $$$
}'

echo -e "\n=== Searching for setNonce in class/object definitions ==="
rg -nP --type=ts -C3 'setNonce\s*[:=]\s*(\(|async)'

echo -e "\n=== Searching for setNonce tests ==="
rg -nP --type=ts -C3 'describe|it|test.*setNonce|setNonce.*describe|it|test'

Length of output: 60395


setNonce method requires implementation and tests - type-only addition is incomplete.

The type definition was added but the actual implementation and tests are missing. Other methods (setEmail, setAttribute, setUserId, etc.) in the codebase follow a consistent pattern where each has both an implementation that proxies through loadFormbricksToProxy and corresponding test coverage in packages/js/src/index.test.ts.

Add:

  1. Implementation that proxies the nonce parameter through loadFormbricksToProxy (consistent with other setter methods)
  2. Test case in packages/js/src/index.test.ts following the existing pattern for other setter methods
🤖 Prompt for AI Agents
In packages/js/src/types/formbricks.ts around line 35, the setNonce type was
added but not implemented; add a setNonce implementation in the corresponding
module (same file or the module that defines the other setters) that mirrors the
pattern of setEmail/setAttribute/setUserId by calling loadFormbricksToProxy()
and invoking the proxy method with the nonce parameter, returning the
Promise<void> result; also add a unit test in packages/js/src/index.test.ts
following the existing setter tests (mock loadFormbricksToProxy, call setNonce
with a test value, and assert the proxy was called with the correct method name
and nonce argument and that the returned promise resolves).

@krilllind
Copy link

Hello 👋

Wanted to check in on the status of this PR.
I see the nonce change has been released in version 4.3.0 but I am unable to call the new setNonce function on the js package as it's not typed. While I can patch it locally it would be nice to get this updated version available 😊

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

@Dhruwang Thank you for the PR :-)
I only have one concern regarding the version. We should do a new release for the js package next week when Anshuman has also merged his new changes.

"name": "@formbricks/js",
"license": "MIT",
"version": "4.2.1",
"version": "4.3.1",
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't change the version here at this moment, we should do this when we do a new release.
(and then we will likely go from 4.2.1 to 4.3.0 instead of 4.3.1 ;-) )

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.

4 participants