@financial-times/dotcom-server-app-context
TypeScript icon, indicating that this package has built-in type declarations

11.2.1 • Public • Published

@financial-times/dotcom-server-app-context

This package provides tools to define FT app context data and a JSON schema definition to validate it with. It is used to define and distribute useful information to other components including ads and tracking.

To learn more about why this feature exists please review the design document. To find out which properties can be defined please refer to the app context schema.

If you want to share application specific data with the client, consider using @financial-times/dotcom-ui-data-embed.

Getting started

This package is compatible with Node 12+ and is distributed on npm.

npm install -S @financial-times/dotcom-server-app-context

This package provides a single class which can be configured using options:

import { AppContext } from '@financial-times/dotcom-server-app-context'
const appContext = new AppContext()

The app context instance provides methods to get and set app context data:

appContext.set('appName', 'my-application')
const property = appContext.get('appName') // "my-application"
const contextData = appContext.getAll() // { appName: "my-application" }

API

get(property: string): any

Returns the value of the requested property.

set(property: string, value: any)

Sets the value of the specified property. The provided value will be validated against the app context schema. If the value is invalid this method will throw an error.

getAll(): object

Returns an immutable copy of the app context data.

Options

The AppContext class accepts the following parameters. All parameters are optional:

appContext

An app context data object, see the app context schema for more information. Defaults to {}.

/@financial-times/dotcom-server-app-context/

    Package Sidebar

    Install

    npm i @financial-times/dotcom-server-app-context

    Weekly Downloads

    191

    Version

    11.2.1

    License

    MIT

    Unpacked Size

    179 kB

    Total Files

    22

    Last publish

    Collaborators

    • robgodfrey
    • robertboulton
    • seraph2000
    • hamza.samih
    • notlee
    • emmalewis
    • aendra
    • the-ft
    • rowanmanning
    • chee
    • alexwilson