@rxbenefits/constants
v1.0.0
Published
Application-wide constants, configuration, and validation rules for RxBenefits applications
Downloads
4
Maintainers
Readme
@rxbenefits/constants
Application-wide constants, configuration, validation rules, and static data for RxBenefits applications.
Installation
npm install @rxbenefits/constants @rxbenefits/types
# or
yarn add @rxbenefits/constants @rxbenefits/typesNote: This package requires
@rxbenefits/typesas a peer dependency.
Features
- 📝 Validation Rules - Form validation rules and regex patterns
- 🔐 Permissions - Application permission constants
- 🗺️ Data Mappings - States, gender, relationship mappings
- ⚙️ Configuration - Runtime configuration management
- 🛣️ Routes - Application routing constants
- ✅ Form Validators - Custom form validation functions
Usage
Configuration
Access runtime configuration values:
import { config } from '@rxbenefits/constants';
// API endpoints
console.log(config.apiUri);
console.log(config.billingApiUri);
// Auth0 configuration
console.log(config.auth0.domain);
console.log(config.auth0.clientId);
// DataDog RUM configuration
console.log(config.datadog.applicationId);
console.log(config.datadog.clientToken);Validation Rules
Use pre-defined validation rules for forms:
import { validationRules } from '@rxbenefits/constants';
// Use in Ant Design forms
<Form.Item name="email" rules={validationRules.email}>
<Input placeholder="Email address" />
</Form.Item>
<Form.Item name="firstName" rules={validationRules.firstName}>
<Input placeholder="First name" />
</Form.Item>
<Form.Item name="zip" rules={validationRules.zip}>
<Input placeholder="ZIP code" />
</Form.Item>Form Validators
Use custom validator functions:
import { Int32Validator } from '@rxbenefits/constants';
// Use in Ant Design form rules
const rules = [
{
message: 'Person Code must be less than 2147483647',
validator: Int32Validator,
},
];
<Form.Item name="personCode" rules={rules}>
<Input placeholder="Person Code" />
</Form.Item>Regex Patterns
Validate data with regex patterns:
import {
SINGLE_EMAIL_PATTERN,
SSN_PATTERN,
ZIP_PATTERN,
NUMBERS_ONLY,
ALPHA_ONLY,
} from '@rxbenefits/constants';
// Validate email
if (SINGLE_EMAIL_PATTERN.test(email)) {
console.log('Valid email');
}
// Validate SSN (9 digits, no dashes)
if (SSN_PATTERN.test(ssn)) {
console.log('Valid SSN');
}
// Validate ZIP code (5 digits or 5+4 format)
if (ZIP_PATTERN.test(zip)) {
console.log('Valid ZIP');
}Data Mappings
Use standardized data mappings:
import { stateCodeMapping, genderMapping, relationshipMapping } from '@rxbenefits/constants';
// Use in select dropdowns
<Select options={stateCodeMapping} placeholder="Select state" />
<Select options={genderMapping} placeholder="Select gender" />
<Select options={relationshipMapping} placeholder="Select relationship" />Permissions
Check user permissions:
import {
MEMBER_PERMISSIONS,
INVOICE_PERMISSIONS,
FILE_PERMISSIONS,
DEV_PERMISSIONS,
} from '@rxbenefits/constants';
// Check if user has permission
if (userPermissions.includes(MEMBER_PERMISSIONS.EDIT)) {
// Show edit button
}
if (userPermissions.includes(INVOICE_PERMISSIONS.DOWNLOAD_FINANCIAL)) {
// Allow invoice download
}Application Modules
Define application modules:
import { APP_MODULES, KEYSTONE_APP_MODULES } from '@rxbenefits/constants';
console.log(APP_MODULES); // ['Portal', 'Authorization', 'Keystone', 'Evaluate', 'Agent']
console.log(KEYSTONE_APP_MODULES); // ['Keystone']Numeric Constants
Use standard numeric constants:
import { INT32MAX } from '@rxbenefits/constants';
// Maximum value for 32-bit signed integer
console.log(INT32MAX); // 2147483647
// Use in validation
if (value <= INT32MAX) {
console.log('Valid INT32');
}Available Constants
Configuration
config- Runtime configuration object
Validation
validationRules- Form validation rulesInt32Validator- 32-bit integer validator function
Regex Patterns
ALPHA_ONLY- Alphabetic characters onlyALPHANUMERIC_ONLY- Alphanumeric characters onlyNUMBERS_ONLY- Numeric characters onlyNAME_PATTERN- Valid name pattern (allows -, ., ')FULL_NAME_PATTERN- Full name with spacesSINGLE_EMAIL_PATTERN- Email validationSSN_PATTERN- SSN (9 digits, no dashes)ZIP_PATTERN- ZIP code (5 or 5+4 format)MASKED_PHONE_NUMBER_PATTERN- Phone number validationSINGLE_DECIMAL_POINT_PATTERN- Decimal number validation
Data Mappings
stateCodeMapping- US states and territories (56 entries)genderMapping- Gender options (M, F, U)relationshipMapping- Family relationships (7 types)
Permissions
MEMBER_PERMISSIONS- Member-related permissionsINVOICE_PERMISSIONS- Invoice-related permissionsFILE_PERMISSIONS- File management permissionsDEV_PERMISSIONS- Developer permissionsUSER_PERMISSIONS- User management permissions
Routes
PageRoutes- Application page routesReactRouterRoutes- React Router paths
Numeric Constants
INT32MAX- Maximum 32-bit signed integer (2147483647)
UI Resources
TOOLTIPS- UI tooltip contentpbmLogoPaths- PBM logo file pathspbmURLs- PBM URLsstaticPdfs- Static PDF pathshelpContent- Help content paths
Other
APP_MODULES- Application module namesKEYSTONE_APP_MODULES- Keystone-specific modulesselectIdentifiers- Select box identifierstableQueryPrefixes- Table query prefixes
Breaking Changes from Monorepo
Int32Validator Location Change
In the monorepo, Int32Validator was located in @optimize/utils. It has been moved to @rxbenefits/constants to break a circular dependency.
Before (monorepo):
import { Int32Validator } from '@optimize/utils';After (npm package):
import { Int32Validator } from '@rxbenefits/constants';Rationale: The validator depends on INT32MAX constant and causes a circular dependency when in utils. Moving it to constants co-locates it with the constant it depends on.
Development
Setup
git clone https://github.com/RxBenefits/rxbenefits-constants.git
cd rxbenefits-constants
npm installScripts
npm run build # Build the package
npm run build:dev # Build with source maps
npm run build:watch # Watch mode for development
npm run clean # Remove build artifacts
npm run typecheck # Type check without building
npm run test # Run test suite
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage
npm run lint # Lint code
npm run lint:fix # Lint and auto-fix
npm run format # Format code with Prettier
npm run format:check # Check formatting
npm run validate # Run all checks (typecheck, lint, test)Testing
This package has comprehensive test coverage including:
- Form validator tests (Int32Validator)
- Regex pattern validation tests
- Data mapping validation tests
- Permission constants tests
- Configuration tests
Run tests with:
npm testContributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes
- Run validation:
npm run validate - Commit using conventional commits:
git commit -m "feat: add new constant" - Push and create a pull request
Commit Message Format
We use Conventional Commits:
<type>(<scope>): <subject>
<body>
<footer>Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore
License
MIT © RxBenefits
Support
- Issues
- Documentation
- Internal Slack: #optimize-ui
Related Packages
- @rxbenefits/types - TypeScript type definitions
- @rxbenefits/utils - Utility functions
- @rxbenefits/ui - UI component library
