@newskit-render/api
v1.15.0
Published
helper package for accessing MAIN and NK API data
Downloads
975
Readme
@newskit-render/api
Helper package to make setting up and using Apollo Client with CPS (formerly Main) or NewsKit API easier.
Usage
createApolloClient
import { createApolloClient, ClientTypes } from '@newskit-render/api'
// MAIN with cookies
const mainApolloClient = await createApolloClient(
ClientTypes.main,
context.req.headers.cookie
)
// NKAPI with cookies
const nkApiApolloClient = await createApolloClient(
ClientTypes.nkapi,
context.req.headers.cookie
)
// NKAPI without cookies
const apolloClient = await createApolloClient(ClientTypes.nkapi)
// pass custom set up
const apolloClient = await createApolloClient({
initialState: {},
uri: process.env.NEWSKIT_API_ENV_URL,
headers: {
'x-api-key': process.env.NEWSKIT_API_X_API_KEY,
},
addTypename: false,
})
getApolloClient
import { getApolloClient } from '@newskit-render/api'
const shouldUseNewskitApi = true
const apolloClient = await getApolloClient(
shouldUseNewskitApi,
req.headers.cookie
)
helpers
- getHeaders - creates header for MAIN
- getAccessToken - access header used by MAIN
- getMainSession - get MAIN session from cookie
- sessionParser - decodes session id
Authentication environment variables
For MAIN and NewsKit API authentication see MAIN and NewsKit API. For Step-up MFA see @newskit-render/my-account