Ah, ok, I understand what you mean, thank you for the sugestion. It doesnt apply to my problem tho because I am treating the discount code as a wildcard not something I could easily control. Controling the discount code behaviour trough the admin or api is the solution, however it isnt practical when you have many existing sales rules and 3rd party apps generate new ones regularly.
Did you ever find a working solution? I'm having the same issue. Shopify REALLY needs to add the ability to mark certain products as undiscountable in the admin. The accepted solution of creating an automatic collection isn't scalable if you have thousands of existing discount codes and dozens of distributed people creating future discount codes.
I did not find a solution unfortunately. I dont think there is a solution at this point. There are some really hacky things I thought might work with the script api but I did not try it -> Like for discountable products, on the first run you would set the discount in line item props, then reject the discount. On the cart refresh you should still have the props, use the info in them to apply a discount (make sure to have this capped since props are editable) and then finally remove the props.