Skip to content

feat: adds workspace support#47

Open
pandeymangg wants to merge 1 commit intoepic/v5from
feat/workspace-support
Open

feat: adds workspace support#47
pandeymangg wants to merge 1 commit intoepic/v5from
feat/workspace-support

Conversation

@pandeymangg
Copy link
Copy Markdown
Contributor

Adds support for workspaceId and keeps support for environmentId as well for backwards compatibility by marking it as deprecated. Similar to the js-core changes for this

@pandeymangg pandeymangg changed the base branch from main to epic/v5 April 24, 2026 06:22
@sonarqubecloud
Copy link
Copy Markdown

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

Walkthrough

This pull request updates the Formbricks JavaScript SDK's setup configuration to support workspaceId as an alternative identifier alongside the existing environmentId. The changes introduce a new TSetupConfig type that accepts appUrl with either workspaceId or environmentId (or both). Validation logic is updated to require at least one identifier and emit a deprecation warning when only environmentId is used. Documentation and test coverage are expanded to reflect the new configuration option while maintaining backward compatibility with existing deployments using environmentId.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: adds workspace support' clearly describes the main change—introducing workspace ID support—which aligns with the core modifications across all changed files.
Description check ✅ Passed The description is directly related to the changeset, explaining that workspaceId support is added while environmentId remains for backward compatibility and is marked deprecated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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
Copy Markdown

@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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/js/src/lib/load-formbricks.test.ts`:
- Around line 4-8: Replace the inline config shape with the canonical
TSetupConfig type: add a static import of TSetupConfig from the types module at
the top of the test file and change the setup declaration to use TSetupConfig
(i.e. let setup: (config: TSetupConfig) => Promise<void>), keeping the dynamic
import("./load-formbricks") behavior for runtime module reset unchanged so only
the type is resolved statically.

In `@packages/js/src/lib/load-formbricks.ts`:
- Around line 79-80: The parameter to validateSetupArgs should be typed as
TSetupConfig instead of unknown; change the signature from
validateSetupArgs(config: unknown) to validateSetupArgs(config: TSetupConfig),
remove the runtime cast (config as TSetupConfig) and destructure directly (const
{ appUrl, environmentId, workspaceId } = config), and ensure any callers (e.g.,
setup) already passing a TSetupConfig keep their types so the compiler surfaces
typos like enviromentId.

In `@packages/js/src/types/formbricks.ts`:
- Around line 6-13: Replace the inline setupConfig object in the
TFormbricks.setup signature with the existing TSetupConfig type to avoid
duplication; update the setup signature to accept (setupConfig: TSetupConfig) =>
Promise<void>, ensuring TSetupConfig (the type that includes environmentId,
workspaceId, appUrl and the `@deprecated` JSDoc) is referenced instead of
redefining the shape, and keep TSetupConfig declared in the same module (no
reordering required).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0eb613f6-4063-4367-8ebf-7fb00e8c2ae9

📥 Commits

Reviewing files that changed from the base of the PR and between ca8bd8c and c6e0f02.

📒 Files selected for processing (5)
  • packages/js/README.md
  • packages/js/src/index.test.ts
  • packages/js/src/lib/load-formbricks.test.ts
  • packages/js/src/lib/load-formbricks.ts
  • packages/js/src/types/formbricks.ts

Comment on lines +4 to +8
let setup: (config: {
appUrl: string;
workspaceId?: string;
environmentId?: string;
}) => Promise<void>;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider importing TSetupConfig instead of redeclaring its shape.

This inline type mirrors TSetupConfig from packages/js/src/types/formbricks.ts. Since dynamic import("./load-formbricks") is used to reset module state, only the runtime value needs to be re-resolved — the type can be imported statically at the top of the file so it stays in sync with the source of truth.

♻️ Proposed change
 import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+import type { TSetupConfig } from "../types/formbricks";

 // We need to import the module after each reset
-let setup: (config: {
-  appUrl: string;
-  workspaceId?: string;
-  environmentId?: string;
-}) => Promise<void>;
+let setup: (config: TSetupConfig) => Promise<void>;
 let callMethod: (method: string, ...args: unknown[]) => Promise<void>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/js/src/lib/load-formbricks.test.ts` around lines 4 - 8, Replace the
