TikTok has finalized a deal to create a new American version of the app, avoiding the looming threat of a ban in the U.S.