Skip to content

feat(actions): add community export hook#62

Merged
tomcasaburi merged 6 commits into
masterfrom
feature/export-community
Jun 7, 2026
Merged

feat(actions): add community export hook#62
tomcasaburi merged 6 commits into
masterfrom
feature/export-community

Conversation

@tomcasaburi

@tomcasaburi tomcasaburi commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Upgrade @pkcprotocol/pkc-js to 0.0.41.
  • Add accountsActions.exportCommunity() and useExportCommunity() for one, many, or all account communities.
  • Update the pkc-js mock, public exports, types, README, and generated LLM context.

Verification

  • yarn build
  • yarn test
  • yarn test:coverage

Note: node scripts/verify-hooks-stores-coverage.mjs still reports existing repo-wide hooks/stores coverage gaps outside this feature.


Note

Medium Risk
Touches account actions and optional private-key export via upgraded pkc-js; well-covered by tests but desktop/export paths warrant careful review.

Overview
Adds desktop community export end-to-end: bumps @pkcprotocol/pkc-js to 0.0.41, implements accountsActions.exportCommunity() (single address, list, or default to all PKC-listed communities; concurrent exports; optional includePrivateKey / exportPath), and exposes useExportCommunity() with state / error / communityExports and context-aware clearing when the account or export targets change.

Public API updates include new ExportCommunityOptions / CommunityExport types, package exports, README and LLM docs recipes, and mock Community.export for tests.

Reviewed by Cursor Bugbot for commit 14b96b0. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features

    • Added useExportCommunity hook enabling users to export single, multiple, or all communities associated with their account
    • Desktop-only export functionality with built-in state and error handling
  • Documentation

    • Updated API reference with new export hook documentation
    • Added export communities recipe with practical usage examples
  • Chores

    • Updated @pkcprotocol/pkc-js dependency to v0.0.41

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces community export functionality by adding a new useExportCommunity React hook and supporting store action. The implementation flows from type contracts through Community model enhancement, store orchestration, React hook wrapper, public API export, comprehensive tests, and documentation examples. A dependency version update to @pkcprotocol/pkc-js provides the underlying support.

Changes

Community Export Feature