inline config shape with the canonical TSetupConfig type: add a static import of
TSetupConfig from the types module at the top of the test file and change the
setup declaration to use TSetupConfig (i.e. let setup: (config: TSetupConfig) =>
Promise<void>), keeping the dynamic import("./load-formbricks") behavior for
runtime module reset unchanged so only the type is resolved statically.

Comment on lines +79 to +80
const validateSetupArgs = (config: unknown): TSetupConfig | null => {
const { appUrl, environmentId, workspaceId } = config as TSetupConfig;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Tighten validateSetupArgs parameter typing.

config: unknown followed by config as TSetupConfig is strictly weaker than typing the parameter as TSetupConfig. The sole caller (setup, line 136) already constrains config to TSetupConfig, so the unknown + cast adds no runtime safety and removes compile-time safety (e.g., a typo like config.enviromentId would no longer surface).

♻️ Proposed change
-const validateSetupArgs = (config: unknown): TSetupConfig | null => {
-  const { appUrl, environmentId, workspaceId } = config as TSetupConfig;
+const validateSetupArgs = (config: TSetupConfig): TSetupConfig | null => {
+  const { appUrl, environmentId, workspaceId } = config;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const validateSetupArgs = (config: unknown): TSetupConfig | null => {
const { appUrl, environmentId, workspaceId } = config as TSetupConfig;
const validateSetupArgs = (config: TSetupConfig): TSetupConfig | null => {
const { appUrl, environmentId, workspaceId } = config;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/js/src/lib/load-formbricks.ts` around lines 79 - 80, The parameter
to validateSetupArgs should be typed as TSetupConfig instead of unknown; change
the signature from validateSetupArgs(config: unknown) to
validateSetupArgs(config: TSetupConfig), remove the runtime cast (config as
TSetupConfig) and destructure directly (const { appUrl, environmentId,
workspaceId } = config), and ensure any callers (e.g., setup) already passing a
TSetupConfig keep their types so the compiler surfaces typos like enviromentId.

Comment on lines 6 to 13
setup: (setupConfig: {
environmentId: string;
/**
* @deprecated use workspaceId instead, environmentId will be removed in a future version
*/
environmentId?: string;
workspaceId?: string;
appUrl: string;
}) => Promise<void>;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Deduplicate: reuse TSetupConfig in the setup signature.

The inline setupConfig shape here (lines 7-12) is a verbatim copy of the newly added TSetupConfig (lines 75-82), including the @deprecated JSDoc. The two definitions will drift (e.g., next time the deprecation wording or field set changes). Since TSetupConfig is declared in the same file, prefer referencing it directly.

♻️ Proposed refactor
 export interface TFormbricks {
   /**
    * `@description` Initializes the Formbricks SDK.
    * `@param` setupConfig - The configuration for the Formbricks SDK.
    */
-  setup: (setupConfig: {
-    /**
-     * `@deprecated` use workspaceId instead, environmentId will be removed in a future version
-     */
-    environmentId?: string;
-    workspaceId?: string;
-    appUrl: string;
-  }) => Promise<void>;
+  setup: (setupConfig: TSetupConfig) => Promise<void>;

Note: this requires moving/hoisting the TSetupConfig declaration above TFormbricks, or adding a forward type alias — TypeScript allows type references inside an interface to resolve regardless of order in the same module.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
setup: (setupConfig: {
environmentId: string;
/**
* @deprecated use workspaceId instead, environmentId will be removed in a future version
*/
environmentId?: string;
workspaceId?: string;
appUrl: string;
}) => Promise<void>;
setup: (setupConfig: TSetupConfig) => Promise<void>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/js/src/types/formbricks.ts` around lines 6 - 13, Replace the inline
setupConfig object in the TFormbricks.setup signature with the existing
TSetupConfig type to avoid duplication; update the setup signature to accept
(setupConfig: TSetupConfig) => Promise<void>, ensuring TSetupConfig (the type
that includes environmentId, workspaceId, appUrl and the `@deprecated` JSDoc) is
referenced instead of redefining the shape, and keep TSetupConfig declared in
the same module (no reordering required).

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