@jotul/jotul-api
v1.1.0
Published
Server-side wrapper helpers for protected Jotul API routes.
Readme
@jotul/jotul-api
Server-side wrapper helpers for protected Jotul API routes.
Use this package from a partner-owned backend route so the browser never sees
JOTUL_API_KEY.
Setup
import { createWidgetRouteHandler } from '@jotul/jotul-api'
export const dynamic = 'force-dynamic'
export const GET = createWidgetRouteHandler()Example Next route file:
// app/api/jotul/widget/route.ts
import { createWidgetRouteHandler } from '@jotul/jotul-api'
export const dynamic = 'force-dynamic'
export const GET = createWidgetRouteHandler()Or, if you want to pass the key explicitly from the route:
import { createWidgetRouteHandler } from '@jotul/jotul-api'
export const dynamic = 'force-dynamic'
export const GET = createWidgetRouteHandler({
apiKey: process.env.JOTUL_API_KEY!,
})This route will:
- Read
JOTUL_API_KEYfrom server env - Call the Find Dealer API on
https://api.jotul.com/api/v1/find-dealer(dealer search and location autocomplete) - Return widget-friendly JSON/status to the browser
Error normalization:
- invalid/disabled API key ->
Invalid API key - missing dealer permission ->
Insufficient permissions
