@newskit-render/api
TypeScript icon, indicating that this package has built-in type declarations

1.11.0 • Public • Published

@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

  1. getHeaders - creates header for MAIN
  2. getAccessToken - access header used by MAIN
  3. getMainSession - get MAIN session from cookie
  4. 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

Dependents (6)

Package Sidebar

Install

npm i @newskit-render/api

Weekly Downloads

482

Version

1.11.0

License

UNLICENSED

Unpacked Size

82.3 kB

Total Files

86

Last publish

Collaborators

  • newskit