@conduit-client/bindings-utils
v3.13.0
Published
Conduit utils for building bindings consistently
Downloads
1,006
Readme
@conduit-client/bindings-utils
Utility functions and types for building Conduit bindings consistently across different environments.
Overview
This package provides core utilities for error handling, command type definitions, and common patterns used in both LWC and imperative binding implementations. It serves as a foundational layer for building robust data bindings in the Conduit ecosystem.
Key Features
- Error Handling: Comprehensive error detection and handling utilities
- Command Types: Type definitions for different command result patterns
- Logging Utilities: Standardized error logging and transformation
API Reference
Error Handling Utilities
isInternalError(error: unknown): boolean
Determines if an error is an internal system error.
isUserVisibleError(error: unknown): boolean
Checks if an error should be shown to end users.
getErrorResponse(error: unknown)
Transforms errors into standardized response format.
logError(error: unknown, logger?: Logger)
Logs errors with appropriate context and formatting.
Command Types
ResultCommand<R>
Command that returns a direct result.
SubscribableResultCommand<R>
Command that returns a subscribable result for reactive updates.
MaybeSubscribableResultCommand<R>
Command that can return either a direct or subscribable result.
ResultOrSubscribableResult<R>
Union type for result flexibility.
Usage Examples
Error Handling
import { isInternalError, isUserVisibleError, logError } from '@conduit-client/bindings-utils/v1';
try {
// Your code here
} catch (error) {
if (isInternalError(error)) {
// Handle internal error
logError(error);
} else if (isUserVisibleError(error)) {
// Show error to user
showUserNotification(error);
}
}Command Type Usage
import type { ResultCommand, SubscribableResultCommand } from '@conduit-client/bindings-utils/v1';
// Direct result command
const fetchData: ResultCommand<UserData> = {
execute: () => Promise.resolve(userData),
};
// Subscribable command for reactive data
const subscribeToData: SubscribableResultCommand<UserData> = {
execute: () => ({
subscribe: (callback) => {
// Subscribe logic
return unsubscribe;
},
}),
};Dependencies
@conduit-client/utils: Core utility functions@conduit-client/command-base: Base command interfaces
