How to use the contentful-migration/built/bin/lib/contentful-client.createManagementClient function in contentful-migration

To help you get started, we’ve selected a few contentful-migration 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 deluan / contentful-migrate / lib / run.js View on Github external
const run = async ({
  spaceId, environmentId, accessToken, dryRun, migrationFunction
}) => {
  const config = { spaceId, environmentId, accessToken }
  const clientConfig = Object.assign({
    application: `contentful-migrate/${version}`
  }, config)
  const client = createManagementClient(clientConfig)

  const makeRequest = (requestConfig) => {
    // eslint-disable-next-line no-param-reassign
    requestConfig.url = path.join(config.spaceId, 'environments', environmentId, requestConfig.url)
    return client.rawRequest(requestConfig)
  const migrationParser = migrationParser1.default(makeRequest, clientConfig)
  let parseResult
  try {
    parseResult = await migrationParser(migrationFunction)
  } catch (e) {
    if (e instanceof SpaceAccessError) {
      const message = [`${e.message}\n`),'🚨  Migration unsuccessful')