Layer / File(s) Summary
Export type contracts
src/types.ts
New types define UseExportCommunityOptions, UseExportCommunityResult, ExportCommunityOptions, and CommunityExport to shape the export API surface.
Community export model capability
src/lib/pkc-js/pkc-js-mock.ts
Community class adds publicKey field, exportRecords state array, exports getter, and export() async method that creates export records, emits "exportschange" events, and returns export identifiers.
Store export action and tests
src/stores/accounts/accounts-actions.ts, src/stores/accounts/accounts-actions.test.ts
exportCommunity store action validates inputs, resolves target community addresses (from input or active account's PKC list), deduplicates, creates community instances, invokes their export() methods, and aggregates results; tests cover single/multiple/list exports, account selection by name, input validation, and error handling.
useExportCommunity React hook and tests
src/hooks/actions/actions.ts, src/hooks/actions/actions.test.ts
useExportCommunity hook wraps the store action with React state management for initializing/ready/exporting/succeeded/failed transitions, exposes communityExports array and exportCommunity() function, and handles error callbacks; tests verify state transitions, export result shape, and error propagation.
Public API export
src/index.ts
Re-exports useExportCommunity via named export and adds it to the hooks default export object.
API documentation and recipes
README.md, llms-full.txt
API reference lists useExportCommunity hook signature; new "(Desktop only) Export communities" recipe demonstrates exporting single communities, multiple concurrent exports, and all account-linked communities with state/error handling.
Dependency version update
package.json
Bumps @pkcprotocol/pkc-js from 0.0.38 to 0.0.41.

Sequence Diagram

sequenceDiagram
  participant Component
  participant useExportCommunity
  participant accountsActions
  participant Community
  
  Component->>useExportCommunity: exportCommunity(addresses)
  activate useExportCommunity
  useExportCommunity->>useExportCommunity: setState("exporting")
  
  useExportCommunity->>accountsActions: exportCommunity(addresses)
  activate accountsActions
  accountsActions->>accountsActions: validate & deduplicate addresses
  
  loop for each address
    accountsActions->>Community: createPkcCommunity(address)
    accountsActions->>Community: export(options)
    activate Community
    Community->>Community: append exportRecord
    Community->>Community: emit "exportschange"
    Community-->>accountsActions: { exportId }
    deactivate Community
  end
  
  accountsActions-->>useExportCommunity: CommunityExport[]
  deactivate accountsActions
  
  useExportCommunity->>useExportCommunity: setState("succeeded")
  useExportCommunity->>useExportCommunity: setCommunityExports(results)
  useExportCommunity-->>Component: { communityExports, state: "succeeded" }
  deactivate useExportCommunity
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through exports bright,
Communities bundled left and right,
From types to hooks, the pieces align,
With tests and docs, the features shine—
One community, or all at once,
Export them swift, no more bungled stunts!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(actions): add community export hook' directly and concisely describes the main change: adding a new hook for exporting communities.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/export-community

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/types.ts (1)

594-606: ⚡ Quick win

Tighten the shared export contracts to avoid type erosion.

At Line 594 and Line 606, [key: string]: any weakens the new cross-layer contract and can hide payload drift between hook/store/mock. Prefer explicit fields plus unknown for extensibility.

♻️ Proposed contract tightening
-export type ExportCommunityOptions = { [key: string]: any };
+export interface ExportCommunityOptions {
+  includePrivateKey?: boolean;
+  exportPath?: string;
+  signal?: AbortSignal;
+  [key: string]: unknown;
+}

-export type CommunityExport = { communityAddress: string; exportId: string; [key: string]: any };
+export type CommunityExport = {
+  communityAddress: string;
+  exportId: string;
+  name?: string;
+  publicKey?: string;
+  includePrivateKey?: boolean;
+  progress?: number;
+  url?: string;
+  [key: string]: unknown;
+};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/types.ts` around lines 594 - 606, Replace the overly permissive {[key:
string]: any} index signatures across the exported types
(ExportCommunityOptions, Challenge, ChallengeVerification, CreateCommentOptions,
CreateCommunityOptions, CreateVoteOptions, Comment, Vote, CommentEdit,
CommentModeration, CommunityEdit, Community, CommunityExport) with tightened
contracts: declare explicit known fields for each type and use unknown (or
Record<string, unknown>) for any additional extensibility, e.g., change trailing
any-indexes to Record<string, unknown> or an explicit optional extras field to
prevent silent payload drift while preserving forward-compatibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 174: Update the README's useExportCommunity signature to match the actual
public contract: replace the generic return shown as {communityExports:
{communityAddress: string, exportId: string}[], exportCommunity: Function} with
the full UseExportCommunityResult shape used in src/types.ts, and document
exportCommunity as an async function (exportCommunity(): Promise<void>) that
also exposes Result fields; ensure you reference the UseExportCommunityResult
type and the useExportCommunity hook name so the docs match the hook
implementation and exported types.

In `@src/stores/accounts/accounts-actions.ts`:
- Around line 815-819: The log call in accountsActions.exportCommunity currently
prints full payloads (communityAddresses, exportCommunityOptions,
communityExports) which can contain private keys; change the export logging to
avoid raw objects by either omitting/redacting sensitive fields (e.g., do not
log privateKey or when exportCommunityOptions.includePrivateKey is true) or
replace the payloads with a sanitized summary (counts, flags) before calling
log("accountsActions.exportCommunity", ...); specifically update the code around
the log invocation to inspect exportCommunityOptions and communityExports and
only include non-sensitive metadata or masked values rather than the full
objects.

---

Nitpick comments:
In `@src/types.ts`:
- Around line 594-606: Replace the overly permissive {[key: string]: any} index
signatures across the exported types (ExportCommunityOptions, Challenge,
ChallengeVerification, CreateCommentOptions, CreateCommunityOptions,
CreateVoteOptions, Comment, Vote, CommentEdit, CommentModeration, CommunityEdit,
Community, CommunityExport) with tightened contracts: declare explicit known
fields for each type and use unknown (or Record<string, unknown>) for any
additional extensibility, e.g., change trailing any-indexes to Record<string,
unknown> or an explicit optional extras field to prevent silent payload drift
while preserving forward-compatibility.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: f4d7fecc-566e-43d6-9430-421721a67cb6

📥 Commits

Reviewing files that changed from the base of the PR and between cc61e65 and c9b4d92.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (10)
  • README.md
  • llms-full.txt
  • package.json
  • src/hooks/actions/actions.test.ts
  • src/hooks/actions/actions.ts
  • src/index.ts
  • src/lib/pkc-js/pkc-js-mock.ts
  • src/stores/accounts/accounts-actions.test.ts
  • src/stores/accounts/accounts-actions.ts
  • src/types.ts

Comment thread README.md Outdated
Comment thread src/stores/accounts/accounts-actions.ts
Comment thread src/stores/accounts/accounts-actions.ts Outdated
Comment thread src/hooks/actions/actions.ts Outdated
Comment thread src/hooks/actions/actions.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 2 potential issues.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 14b96b0. Configure here.

setExportingState("failed");
setErrors((errors) => [...errors, e]);
onError?.(e);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale export overwrites newer run

High Severity

exportCommunity applies setCommunityExports, setExportingState, and error updates when the awaited store call finishes, without checking that the export still matches the active exportingContext. A slower earlier export can finish after a later one starts and show the wrong communities as succeeded or failed.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 14b96b0. Configure here.

setExportingState("failed");
setErrors((errors) => [...errors, e]);
onError?.(e);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Success keeps prior export error

Medium Severity

Calling exportCommunity again after a failure does not reset errors, yet error still exposes errors[errors.length - 1] whenever hasCurrentExportState is true. A later successful run can leave state as succeeded while error still reflects the earlier failure.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 14b96b0. Configure here.

@tomcasaburi

Copy link
Copy Markdown
Member Author

Review feedback handled in the latest commits:

  • Fixed the README signature so useExportCommunity documents the async exportCommunity() result shape.
  • Sanitized export logging so raw export options/results are not logged.
  • Tightened the new export-related public types while leaving the broader legacy placeholder type cleanup out of scope for this PR.
  • Fixed the export result merge order so the requested communityAddress cannot be overwritten by export metadata.
  • Fixed stale useExportCommunity state so completed export results/errors are hidden when account or export targets change, including switching away and back.

Verification:

  • yarn prettier
  • yarn build
  • yarn test
  • yarn test:coverage
  • Hosted CI checks/e2e passed after the final push.

Local node scripts/verify-hooks-stores-coverage.mjs still reports the existing repo-wide 100% hooks/stores baseline gaps; this PR did not resolve that baseline, but the final coverage run passed and the changed action hook branch coverage is back to the existing single uncovered branch.

@tomcasaburi tomcasaburi merged commit f6a9616 into master Jun 7, 2026
8 checks passed
@tomcasaburi tomcasaburi deleted the feature/export-community branch June 7, 2026 07:57
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