The easiest way to use the calendar widget is via the global calendar_listing function:
// Get a reference to a DOM element const root = document.getElementById('calendar-listing') // Initialize the widget const widget = calendar_listing(root, { api_url: 'https://example.com', criteria: { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z' } }) // Later, to clean up: widget.cleanup()
You must be signed in with the view role to use the live demo.
import { calendar_listing } from 'https://example.com/widget.es.js' const root = document.getElementById('calendar-root') calendar_listing(root, { criteria: { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z' } })
For SolidJS applications, import the component directly:
import { CalendarView, CalendarCriteria } from 'https://example.com/widget.es.js' function MyComponent() { const criteria: CalendarCriteria = { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z' } return ( <div> <CalendarView criteria={criteria} /> </div> ) }
Render a calendar widget into the specified DOM element.
| Parameter | Type | Required | Description |
|---|---|---|---|
root |
HTMLElement | Required | The DOM element to render the widget into |
props |
CalendarViewProps | Optional | Configuration options for the widget |
WidgetInstance| Property | Type | Description |
|---|---|---|
cleanup() |
function | Removes the widget and cleans up resources |
Configuration options for the calendar widget.
| Property | Type | Default | Description |
|---|---|---|---|
api_url |
string | BASE_URL | Base URL for the calendar API |
criteria |
CalendarCriteria | {} | Filters and search criteria for events |
show_header |
boolean | false | Show the calendar header with date picker and controls |
chart |
'mini' | off | Render a sparkline of the last 5 years of actual values to the right of each data row's figure. One batched history request per listing (GET /api/calendar/entries/data); hidden on narrow screens. |
get_token |
() => Promise<string | null> | OIDC session | Token provider for machine (non-sign-in) users. Called before every request so short-lived client-credentials tokens can be refreshed. Overrides OIDC session auth when provided. See Machine Users below. |
Filter criteria for calendar events. All fields are optional.
| Property | Type | Description |
|---|---|---|
by_category |
number | null | Filter by category ID |
by_location |
string | null | Filter by location code (e.g., 'US', 'UK', 'EU') |
text_query |
string | null | Search events by text content |
by_classification |
Classification | Filter by event type: 'data', 'holiday', 'ad_hoc', 'expiry', 'speaker', 'supply', 'earning' |
occurs_from |
string | null | Start date for date range filter (ISO format) |
occurs_to |
string | null | End date for date range filter (ISO format) |
const widget = calendar_listing(root, { criteria: { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z' } })
// Show only events from category ID 5 const widget = calendar_listing(root, { criteria: { by_category: 5 } })
// Show only US events const widget = calendar_listing(root, { criteria: { by_location: 'US' } }) // Show G20 major economies const g20 = ['US', 'GB', 'EU', 'JP', 'DE', 'CN', 'FR', 'IT', 'CA', 'AU'] // Note: Use multiple widget instances or broader criteria for multiple locations
// Search for events containing "GDP" const widget = calendar_listing(root, { criteria: { text_query: 'GDP' } })
// Show only economic data releases const widget = calendar_listing(root, { criteria: { by_classification: 'data' } }) // Show only holidays const widget = calendar_listing(root, { criteria: { by_classification: 'holiday' } })
// Show US economic data for today const widget = calendar_listing(root, { criteria: { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z', by_location: 'US', by_classification: 'data' } })
const widget = calendar_listing(root, { api_url: 'https://example.com/api', criteria: { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z' } })
For server-to-server or embedded integrations where no user signs in, the widget accepts a
get_token callback instead of an OIDC session. Access is controlled by a
dedicated Keycloak service-account client (OAuth2 client credentials grant),
which your backend uses to mint short-lived access tokens.
| Step | Setting | Value |
|---|---|---|
| 1. Create client | Client ID (example) | calendar-widget-<customer> |
| Client authentication | On (confidential) | |
| Authentication flow | Service accounts roles only (client credentials grant) | |
| 2. Audience mapper | Client → Mappers → Add mapper → Audience | Included Client Audience = calendar-client (the API rejects tokens whose aud/azp does not match) |
| 3. Grant access | Client → Service accounts roles → Assign role | calendar-client → external-newsquawk-user (maps to the view role) |
| 4. Credentials | Client → Credentials tab | Client Secret — goes in your backend only, never in browser code |
# Your backend mints tokens (client secret stays server-side)
POST https://<keycloak>/auth/realms/<realm>/protocol/openid-connect/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=calendar-widget-<customer>
&client_secret=<secret>Expose the short-lived token to your page via your backend (e.g. a small endpoint that returns the current token), then pass a callback. The widget calls it before every request, so expired tokens are refreshed transparently:
const widget = calendar_listing(root, { api_url: 'https://calendar.example.com', get_token: async () => { const response = await fetch('/api/calendar-token') // your backend const data = await response.json() return data.access_token }, criteria: { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z' } })
Note: get_token is called on every listing request and on SSE (re)connects —
have your backend cache the token and only re-mint near expiry.
For SolidJS applications, you can import the component and types directly:
import { CalendarView, CalendarCriteria, CalendarViewProps, CalendarEvent, Classification } from 'https://example.com/widget.es.js' // Use in your component function App() { const criteria: CalendarCriteria = { occurs_from: '2025-12-18T00:00:00.000Z', occurs_to: '2025-12-18T23:59:59.999Z', by_classification: 'data' } const props: CalendarViewProps = { api_url: 'https://example.com', criteria } return <CalendarView {...props} /> }
| Export | Type | Description |
|---|---|---|
calendar_listing |
function | Framework-agnostic widget initializer |
CalendarView |
Component | SolidJS component for direct use |
CalendarViewProps |
interface | TypeScript interface for component props |
CalendarCriteria |
interface | TypeScript interface for filter criteria |
CalendarEvent |
type | Type for calendar event objects |
Classification |
type | Union type for event classifications |
create_calendar_store |
function | Low-level store for custom integrations |