How to use contentful-sdk-core - 10 common examples

To help you get started, we’ve selected a few contentful-sdk-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github contentful / contentful.js / lib / paged-sync.js View on Github external
// clones response.items used in includes because we don't want these to be mutated
      if (resolveLinks) {
        response.items = resolveResponse(response, {removeUnresolved, itemEntryPoints: ['fields']})
      }
      // maps response items again after getters are attached
      const mappedResponseItems = mapResponseItems(response.items)

      if (response.nextSyncToken) {
        mappedResponseItems.nextSyncToken = response.nextSyncToken
      }

      if (response.nextPageToken) {
        mappedResponseItems.nextPageToken = response.nextPageToken
      }

      return freezeSys(mixinStringifySafe(toPlainObject(mappedResponseItems)))
    }, (error) => {
      throw error
github contentful / contentful.js / lib / contentful.js View on Github external
const config = {
    ...defaultConfig,
    ...params
  }

  const userAgentHeader = getUserAgentHeader(`contentful.js/${__VERSION__}`,
    config.application,
    config.integration
  )
  config.headers = {
    ...config.headers,
    'Content-Type': 'application/vnd.contentful.delivery.v1+json',
    'X-Contentful-User-Agent': userAgentHeader
  }

  const http = createHttpClient(axios, config)

  const getGlobalOptions = createGlobalOptions({
    resolveLinks: config.resolveLinks,
    environment: config.environment,
    removeUnresolved: config.removeUnresolved,
    spaceBaseUrl: http.defaults.baseURL,
    environmentBaseUrl: `${http.defaults.baseURL}environments/${config.environment}`
  })
  // Append environment to baseURL
  http.defaults.baseURL = getGlobalOptions().environmentBaseUrl

  // Intercepts response and obscure the token
  obscureAuthTokenInResponse(http)

  return createContentfulApi({
    http,
github contentful / contentful-management.js / lib / entities / role.js View on Github external
export function wrapRoleCollection (http, data) {
  const roles = toPlainObject(cloneDeep(data))
  roles.items = roles.items.map((entity) => wrapRole(http, entity))
  return freezeSys(roles)
}
github contentful / contentful.js / lib / entities / content-type.ts View on Github external
export function wrapContentType (data: ContentTypeJSON): ContentType {
  return freezeSys(toPlainObject(cloneDeep(data)))
}
github contentful / contentful-management.js / lib / entities / space-membership.js View on Github external
export function wrapSpaceMembership (http, data) {
  const spaceMembership = toPlainObject(cloneDeep(data))
  enhanceWithMethods(spaceMembership, createSpaceMembershipApi(http))
  return freezeSys(spaceMembership)
}
github contentful / contentful.js / lib / paged-sync.js View on Github external
return (accumulated, item) => {
      if (item.sys.type === type) {
        accumulated.push(toPlainObject(item))
      }
      return accumulated
    }
  }
github contentful / contentful-management.js / lib / entities / personal-access-token.js View on Github external
export function wrapPersonalAccessToken (http, data) {
  const personalAccessToken = toPlainObject(cloneDeep(data))
  enhanceWithMethods(personalAccessToken, createPersonalAccessToken(http))
  return freezeSys(personalAccessToken)
}
github contentful / contentful-management.js / lib / entities / space.js View on Github external
export function wrapSpaceCollection (http, data) {
  const spaces = toPlainObject(cloneDeep(data))
  spaces.items = spaces.items.map((entity) => wrapSpace(http, entity))
  return freezeSys(spaces)
}
github contentful / contentful.js / lib / entities / entry.js View on Github external
export function wrapEntry (data) {
  return freezeSys(toPlainObject(cloneDeep(data)))
}
github contentful / contentful-management.js / lib / entities / locale.js View on Github external
export function wrapLocale (http, data) {
  delete data.internal_code
  const locale = toPlainObject(cloneDeep(data))
  enhanceWithMethods(locale, createLocaleApi(http))
  return freezeSys(locale)
}

contentful-sdk-core

Core modules for the Contentful JS SDKs

MIT
Latest version published 5 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages