[api] refactor source#index_package

Some of the code branches are rather bizzare