Skip to content

chore: remove legacy CJS files, fix env defaults, and improve type annotations#63

Merged
thephez merged 5 commits intomainfrom
chore/minor-updates
Mar 18, 2026
Merged

chore: remove legacy CJS files, fix env defaults, and improve type annotations#63
thephez merged 5 commits intomainfrom
chore/minor-updates

Conversation

@thephez
Copy link
Collaborator

@thephez thephez commented Mar 17, 2026

Summary

  • Removed legacy CommonJS (.js) tutorial files that used the old require() API (identity-retrieve-account-ids.js, identity-update-add-key.js, identity-update-disable-key.js). All tutorials now use ESM (.mjs) exclusively.
  • Replaced ?? with || for process.env defaults across all tutorial scripts. The nullish coalescing operator (??) does not handle empty strings (""), which process.env returns for unset-but-defined variables. Using || correctly falls back to the default in those cases.
  • Improved JSDoc type annotations in setupDashClient.mjs — added @typedef, @param, and @returns annotations to IdentityKeyManager, AddressKeyManager, createClient(), setupDashClient(), and related helpers. Added a null-check after identities.fetch() with a corresponding test.
  • Fixed tsconfig.json to use module: "node16" / moduleResolution: "node16" so that .mjs files are type-checked correctly. Narrowed include to setupDashClient.mjs and set maxNodeModuleJsDepth: 0 to avoid checking node_modules.
  • Updated package.json: fixed main entry (connect.jsconnect.mjs), upgraded formatter to prettier@3.8.1, added @types/mocha and @types/node dev dependencies.
  • Formatting pass on README.md and test file to fix line lengths and brace style.

Summary by CodeRabbit

  • Chores

    • Updated package metadata and dev tooling; adjusted TypeScript project settings.
  • Refactor

    • Standardized environment-variable defaulting across example scripts so empty/falsy values now fall back to defaults.
  • Removed

    • Deleted several example scripts related to identity and key management and account retrieval.
  • Tests

    • Added a test covering missing on-chain identity handling; formatting tweaks for readability.
  • Documentation

    • Expanded JSDoc/type annotations and minor README formatting adjustments.

thephez added 4 commits March 17, 2026 16:08
?? only falls back on null/undefined, so an empty env var (e.g.
DATA_CONTRACT_ID='') would be used as-is instead of the intended default.
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

The PR deletes three JavaScript identity example scripts, replaces multiple occurrences of the nullish coalescing operator (??) with logical OR (||) for environment defaults across many .mjs examples, updates package.json (main, formatter, devDependencies), adds JSDoc typing and typedefs to setupDashClient.mjs, adjusts tsconfig includes and module settings, and refactors tests and README formatting.

Changes

Cohort / File(s) Summary
Removed Identity Example Scripts
1-Identities-and-Names/identity-retrieve-account-ids.js, 1-Identities-and-Names/identity-update-add-key.js, 1-Identities-and-Names/identity-update-disable-key.js
Deleted three example scripts that managed identity retrieval, key addition, and key disabling; removes associated runtime examples and logic.
Operator Replacement — Identities
1-Identities-and-Names/identity-transfer-credits.mjs, 1-Identities-and-Names/identity-update-disable-key.mjs, 1-Identities-and-Names/identity-withdraw-credits.mjs, 1-Identities-and-Names/name-register.mjs
Replaced ?? with `
Operator Replacement — Contracts & Documents
2-Contracts-and-Documents/...
2-Contracts-and-Documents/contract-retrieve-history.mjs, 2-Contracts-and-Documents/contract-retrieve.mjs, 2-Contracts-and-Documents/contract-update-history.mjs, 2-Contracts-and-Documents/contract-update-minimal.mjs, 2-Contracts-and-Documents/document-delete.mjs, 2-Contracts-and-Documents/document-retrieve.mjs, 2-Contracts-and-Documents/document-submit.mjs, 2-Contracts-and-Documents/document-update.mjs
Systematically swapped ?? for `
Client Setup Typing & JSDoc Additions
setupDashClient.mjs
Added extensive JSDoc typedefs, annotated return types and function parameters, documented IdentityKeyManager and AddressKeyManager methods and shapes; purely additive typing/docs with minor type casts, no runtime control-flow changes.
Tests
test/setupDashClient.test.mjs
Added a test covering IdentityKeyManager throwing when identity is missing on-chain; reformatted assertions and multiline objects for readability.
Project Config & Tooling
package.json, tsconfig.json
package.json: changed main to connect.mjs, updated scripts.fmt to use Prettier v3.8.1 and limit glob to {js,mjs}, added devDependencies @types/mocha and @types/node. tsconfig.json: switched module/moduleResolution to node16, set maxNodeModuleJsDepth to 0, and narrowed include to ["./setupDashClient.mjs"].
Docs / Misc
README.md
Minor reflow/line-wrapping edits; no content or behavior changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with tiny paws,
Swapped ?? for || — a little cause,
Three scripts I nudged off to rest,
Typed the client to make it dressed,
Tests stretched lines and Prettier glossed our claws.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title accurately captures the three main objectives of the changeset: removing legacy CommonJS files, changing environment variable defaults from nullish coalescing to logical OR, and adding type annotations.

✏️ 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 chore/minor-updates
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@thephez thephez marked this pull request as ready for review March 18, 2026 14:45
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

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

