Development and Packaging
Getting Started
The Infinity Elements SDK provides a complete local development environment with CLI tools and testing capabilities:
Install SDK Globally
Install the Infinity Elements SDK CLI globally:
# Install the SDK globally
npm install -g @avaya/infinity-elements-sdk
Create a New Element Project
The CLI scaffolds a complete Element project with the Element API already included:
# Create a new project
infinity init my-element
cd my-widget
# Start development server
infinity dev
# Build for production
infinity build
-
Create a new Infinity Element Project
infinity init my-widget
cd my-widget -
Start a Development Server
Launches a local development server with:- Hot module replacement for instant feedback
- Live reload on file changes
- Debug mode enabled by default
infinity dev
-
Build for Production
Generates production-ready output in thedist/directory:- ES module format (
.es.js) - For modern browsers - UMD format (
.umd.js) - For compatibility with older environments - Optimized and minified bundle with CSS inlined
infinity build
- ES module format (
The scaffolded project automatically includes @avaya/infinity-elements-api as a dependency, so you can immediately start using the Element API.
Import the Element API
In your Element component:
import { ElementAPI, DialpadDigit } from '@avaya/infinity-elements-api';
Initialize the API
Create an instance of the Element API in your component:
const api = new ElementAPI({
elementId: 'my-element', // Unique identifier for your element
timeout: 5000, // Request timeout in milliseconds
debug: true // Enable console logging for development
});
Note: Element names must follow W3C Custom Elements specification (lowercase, contain a hyphen, start with a letter). Valid:
my-element,user-profile. Invalid:myelement,MyElement.
Basic Usage Example
// Get current agent information
const userInfo = await api.getUserInfo();
console.log('Agent:', userInfo.displayName);
console.log('Status:', userInfo.agentStatus);
// Listen for interaction events
api.onInteractionAccepted((interactionId) => {
console.log('New interaction accepted:', interactionId);
// Load customer data, initialize UI, etc.
});
api.onInteractionEnded((interactionId) => {
console.log('Interaction ended:', interactionId);
// Clean up resources, save state, etc.
});
Error Handling
The Element API provides consistent error handling across all methods:
api.onError((error) => {
console.error('Error Code:', error.code);
console.error('Message:', error.message);
});
try {
const interaction = await api.getInteraction();
} catch (error) {
if (error.code === 'NO_ACTIVE_INTERACTION') {
console.log('Waiting for interaction...');
}
}
Common Error Codes
| Code | Description |
|---|---|
TIMEOUT | Request exceeded timeout limit |
VALIDATION_ERROR | Invalid parameters provided |
UNAUTHORIZED | Authentication failed |
NOT_FOUND | Resource not found |
PERMISSION_DENIED | Insufficient permissions' |
Development Workflow
- Initialize Your Project
As mentioned above. - Project structure
my-widget/
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
├── vite.config.ts # Build configuration
├── index.html # Development preview page
└── src/
├── Component.tsx # Your React component (main logic here)
├── Component.module.css # Scoped CSS styles
└── index.ts # Web component registration - Project Structure Permissions
InfinityElements operate with carefully scoped permissions:
<iframe
sandbox="allow-scripts allow-popups allow-forms allow-popups-to-escape-sandbox"
src="component.js">
</iframe>
Granted Permissions:
| Permissions | Purpose |
|---|---|
allow-scripts | Enable JavaScript execution |
allow-popups| | Required for OAuth authentication popups |
allow-forms | Allow form submissions |
allow-popups-to-escape-sandbox | Allow form submissions |
Resources
Updated 11 days ago
