[EOSIO/eos] When does the account require the eosio.code permission to do some action on its own? (#4895)

Solved like this
«`
const addAuthToAccountPermission = async({
eosInstance
accountName, permissionName,
accountAuth = null, keyAuth = null
}) => {
if (!accountName || !permissionName) throw new Error()
if (accountAuth == null && keyAuth == null) throw new Error()

const account = await eosInstance.getAccount(accountName)

const { required_auth, parent, perm_name } = account.permissions
.find(p => p.perm_name === permissionName)

let update_auth = {
accounts: [],
keys: []
}

if (typeof accountAuth === ‘object’) {
update_auth.accounts.push({
permission: accountAuth,
weight: 1
})
}

if (typeof keyAuth === ‘string’) {
update_auth.keys.push({
key: keyAuth,
weight: 1
})
}

const transaction = await eosInstance.transaction(tx => {
tx.updateauth({
account: accountName,
permission: perm_name,
parent: parent,
auth: {
threshold: required_auth.threshold,
waits: required_auth.waits,
accounts: [
…required_auth.accounts,
…update_auth.accounts
],
keys: [
…required_auth.keys,
…update_auth.keys
]
}
}, { authorization: `${accountName}@active` })
})

return transaction
}
«`