Inline comments:
In `@1-Identities-and-Names/identity-update-disable-key.mjs`:
- Line 8: The constant DISABLE_KEY_ID currently uses || which treats "0" as
falsy; change it to use the nullish coalescing operator (??) so a user-provided
"0" is preserved. Update the DISABLE_KEY_ID initialization to coalesce only when
process.env.DISABLE_KEY_ID is null/undefined (e.g., use
process.env.DISABLE_KEY_ID ?? fallback) and then convert to Number, ensuring
DISABLE_KEY_ID preserves 0 instead of defaulting to 99.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ef9a3d01-dce6-4584-b949-2623d019b776

📥 Commits

Reviewing files that changed from the base of the PR and between 5b85735 and b3cc55e.

📒 Files selected for processing (18)
  • 1-Identities-and-Names/identity-retrieve-account-ids.js
  • 1-Identities-and-Names/identity-transfer-credits.mjs
  • 1-Identities-and-Names/identity-update-add-key.js
  • 1-Identities-and-Names/identity-update-disable-key.js
  • 1-Identities-and-Names/identity-update-disable-key.mjs
  • 1-Identities-and-Names/identity-withdraw-credits.mjs
  • 1-Identities-and-Names/name-register.mjs
  • 2-Contracts-and-Documents/contract-retrieve-history.mjs
  • 2-Contracts-and-Documents/contract-retrieve.mjs
  • 2-Contracts-and-Documents/contract-update-history.mjs
  • 2-Contracts-and-Documents/contract-update-minimal.mjs
  • 2-Contracts-and-Documents/document-delete.mjs
  • 2-Contracts-and-Documents/document-retrieve.mjs
  • 2-Contracts-and-Documents/document-submit.mjs
  • 2-Contracts-and-Documents/document-update.mjs
  • README.md
  • package.json
  • test/setupDashClient.test.mjs
💤 Files with no reviewable changes (3)
  • 1-Identities-and-Names/identity-update-disable-key.js
  • 1-Identities-and-Names/identity-update-add-key.js
  • 1-Identities-and-Names/identity-retrieve-account-ids.js

#64)

* chore: fix tsconfig to check setupDashClient with correct ESM settings

Update tsconfig.json to use module/moduleResolution node16 for proper
.mjs ESM support, scope include to setupDashClient.mjs only, and set
maxNodeModuleJsDepth to 0. Add @types/node and @types/mocha devDeps.
Add JSDoc type annotations to setupDashClient.mjs to pass strict tsc check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: replace any types with precise SDK types in setupDashClient

Add JSDoc typedef imports for Identity, IdentityPublicKey, PlatformAddress,
PlatformAddressInfo, and NetworkLike. Define DerivedKeyEntry and AddressEntry
typedefs. Replace all any params/returns with real SDK types. Add missing
@returns to create(), convenience signer methods, and exported functions.
Add identity-not-found guard in getSigner() with corresponding test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@thephez thephez changed the title chore: cleanup chore: remove legacy CJS files, fix env defaults, and improve type annotations Mar 18, 2026
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
setupDashClient.mjs (1)

380-404: ⚠️ Potential issue | 🟡 Minor

Fail fast when the expected identity public key is absent.

At Line 401, identity.getPublicKeyById(key.keyId) can return undefined, but execution continues and returns a signer anyway. This pushes errors downstream with poorer diagnostics.

💡 Suggested fix
     const identityKey = identity.getPublicKeyById(key.keyId);
+    if (!identityKey) {
+      throw new Error(
+        `Identity "${this.id}" does not contain keyId=${key.keyId} (${keyName}).`,
+      );
+    }
     const signer = new IdentitySigner();
     signer.addKeyFromWif(key.privateKeyWif);
     return { identity, identityKey, signer };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@setupDashClient.mjs` around lines 380 - 404, In getSigner, check the result
of identity.getPublicKeyById(key.keyId) and throw a clear error if it is
undefined so we fail fast; locate getSigner, the identity variable from
this.sdk.identities.fetch(this.id), and the key entry (keyName/key.keyId) and
replace the current logic that returns a signer when identityKey is missing with
a throw including identity id, keyName and keyId to provide actionable
diagnostics before creating the IdentitySigner.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tsconfig.json`:
- Line 74: The tsconfig's "include" was narrowed to only "setupDashClient.mjs",
which limits type-checking and checkJs/strict coverage to that single file;
restore a broader include pattern (e.g., revert to the previous globs or add
back the tutorial/source directories and file extensions such as "src/**/*.ts",
"tutorials/**/*.js", "*.ts", "*.js", or the original patterns) so TypeScript's
checkJs/strict rules run across the full codebase; update the "include" array
(the "include" property and the "setupDashClient.mjs" entry) to cover all
tutorial and source files instead of a single file.

---

Outside diff comments:
In `@setupDashClient.mjs`:
- Around line 380-404: In getSigner, check the result of
identity.getPublicKeyById(key.keyId) and throw a clear error if it is undefined
so we fail fast; locate getSigner, the identity variable from
this.sdk.identities.fetch(this.id), and the key entry (keyName/key.keyId) and
replace the current logic that returns a signer when identityKey is missing with
a throw including identity id, keyName and keyId to provide actionable
diagnostics before creating the IdentitySigner.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1550b207-a06e-4994-9516-025caca70191

📥 Commits

Reviewing files that changed from the base of the PR and between b3cc55e and 3b539e3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json
  • setupDashClient.mjs
  • test/setupDashClient.test.mjs
  • tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/setupDashClient.test.mjs
  • package.json

@thephez thephez merged commit b1b32dc into main Mar 18, 2026
3 checks passed
@thephez thephez deleted the chore/minor-updates branch March 18, 2026 17:03
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