Skip to content

feat(sdk): re-export policy enums from barrel for convenient imports#928

Merged
marythought merged 1 commit intomainfrom
feat/enum-reexports
Apr 28, 2026
Merged

feat(sdk): re-export policy enums from barrel for convenient imports#928
marythought merged 1 commit intomainfrom
feat/enum-reexports

Conversation

@marythought
Copy link
Copy Markdown
Contributor

@marythought marythought commented Apr 28, 2026

Summary

Before / After

// Before — deep import into generated proto internals
import { SubjectMappingOperatorEnum } from '@opentdf/sdk/platform/policy/objects_pb.js';
import { ActiveStateEnum } from '@opentdf/sdk/platform/common/common_pb.js';

// After — clean top-level import
import { SubjectMappingOperatorEnum, ActiveStateEnum } from '@opentdf/sdk';

Usage is the same either way — the TS enum names are already short:

condition.operator = SubjectMappingOperatorEnum.IN;
group.booleanOperator = ConditionBooleanTypeEnum.AND;
attribute.rule = AttributeRuleTypeEnum.HIERARCHY;
request.state = ActiveStateEnum.ACTIVE;

Test plan

  • npx tsc --noEmit passes
  • npm run build succeeds
  • npx mocha 'dist/web/tests/mocha/unit/policy-enums.spec.js' — 4 tests, all pass
  • npm run format — no changes needed
  • CI passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Four new enums added to the public API: AttributeRuleTypeEnum, ConditionBooleanTypeEnum, SubjectMappingOperatorEnum, and ActiveStateEnum for policy and state management configuration.
  • Tests

    • Added unit tests validating the correctness of newly exposed enums.

Re-export SubjectMappingOperatorEnum, ConditionBooleanTypeEnum,
AttributeRuleTypeEnum, and ActiveStateEnum from the main @opentdf/sdk
entry point so users can import them directly instead of reaching into
generated proto paths.

Companion to opentdf/platform#3408 (Go SDK) and opentdf/java-sdk#357
(Java SDK).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
@marythought marythought requested a review from a team as a code owner April 28, 2026 17:21
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48b3e9cd-0de7-48c4-902c-e0e0297a575b

📥 Commits

Reviewing files that changed from the base of the PR and between 037e43e and 64963a9.

📒 Files selected for processing (2)
  • lib/src/index.ts
  • lib/tests/mocha/unit/policy-enums.spec.ts

📝 Walkthrough

Walkthrough

The module's public API is extended by re-exporting four enums: AttributeRuleTypeEnum, ConditionBooleanTypeEnum, SubjectMappingOperatorEnum, and ActiveStateEnum. A corresponding unit test file validates the re-exported enum values against expected mappings.

Changes

Cohort / File(s) Summary
API Exports
lib/src/index.ts
Added four enum re-exports for platform policy and common state management: AttributeRuleTypeEnum, ConditionBooleanTypeEnum, SubjectMappingOperatorEnum, and ActiveStateEnum.
Unit Tests
lib/tests/mocha/unit/policy-enums.spec.ts
New test suite validating the four re-exported enums match their expected numeric values using Chai assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • pflynn-virtru

Poem

🐰 Four enums hop into view,
Policy patterns shiny and new,
Tests verify each one's true,
The API now more bright,
Exports aligned just right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and concisely summarizes the main change: re-exporting policy enums from the barrel entry point for convenient imports.
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.

✨ 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 feat/enum-reexports

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

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request re-exports several policy-related enums, including AttributeRuleTypeEnum, ConditionBooleanTypeEnum, SubjectMappingOperatorEnum, and ActiveStateEnum, from the platform protobuf definitions in the main index file. It also adds a unit test suite to verify that these enums are correctly exported with their expected numeric values. I have no feedback to provide.

@github-actions
Copy link
Copy Markdown

@eugenioenko
Copy link
Copy Markdown
Contributor

Nice! Originally we didn't export much from the generated protos stubs because we really didn't know what consumers might need.
Now that we have real examples of usage, this is a great improvement

@marythought marythought merged commit d43919c into main Apr 28, 2026
23 checks passed
@marythought marythought deleted the feat/enum-reexports branch April 28, 2026 20:36
marythought added a commit to opentdf/docs that referenced this pull request Apr 30, 2026
## Summary

- Update Go SDK code samples to use the new shorthand enum constants
(`policy.OperatorIn`, `policy.BooleanAnd`, `policy.RuleAnyOf`) instead
of verbose proto enum names
- Update JS SDK imports to use barrel exports from `@opentdf/sdk`
instead of deep proto paths
(`@opentdf/sdk/platform/policy/objects_pb.js`)
- Update JS SDK examples to use enum values
(`ConditionBooleanTypeEnum.AND`) instead of string literals
(`'CONDITION_BOOLEAN_TYPE_ENUM_AND'`)
- Update Java SDK inline examples in policy.mdx to use `PolicyEnums`
shorthand constants
- Add `SdkVersion` badges with `NEXT` placeholders — replace with actual
versions once SDK releases ship

### Companion PRs

| SDK | PR | Status |
|---|---|---|
| Go | opentdf/platform#3408 | Open |
| Java | opentdf/java-sdk#357 | Open |
| JavaScript | opentdf/web-sdk#928 | Open |

### Note on Java code samples

The `code_samples/java/` files are pulled from the java-sdk repo at
build time via `docusaurus-plugin-remote-content`. They will update
automatically once `javaSdkVersion` is bumped in `docusaurus.config.ts`
after the java-sdk release containing opentdf/java-sdk#357.

## Test plan

- [x] `npm run build` passes
- [ ] Surge preview renders correctly
- [ ] Replace `NEXT` version placeholders after SDK releases

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Documentation**
* Updated policy and quickstart code examples for Go, Java, and
JavaScript to use simplified SDK enum constants for clearer, more
idiomatic samples.
* Switched JavaScript examples to use package entry-point imports
instead of generated-module paths.
* Added SDK version markers to code samples to show explicit
language/version context and improve consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants