transferPreLoginAccountToCustomersTable = async ({
  identityId,
  apiKeyId,
  preLoginItem
}) => {
  console.log(
    'Transferring pre-login account data to customers table' +
    ` for identityId=[${identityId}]`
  )

  const newCustomerItem = {
    ApiKeyId: apiKeyId,
    Id: identityId,
    UserPoolId: preLoginItem.UserId
  }

  ;[
    'EmailAddress',
    'RegistrationStatus',
    'RegistrationMethod',
    'InviterUserId',
    'InviterEmailAddress',
    'PromoterIdentityId',
    'PromoterEmailAddress',
    'DateRegistered',
    'DateRequested'
  ].forEach(prop => {
    if ({}.hasOwnProperty.call(preLoginItem, prop)) {
      newCustomerItem[prop] = preLoginItem[prop]
    }
  })

  try {
    await dynamoDb
      .put({
        TableName: getCustomersTableName(),
        Item: newCustomerItem
      })
      .promise()

    // This must only occur if `newCustomerItem` is successfully written to
    // CustomersTable, because otherwise the `preLoginItem` data is
    // unrecoverable.
    if (preLoginItem !== undefined) {
      await dynamoDb
        .delete({
          TableName: getEnv('PreLoginAccountsTableName'),
          Key: {
            UserId: preLoginItem.UserId
          }
        })
        .promise()
    }
    console.log('Transferred pre-login account data to customers table')
  } catch (error) {
    console.error(
      'Failed to transfer pre-login account data to customers table'
    )
    throw error
  }

  return newCustomerItem
}
Given an account item from the PreLoginAccountsTable, transfer the data to
the CustomersTable, and (if successful) delete the item from the
PreLoginAccountsTable.