mangopay2-nodejs-sdk icon indicating copy to clipboard operation
mangopay2-nodejs-sdk copied to clipboard

config and requestOptions should NOT be a prototype of Api

Open domingosl opened this issue 4 years ago • 2 comments

There is fundamental error in the way Api gets instantiated:

const Mangopay = require('mangopay2-nodejs-sdk');
const client = new Mangopay(options);

By doing this, essentially the developer thinks that client is an isolated new instance of Mangopay. So is safe to create several clients in the same process:

const client1 = new Mangopay(options1);
const client2 = new Mangopay(options2);

The problem is, that Api sets config a requestOptions as prototypes: https://github.com/Mangopay/mangopay2-nodejs-sdk/blob/096af0e64be49e5c3bbd135e496a3ce0f84995ed/lib/api.js#L67

This means that client2 configuration override client1 configuration! It makes no sense to set the configuration as Prototype.

domingosl avatar Feb 26 '21 13:02 domingosl

Hello @domingosl,

Thank you for your suggestion. The technical team is reviewing it.

Have a nice day,

fredericdelordm avatar Apr 27 '21 13:04 fredericdelordm

I was hit by this bug a few times causing production requests to hit the sandbox. This is pretty bad design. Please fix 🙏

Tug avatar Feb 23 '24 14:02 Tug