@encodeagent/platform-helper-metadata
v1.2510.1131245
Published
Comprehensive TypeScript metadata library for the EncodeAgent platform with metadata utilities, query builders, migrations, and more
Maintainers
Readme
@encodeagent/platform-helper-util
Comprehensive TypeScript utility library for the EncodeAgent platform with AI services, authentication, file handling, web content processing, and more.
Installation
npm install @encodeagent/platform-helper-utilRequirements
- Node.js >20.0.0 <23.0.0
- TypeScript 5.2+
Usage
Core Utilities
import {
isNonEmptyString,
isGuid,
isEmail,
formatString,
getTimestamp,
numberWithCommas,
readableFileSize
} from '@encodeagent/platform-helper-util';
isNonEmptyString('hello'); // true
isGuid('550e8400-e29b-41d4-a716-446655440000'); // true
isEmail('[email protected]'); // true
formatString('Hello {0}!', 'World'); // 'Hello World!'
numberWithCommas(1234567); // '1,234,567'
readableFileSize(1024); // '1.00 KB'Authentication & Authorization
import {
checkRecordPrivilege,
hasRole,
isOwner,
checkPrivileges
} from '@encodeagent/platform-helper-util';
const hasAccess = checkRecordPrivilege(record, context, 'read');
const userHasRole = hasRole(user, 'admin');
const isRecordOwner = isOwner(record, userId);AI Services & LLM Integration
import {
getAIService,
getLLMRequest,
getAIContext,
calculateCost
} from '@encodeagent/platform-helper-util';
const aiService = getAIService('gpt-4');
const llmRequest = getLLMRequest(prompt, parameters);
const context = getAIContext(userId, organizationId);
const cost = calculateCost({ service: aiService, inputQuantity: 1000 });File & Content Processing
import {
getFileType,
getContentType,
processWebPage,
markdownToHtml,
htmlToMarkdown,
cleanHtml
} from '@encodeagent/platform-helper-util';
const fileType = getFileType('document.pdf');
const contentType = getContentType('.json');
const webContent = await processWebPage(url, settings);
const html = markdownToHtml('# Hello World');
const markdown = htmlToMarkdown('<h1>Hello World</h1>');Color Utilities
import {
getColor,
hexToRgb,
isValidHex,
BLUE,
RED
} from '@encodeagent/platform-helper-util';
const color = getColor('primary');
const rgb = hexToRgb('#FF0000'); // { r: 255, g: 0, b: 0 }
const isValid = isValidHex('#FF0000'); // trueWeb & URL Utilities
import {
isValidUrl,
getBaseDomain,
fixUrl,
getWebQueryValue
} from '@encodeagent/platform-helper-util';
const isValid = isValidUrl('https://example.com');
const domain = getBaseDomain('https://sub.example.com/path');
const fixedUrl = fixUrl('example.com'); // 'https://example.com'Record & Data Management
import {
getRecordDisplay,
convertRecordForCreate,
getContextFromRecord,
applyRecordSlug
} from '@encodeagent/platform-helper-util';
const display = getRecordDisplay(record, entity);
const createRecord = convertRecordForCreate(record);
const context = getContextFromRecord(record);Tree Operations
import {
getTreeItem,
insertTreeItem,
removeTreeItem,
updateTreeItem
} from '@encodeagent/platform-helper-util';
const item = getTreeItem(tree, itemId);
const newTree = insertTreeItem(tree, parentId, newItem);
const updatedTree = removeTreeItem(tree, itemId);Caching
import {
getCache,
setCache,
removeCache
} from '@encodeagent/platform-helper-util';
const cached = getCache('myKey');
setCache('myKey', data, 60); // Cache for 60 minutes
removeCache('myKey');ID Generation
import {
newGuid,
newShortId,
slug
} from '@encodeagent/platform-helper-util';
const guid = newGuid(); // '550e8400-e29b-41d4-a716-446655440000'
const shortId = newShortId(); // 'rJUWbIHOWM'
const urlSlug = slug('Hello World!'); // 'hello-world'Type Definitions
The library exports comprehensive TypeScript types:
import type {
IContext,
IError,
IService,
ICost,
TKeyOwner,
TToken,
TLLMMessage
} from '@encodeagent/platform-helper-util';Constants
Access platform constants and configurations:
import {
GUID_EMPTY,
DEFAULT_PASSWORD_RULE,
COUNTRIES,
LANGUAGES,
ERROR_HTTP_LIST
} from '@encodeagent/platform-helper-util';Development
Setup
npm installBuild
npm run build
npm run build:watchTest
npm test
npm run test:watchLint
npm run lint
npm run lint:fixClean
npm run cleanPublishing
Automated Publishing (Recommended)
sh publish.shThis script will:
- Clean previous builds
- Run tests
- Build the project
- Update version automatically
- Publish to npm
Manual Publishing
npm run prepublishOnly
npm publishScripts
build- Compile TypeScript to JavaScriptbuild:watch- Watch mode compilationclean- Remove dist directorytest- Run Jest teststest:watch- Run tests in watch modelint- Run ESLintlint:fix- Fix ESLint issuesprepublishOnly- Clean and build before publishing
License
UNLICENSED - PrimeObjects Software Inc. All rights reserved.
