Add hotel_location and met_office integrations
Two new schema-driven integrations for hvac's weather compensation feature: hotel_location (lat/lon, plaintext config) and met_office (encrypted api_key). Both surface automatically on the portal's Integrations tab via the existing generic integration UI/routes — no portal changes needed. Deliberately central here rather than hvac-local so other apps can reuse the hotel's location later. Added a met_office connection test (DataHub daily-forecast call) alongside the others. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
9fce62525d
commit
5f84a44d1f
2 changed files with 22 additions and 0 deletions
|
|
@ -52,6 +52,16 @@ export const INTEGRATIONS = {
|
||||||
configFields: ['host', 'port'],
|
configFields: ['host', 'port'],
|
||||||
secretFields: ['username', 'password'],
|
secretFields: ['username', 'password'],
|
||||||
},
|
},
|
||||||
|
hotel_location: {
|
||||||
|
name: 'Hotel Location',
|
||||||
|
configFields: ['latitude', 'longitude'],
|
||||||
|
secretFields: [],
|
||||||
|
},
|
||||||
|
met_office: {
|
||||||
|
name: 'Met Office DataHub',
|
||||||
|
configFields: [],
|
||||||
|
secretFields: ['api_key'],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MASKED = '••••••••'
|
export const MASKED = '••••••••'
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,18 @@ export async function integrationRoutes(app) {
|
||||||
if (res.status === 401 || res.status === 403) throw new Error('Invalid Azure API key')
|
if (res.status === 401 || res.status === 403) throw new Error('Invalid Azure API key')
|
||||||
if (!res.ok) throw new Error(`Azure returned ${res.status}`)
|
if (!res.ok) throw new Error(`Azure returned ${res.status}`)
|
||||||
}
|
}
|
||||||
|
else if (req.params.slug === 'met_office') {
|
||||||
|
if (!creds.api_key) throw new Error('Met Office API key required')
|
||||||
|
const { rows: [loc] } = await pool.query(`SELECT config FROM integrations WHERE slug = 'hotel_location'`)
|
||||||
|
const lat = loc?.config?.latitude || '51.5072'
|
||||||
|
const lon = loc?.config?.longitude || '-0.1276'
|
||||||
|
const res = await fetch(
|
||||||
|
`https://data.hub.api.metoffice.gov.uk/sitespecific/v0/point/daily?latitude=${lat}&longitude=${lon}`,
|
||||||
|
{ headers: { apikey: creds.api_key }, signal: AbortSignal.timeout(8000) }
|
||||||
|
)
|
||||||
|
if (res.status === 401 || res.status === 403) throw new Error('Invalid Met Office API key')
|
||||||
|
if (!res.ok) throw new Error(`Met Office DataHub returned ${res.status}`)
|
||||||
|
}
|
||||||
else if (req.params.slug === 'sambapos') {
|
else if (req.params.slug === 'sambapos') {
|
||||||
const errors = []
|
const errors = []
|
||||||
// SQL test — SambaPOS uses MSSQL; host may be "server\INSTANCE"
|
// SQL test — SambaPOS uses MSSQL; host may be "server\INSTANCE"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue