Skip to content

feat: add group and context management hooks#7

Open
rtb-12 wants to merge 2 commits intomainfrom
feat/group-context-hooks
Open

feat: add group and context management hooks#7
rtb-12 wants to merge 2 commits intomainfrom
feat/group-context-hooks

Conversation

@rtb-12
Copy link
Copy Markdown

@rtb-12 rtb-12 commented Mar 31, 2026

Summary

  • add reusable mero-react hooks for application context discovery, group listing, group membership, invitations, joining, and capabilities management
  • update useContexts(applicationId) to use the application-scoped admin API instead of fetching all contexts and filtering client-side
  • point local mero-react testing at the local mero-js package and add focused hook tests for the new flows

Test plan

  • cd mero-react && pnpm test
  • cd mero-react && pnpm typecheck
  • cd mero-react && pnpm build

Documentation update

  • Not needed

Made with Cursor


Note

Medium Risk
Medium risk because it expands the public hook surface area and changes useContexts fetching behavior to call a different admin API, which could affect consumers’ data loading patterns. Logic is mostly additive and covered by new hook tests, but correctness depends on mero-js admin API contracts (including alias lookup/polling).

Overview
Adds a new set of React hooks for group and context administration (listing groups, fetching members/contexts, creating/joining/inviting, updating member capabilities, syncing/deleting groups, and creating/deleting/joining contexts), with shared unmount-safe async handling.

Updates useContexts to use admin.getContextsForApplication(applicationId) instead of fetching all contexts and filtering client-side, and introduces useContextDiscovery to poll for a newly created context (optionally via alias lookup) with timeout/error reporting.

Exports the new hooks and related types (ApplicationContextRecord, ContextDiscoveryOptions/State) from the package entrypoint, and adds a comprehensive jsdom-based test suite for the new hook flows; dev setup now points @calimero-network/mero-js at a local file: dependency and adds TS path mapping for local typings.

Written by Cursor Bugbot for commit 4afae67. This will update automatically on new commits. Configure here.

Expose reusable group and application context hooks in mero-react so apps can rely on the shared admin surface instead of wiring raw SDK calls themselves. Point local testing at the local mero-js package and add focused hook coverage for the new context discovery and group management flows.

Made-with: Cursor
},
"dependencies": {
"@calimero-network/mero-js": "^1.2.1"
"@calimero-network/mero-js": "file:../mero-js"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Local file path dependency committed to package.json

High Severity

The @calimero-network/mero-js dependency was changed from ^1.2.1 (npm registry) to file:../mero-js (local path). This breaks pnpm install for anyone cloning the repo who doesn't have a sibling mero-js directory, and would produce a broken package on npm publish. The same issue applies to the tsconfig.json paths entry pointing at ../mero-js/dist/index.d.ts. The PR description confirms these changes were intended only for local testing.

Additional Locations (1)
Fix in Cursor Fix in Web

}

await sleep(pollIntervalMs);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Discovery polling loop continues after component unmount

Medium Severity

The useContextDiscovery polling loop does not check mountedRef.current between iterations. If the component unmounts while discover() is running, the loop keeps making API calls (lookupContextAlias and getContextsForApplication) on each poll cycle until the timeout expires (default 30 seconds). State updates are guarded, but the unnecessary network requests continue.

Fix in Cursor Fix in Web

Added new hooks for context and group management, including create, delete, invite, and join functionalities. Updated the index files to export these hooks and their types, improving the overall API for easier integration. Enhanced test coverage for the new hooks to ensure reliability and correctness.
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

options.pollIntervalMs,
options.targetAlias,
options.timeoutMs,
]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Redundant dependency defeats serialized key stabilization purpose

Low Severity

The discover callback's dependency array includes both knownContextIdsKey (the serialized string) and options.knownContextIds (the raw array). Including the raw array reference defeats the purpose of serializing it into knownContextIdsKey for stable comparison, since the callback will still be recreated whenever the array reference changes. The useSubscription hook in the same file demonstrates the correct pattern — only including the serialized contextIdsKey.

Fix in Cursor Fix in Web

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