Generally a resident state will give a credit for taxes paid to a nonresident state for income which has been taxed by both. So NJ would be giving the other state tax credit. You should go through the nonresident state first, so the resident state can take that into account. The other state tax credit is generally limited to the tax paid to the other state on the same income.
New York will compute tax on total/federal income earned by nonresidents, and then apply a percentage of NY sourced income over total/federal income, to the tax.