This guide covers essential best practices for integrating Licentra into your NetSuite solutions, ensuring optimal performance, security, and maintainability.
Only check feature status when needed, not on every script execution.
Code
const beforeLoad = (context) => { // Only check features when specific conditions are met if (context.type === context.UserEventType.EDIT) { const status = licentraLib.isFeatureEnabled('EDIT_FEATURES'); if (status.enabled) { addEditFeatures(context.form); } }};
Security Considerations
Input Validation
Always validate feature IDs before passing them to the API.
Code
function validateFeatureId(featureId) { if (!featureId || typeof featureId !== 'string') { throw new Error('Invalid feature ID: must be a non-empty string'); } // Only allow alphanumeric characters and underscores if (!/^[A-Z0-9_]+$/.test(featureId)) { throw new Error('Invalid feature ID: must contain only uppercase letters, numbers, and underscores'); } return featureId;}function safeFeatureCheck(featureId) { try { const validatedId = validateFeatureId(featureId); return licentraLib.isFeatureEnabled(validatedId); } catch (error) { log.error('Feature ID Validation Error', error.message); return { enabled: false, message: 'Invalid feature ID' }; }}
Error Information Disclosure
Be careful not to expose sensitive information in error messages.
Code
function handleFeatureError(error, featureId) { // Log detailed error for debugging log.error('Feature Check Error', { featureId: featureId, error: error.message, stack: error.stack }); // Return generic message to user return { enabled: false, message: 'Feature temporarily unavailable' };}
Access Control
Implement proper access control for feature-dependent functionality.
Code
function checkUserPermissions(featureId, userId) { try { const status = licentraLib.isFeatureEnabled(featureId); if (!status.enabled) { return false; } // Additional user-specific checks if needed const user = runtime.getCurrentUser(); if (user.role !== 'ADMIN' && featureId.includes('ADMIN_')) { return false; } return true; } catch (error) { log.error('Permission Check Error', error.message); return false; }}
Development Guidelines
Consistent Error Handling
Implement consistent error handling across all feature checks.
By following these best practices, you'll create robust, maintainable, and performant Licentra integrations that provide excellent user experience while ensuring security and reliability.