@omeron/ota-bre-react-sdk (1.0.0)
Published 2026-04-16 17:05:52 +00:00 by omeron-admin
Installation
@omeron:registry=npm install @omeron/ota-bre-react-sdk@1.0.0"@omeron/ota-bre-react-sdk": "1.0.0"About this package
@omeron/ota-bre-react-sdk
React SDK for OTA Business Rules Engine API with React Hooks
Installation
npm install @omeron/ota-bre-react-sdk
Setup
1. Initialize the API Client
import { initializeClient } from '@omeron/ota-bre-react-sdk';
// Initialize once in your app (e.g., index.tsx or App.tsx)
initializeClient({
apiUrl: 'http://localhost:8081/api',
defaultDomainId: 'your-domain-id', // Optional
apiKey: 'your-product-api-key' // Required for booking ingestion
});
2. Use Hooks in Components
import React from 'react';
import { useAuth, useDomains, useGfsRules } from '@omeron/ota-bre-react-sdk';
function App() {
const { user, login, logout } = useAuth();
const { domains, loading } = useDomains();
return (
<div>
{user ? (
<div>
<h1>Welcome, {user.firstName}</h1>
<button onClick={logout}>Logout</button>
</div>
) : (
<LoginForm onLogin={login} />
)}
</div>
);
}
Available Hooks
useAuth()
Manage authentication state and operations.
const { user, loading, error, login, logout, fetchCurrentUser } = useAuth();
// Login
await login('user@example.com', 'password');
// Logout
await logout();
// Fetch current user
await fetchCurrentUser();
useDomains(params?)
Fetch and manage domains with pagination.
const { domains, loading, error, refetch } = useDomains({
page: 0,
size: 20,
sort: 'name,asc'
});
// Access domains
console.log(domains?.content);
// Refresh
await refetch();
useDomain(id)
Fetch a single domain by ID.
const { domain, loading, error, refetch } = useDomain('domain-id');
useDomainSettings(id)
Fetch and update domain settings.
const { settings, loading, error, refetch, updateSettings } = useDomainSettings('domain-id');
// Update settings
await updateSettings({
gfsFtpSettings: {
host: 'sftp.example.com',
port: 22,
username: 'user',
password: 'password',
remotePath: '/data'
}
});
useSftpTest()
Test SFTP connection.
const { result, testing, error, testConnection } = useSftpTest();
// Test connection
await testConnection('domain-id', {
gfsFtpSettings: {
host: 'sftp.example.com',
port: 22,
username: 'user',
password: 'password',
remotePath: '/data'
}
});
// Check result
if (result?.success) {
console.log('Files:', result.files);
}
useGfsRules(params?)
Fetch and manage GFS rules.
const { rules, loading, error, refetch, toggleRule } = useGfsRules({
page: 0,
size: 20
});
// Toggle rule
await toggleRule('rule-id', true); // Enable
await toggleRule('rule-id', false); // Disable
useGfsRule(id)
Fetch a single GFS rule by ID.
const { rule, loading, error, refetch } = useGfsRule('rule-id');
useBooking()
Manage booking ingestion operations (API key auth).
const { response, loading, error, upsert, createBooking, cancelBooking, voidBooking, getStatus } = useBooking();
// Create a booking
await createBooking({
pnr_id: 'ABC123',
source: { pos: 'UK', gds: 'AMADEUS', airline_code: 'BA' },
travel: { departure_city: 'LHR', arrival_city: 'JFK', trip_type: 'RETURN' },
passengers: { pax_count: 2 },
financials: { currency: 'GBP', grand_total: 1250.00 }
});
// Cancel a booking
await cancelBooking('ABC123', {
cancellation_date: '2026-03-15',
cancellation_fee: 75.00,
reason: 'Customer request'
});
// Void a booking
await voidBooking('ABC123', 'Duplicate entry');
// Get status
await getStatus('ABC123');
console.log(response?.status); // ACCEPTED
Supported Event Types
| Type | Description |
|---|---|
CREATED |
New booking |
MODIFIED |
Booking update |
CANCELLED |
Cancellation |
VOIDED |
Void (same-day cancel) |
REFUNDED |
Refund processed |
EXCHANGED |
Rebooked to new PNR |
Using Services Directly
If you prefer not to use hooks, you can use the services directly:
import { authService, domainService, gfsRuleService, bookingService } from '@omeron/ota-bre-react-sdk';
// Login
const response = await authService.login({ email: 'user@example.com', password: 'password' });
// Get domains
const domains = await domainService.findAll({ page: 0, size: 20 });
// Create rule
const rule = await gfsRuleService.create({
name: 'New Rule',
ruleType: 'ROUTING',
sequenceNumber: 1,
conditions: {},
actions: {},
enabled: true
});
Complete Examples
Login Component
import React, { useState } from 'react';
import { useAuth } from '@omeron/ota-bre-react-sdk';
function LoginPage() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const { user, loading, error, login } = useAuth();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
await login(email, password);
// Redirect or update UI
} catch (err) {
console.error('Login failed:', err);
}
};
if (user) {
return <div>Welcome, {user.firstName}!</div>;
}
return (
<form onSubmit={handleSubmit}>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Email"
/>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Password"
/>
<button type="submit" disabled={loading}>
{loading ? 'Logging in...' : 'Login'}
</button>
{error && <div style={{ color: 'red' }}>{error}</div>}
</form>
);
}
Rules List Component
import React from 'react';
import { useGfsRules } from '@omeron/ota-bre-react-sdk';
function RulesList() {
const { rules, loading, error, toggleRule } = useGfsRules({ page: 0, size: 20 });
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error}</div>;
if (!rules) return null;
return (
<div>
<h2>GFS Rules</h2>
{rules.content.map(rule => (
<div key={rule.id}>
<h3>{rule.name}</h3>
<p>Sequence: {rule.sequenceNumber}</p>
<p>Status: {rule.enabled ? 'Enabled' : 'Disabled'}</p>
<button onClick={() => toggleRule(rule.id, !rule.enabled)}>
{rule.enabled ? 'Disable' : 'Enable'}
</button>
</div>
))}
<div>
Page {rules.number + 1} of {rules.totalPages}
</div>
</div>
);
}
SFTP Test Component
import React, { useState } from 'react';
import { useDomainSettings, useSftpTest } from '@omeron/ota-bre-react-sdk';
function SftpTestPanel({ domainId }: { domainId: string }) {
const { settings } = useDomainSettings(domainId);
const { result, testing, error, testConnection } = useSftpTest();
const handleTest = async () => {
if (settings) {
await testConnection(domainId, settings);
}
};
return (
<div>
<button onClick={handleTest} disabled={testing || !settings}>
{testing ? 'Testing...' : 'Test SFTP Connection'}
</button>
{error && <div style={{ color: 'red' }}>Error: {error}</div>}
{result?.success && (
<div>
<h3>Connection Successful</h3>
<p>Host: {result.host}:{result.port}</p>
<p>Path: {result.path}</p>
<h4>Files ({result.files?.length || 0}):</h4>
<ul>
{result.files?.map((file, idx) => (
<li key={idx}>
{file.name} - {file.isDirectory ? 'Directory' : `${file.size} bytes`}
</li>
))}
</ul>
</div>
)}
</div>
);
}
Authentication
The SDK automatically handles JWT token storage and injection:
- Tokens are stored in localStorage
- All requests include
Authorization: Bearer <token>header - 401 responses automatically clear tokens
- Domain ID is automatically included in
X-Domain-IDheader
TypeScript Support
The SDK is written in TypeScript and includes full type definitions:
import { User, Domain, GFSRule, DomainSettings } from '@omeron/ota-bre-react-sdk';
const user: User = await authService.getCurrentUser();
const domain: Domain = await domainService.findById('id');
Error Handling
All hooks return an error state:
const { data, loading, error } = useDomains();
if (error) {
console.error('Failed to fetch domains:', error);
}
Services throw errors that you can catch:
try {
await domainService.create({ name: 'New Domain' });
} catch (error) {
console.error('Creation failed:', error);
}
License
MIT
Dependencies
Dependencies
| ID | Version |
|---|---|
| axios | ^1.6.0 |
Development Dependencies
| ID | Version |
|---|---|
| @types/node | ^20.0.0 |
| @types/react | ^18.0.0 |
| react | ^18.2.0 |
| typescript | ^5.0.0 |
Peer Dependencies
| ID | Version |
|---|---|
| react | >=16.8.0 |
Keywords
ota
business-rules
react
sdk
api-client
hooks
Details
2026-04-16 17:05:52 +00:00
Assets (1)
Versions (1)
View all
npm
0
Omeron
MIT
latest
15 KiB
ota-bre-react-sdk-1.0.0.tgz
15 KiB
1.0.0
2026-04-16