mangopay4-nodejs-sdk 1.66.1 → 1.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +78 -1
- package/lib/api.js +31 -2
- package/lib/config.js +14 -1
- package/package.json +1 -1
- package/test/services/Idempotency.js +1 -6
- package/test/services/PayIns.js +1 -6
- package/test/services/RateLimit.js +1 -6
- package/test/services/UboDeclarations.js +1 -6
- package/typings/base.d.ts +41 -0
- package/typings/index.test-d.ts +19 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -34,7 +34,84 @@ Supported options
|
|
|
34
34
|
|connectionTimeout|30000|Set the connection timeout limit (in milliseconds)|
|
|
35
35
|
|responseTimeout|80000|Set the response timeout limit (in milliseconds)|
|
|
36
36
|
|apiVersion|'v2.01'|API Version|
|
|
37
|
-
|errorHandler|```function(options, err) {console.error(options, err)}```|Set a custom error handler
|
|
37
|
+
|errorHandler|```function(options, err) {console.error(options, err)}```|Set a custom error handler|
|
|
38
|
+
|cert|null|Base64-encoded string of the mTLS certificate `.pem` file content|
|
|
39
|
+
|key|null|Base64-encoded string of the mTLS private `.key` file content|
|
|
40
|
+
|ca|null|Base64-encoded string of the private or custom certificate authority (optional)|
|
|
41
|
+
|passphrase|null|Passphrase for an encrypted mTLS private key (optional)|
|
|
42
|
+
|certFilePath|null|Path to the mTLS certificate `.pem` file (takes precedence over `cert` if set)|
|
|
43
|
+
|keyFilePath|null|Path to the mTLS private `.key` file (takes precedence over `key` if set)|
|
|
44
|
+
|caFilePath|null|Path to the private or custom certificate authority file (takes precedence over `ca` if set)|
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
mTLS
|
|
48
|
+
-------------------------------------------------
|
|
49
|
+
### Set the base URL for mTLS
|
|
50
|
+
|
|
51
|
+
Using mTLS authentication requires your integration to call a base URL with a different hostname from the standard API:
|
|
52
|
+
|
|
53
|
+
* Sandbox: `https://api-mtls.sandbox.mangopay.com`
|
|
54
|
+
* Production: `https://api-mtls.mangopay.com`
|
|
55
|
+
|
|
56
|
+
If using mTLS, your integration should use the `api-mtls` URLs for all API calls, including OAuth token generation.
|
|
57
|
+
|
|
58
|
+
**Caution:** Ensure you set the mTLS base URL, as shown in the configuration examples below. If you don’t, the mTLS certificate will not be transferred to Mangopay. When mTLS is enforced, your integration will result in an error.
|
|
59
|
+
|
|
60
|
+
### Configure the SDK’s mTLS properties
|
|
61
|
+
|
|
62
|
+
The Node.js SDK allows you to load Base64-encoded strings from your environment variables. You can also load locally stored file paths, which may be useful during testing.
|
|
63
|
+
|
|
64
|
+
**Caution:** The file path properties take precedence if both are set.
|
|
65
|
+
|
|
66
|
+
#### Base64-encoded strings
|
|
67
|
+
|
|
68
|
+
When your `.pem` certificate and private `.key` are stored as encoded strings in a secrets manager, you can load them using the following configuration properties.
|
|
69
|
+
|
|
70
|
+
**Best practice:** Use this option in Production.
|
|
71
|
+
|
|
72
|
+
| Property | Type | Description |
|
|
73
|
+
| ------------ | ----------------- |-------------------------------------------------------------------------------|
|
|
74
|
+
| `cert` | string | Base64-encoded string of the certificate `.pem` file content. |
|
|
75
|
+
| `key` | string | Base64-encoded string of the private `.key` file content. |
|
|
76
|
+
| `ca` | string (optional) | Base64-encoded string of the private or custom certificate authority, if used. |
|
|
77
|
+
| `passphrase` | string (optional) | String of the passphrase for an encrypted private key. |
|
|
78
|
+
|
|
79
|
+
```jsx theme={null}
|
|
80
|
+
const mangopay = new Mangopay({
|
|
81
|
+
clientId: 'your-mangopay-client-id',
|
|
82
|
+
clientApiKey: 'your-api-key',
|
|
83
|
+
baseUrl: 'https://api-mtls.sandbox.mangopay.com', // mTLS base URL
|
|
84
|
+
cert: process.env.CERTIFICATE_PEM_B64, // Base64-encoded
|
|
85
|
+
key: process.env.PRIVATE_KEY_B64, // Base64-encoded
|
|
86
|
+
ca: process.env.YOUR_CUSTOM_CA, // Base64-encoded (optional)
|
|
87
|
+
passphrase: process.env.YOUR_CERT_PASSPHRASE, // (optional)
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### File paths
|
|
92
|
+
|
|
93
|
+
If your `.pem` certificate and private `.key` are stored locally, for example during testing, you can load them using the following properties.
|
|
94
|
+
|
|
95
|
+
**Caution:** If the file path properties are set, they take precedence and the Base64-encoded equivalents are ignored.
|
|
96
|
+
|
|
97
|
+
| Property | Type | Description |
|
|
98
|
+
| -------------- | ----------------- | ------------------------------------------------------------- |
|
|
99
|
+
| `certFilePath` | string | Path to the certificate `.pem` file. |
|
|
100
|
+
| `keyFilePath` | string | Path to the private `.key` file. |
|
|
101
|
+
| `caFilePath` | string (optional) | Path to the private or custom certificate authority, if used. |
|
|
102
|
+
| `passphrase` | string (optional) | String of the passphrase for an encrypted private key. |
|
|
103
|
+
|
|
104
|
+
```jsx theme={null}
|
|
105
|
+
const mangopay = new Mangopay({
|
|
106
|
+
clientId: 'your-mangopay-client-id',
|
|
107
|
+
clientApiKey: 'your-api-key',
|
|
108
|
+
baseUrl: 'https://api-mtls.sandbox.mangopay.com', // mTLS base URL
|
|
109
|
+
certFilePath: '/path/to/certificate.pem',
|
|
110
|
+
keyFilePath: '/path/to/private.key',
|
|
111
|
+
caFilePath: '/path/to/custom-ca.crt', // optional
|
|
112
|
+
passphrase: 'your-cert-passphrase', // optional
|
|
113
|
+
});
|
|
114
|
+
```
|
|
38
115
|
|
|
39
116
|
Documentation
|
|
40
117
|
-------------------------------------------------
|
package/lib/api.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
var _ = require('underscore');
|
|
2
2
|
var Promise = require('promise');
|
|
3
3
|
var querystring = require('querystring');
|
|
4
|
+
var https = require('https');
|
|
5
|
+
var fs = require('fs');
|
|
4
6
|
|
|
5
7
|
var apiMethods = require('./apiMethods');
|
|
6
8
|
var apiModels = require('./models');
|
|
@@ -20,6 +22,29 @@ function _getBasicAuthHash(username, apiKey) {
|
|
|
20
22
|
return 'Basic ' + Buffer.from(username + ':' + apiKey).toString('base64');
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
function _buildHttpsAgent(config) {
|
|
26
|
+
var agentOptions = {
|
|
27
|
+
minVersion: 'TLSv1.2'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var cert = (config.cert && Buffer.from(config.cert, 'base64').toString('utf8')) || (config.certFilePath && fs.readFileSync(config.certFilePath));
|
|
31
|
+
var key = (config.key && Buffer.from(config.key, 'base64').toString('utf8')) || (config.keyFilePath && fs.readFileSync(config.keyFilePath));
|
|
32
|
+
var ca = (config.ca && Buffer.from(config.ca, 'base64').toString('utf8')) || (config.caFilePath && fs.readFileSync(config.caFilePath));
|
|
33
|
+
|
|
34
|
+
if (cert && key) {
|
|
35
|
+
agentOptions.cert = cert;
|
|
36
|
+
agentOptions.key = key;
|
|
37
|
+
if (ca) {
|
|
38
|
+
agentOptions.ca = ca;
|
|
39
|
+
}
|
|
40
|
+
if (config.passphrase) {
|
|
41
|
+
agentOptions.passphrase = config.passphrase;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return new https.Agent(agentOptions);
|
|
46
|
+
}
|
|
47
|
+
|
|
23
48
|
var Api = function (config) {
|
|
24
49
|
var defaultConfig = require('./config');
|
|
25
50
|
config = this.config = _.extend({}, defaultConfig, config);
|
|
@@ -30,6 +55,8 @@ var Api = function (config) {
|
|
|
30
55
|
|
|
31
56
|
this.errorHandler = config.errorHandler;
|
|
32
57
|
|
|
58
|
+
this.httpsAgent = _buildHttpsAgent(config);
|
|
59
|
+
|
|
33
60
|
this.rateLimits = [];
|
|
34
61
|
|
|
35
62
|
// Add default request configuration options
|
|
@@ -244,7 +271,8 @@ Api.prototype = {
|
|
|
244
271
|
data: requestOptions.data,
|
|
245
272
|
headers: requestOptions.headers,
|
|
246
273
|
params: requestOptions.parameters,
|
|
247
|
-
signal: abortSignal
|
|
274
|
+
signal: abortSignal,
|
|
275
|
+
httpsAgent: self.httpsAgent
|
|
248
276
|
})
|
|
249
277
|
.then(function (response) {
|
|
250
278
|
var resolveArgument = (resolveWithFullResponse) ?
|
|
@@ -357,7 +385,8 @@ Api.prototype = {
|
|
|
357
385
|
headers: _.extend({}, self.requestOptions.headers, {
|
|
358
386
|
'Authorization': _getBasicAuthHash(self.config.clientId, self.config.clientApiKey),
|
|
359
387
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
360
|
-
})
|
|
388
|
+
}),
|
|
389
|
+
httpsAgent: self.httpsAgent
|
|
361
390
|
})
|
|
362
391
|
.then(function (response) {
|
|
363
392
|
// Authorization succeeded
|
package/lib/config.js
CHANGED
|
@@ -53,5 +53,18 @@ module.exports = {
|
|
|
53
53
|
*/
|
|
54
54
|
errorHandler: function(options, err) {
|
|
55
55
|
console.error(options, err);
|
|
56
|
-
}
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// mTLS – base64-encoded PEM content
|
|
59
|
+
cert: null,
|
|
60
|
+
key: null,
|
|
61
|
+
ca: null,
|
|
62
|
+
|
|
63
|
+
// mTLS – file paths (SDK reads them at init)
|
|
64
|
+
certFilePath: null,
|
|
65
|
+
keyFilePath: null,
|
|
66
|
+
caFilePath: null,
|
|
67
|
+
|
|
68
|
+
// optional passphrase for encrypted private key
|
|
69
|
+
passphrase: null
|
|
57
70
|
};
|
package/package.json
CHANGED
|
@@ -2,12 +2,7 @@ var expect = require('chai').expect;
|
|
|
2
2
|
var api = require('../main');
|
|
3
3
|
|
|
4
4
|
var helpers = require('../helpers');
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var api = global.api = new mangopay({
|
|
8
|
-
clientId: 'sdk-unit-tests',
|
|
9
|
-
clientApiKey: 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
|
|
10
|
-
});
|
|
5
|
+
var api = require('../main');
|
|
11
6
|
|
|
12
7
|
describe('Idempotency', function () {
|
|
13
8
|
var idempotencyKey = helpers.generateRandomString();
|
package/test/services/PayIns.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
var expect = require('chai').expect;
|
|
2
2
|
|
|
3
3
|
var helpers = require('../helpers');
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var api = global.api = new mangopay({
|
|
7
|
-
clientId: 'sdk-unit-tests',
|
|
8
|
-
clientApiKey: 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
|
|
9
|
-
});
|
|
4
|
+
var api = require('../main');
|
|
10
5
|
|
|
11
6
|
describe('PayIns', function () {
|
|
12
7
|
var payIn;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
var expect = require('chai').expect;
|
|
2
2
|
var helpers = require('../helpers');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var api = global.api = new mangopay({
|
|
6
|
-
clientId: 'sdk-unit-tests',
|
|
7
|
-
clientApiKey: 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
|
|
8
|
-
});
|
|
3
|
+
var api = require('../main');
|
|
9
4
|
|
|
10
5
|
describe('Rate Limits', function () {
|
|
11
6
|
expect(api.rateLimits).to.be.empty;
|
|
@@ -6,12 +6,7 @@ var Ubo = require('../../lib/models/Ubo');
|
|
|
6
6
|
var UboDeclarationStatus = require('../../lib/models/UboDeclarationStatus');
|
|
7
7
|
var UserNatural = require('../../lib/models/UserNatural');
|
|
8
8
|
var UserLegal = require('../../lib/models/UserLegal');
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var api = global.api = new mangopay({
|
|
12
|
-
clientId: 'sdk-unit-tests',
|
|
13
|
-
clientApiKey: 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
|
|
14
|
-
});
|
|
9
|
+
var api = require('../main');
|
|
15
10
|
|
|
16
11
|
describe('UBO Declarations', function () {
|
|
17
12
|
var user = new UserLegal(helpers.data.getUserLegal());
|
package/typings/base.d.ts
CHANGED
|
@@ -64,6 +64,47 @@ export namespace base {
|
|
|
64
64
|
* @default `console.error`
|
|
65
65
|
*/
|
|
66
66
|
errorHandler?(options: any, err: any): void;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Client certificate for mTLS (PEM string or Buffer).
|
|
70
|
+
* Use either this or `certFilePath`.
|
|
71
|
+
*/
|
|
72
|
+
cert?: string | Buffer;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Client private key for mTLS (PEM string or Buffer).
|
|
76
|
+
* Use either this or `keyFilePath`.
|
|
77
|
+
*/
|
|
78
|
+
key?: string | Buffer;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* CA certificate for mTLS (PEM string or Buffer).
|
|
82
|
+
* Use either this or `caFilePath`.
|
|
83
|
+
*/
|
|
84
|
+
ca?: string | Buffer;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Path to client certificate file for mTLS.
|
|
88
|
+
* Read at initialization time. Ignored if `cert` is set.
|
|
89
|
+
*/
|
|
90
|
+
certFilePath?: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Path to client private key file for mTLS.
|
|
94
|
+
* Read at initialization time. Ignored if `key` is set.
|
|
95
|
+
*/
|
|
96
|
+
keyFilePath?: string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Path to CA certificate file for mTLS.
|
|
100
|
+
* Read at initialization time. Ignored if `ca` is set.
|
|
101
|
+
*/
|
|
102
|
+
caFilePath?: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Passphrase for an encrypted private key (`key` or `keyFilePath`).
|
|
106
|
+
*/
|
|
107
|
+
passphrase?: string;
|
|
67
108
|
}
|
|
68
109
|
|
|
69
110
|
interface RequestOptions {
|
package/typings/index.test-d.ts
CHANGED
|
@@ -12,6 +12,25 @@ const validConfig: Mangopay.base.Config = {
|
|
|
12
12
|
baseUrl: "https://api.mangopay.com"
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// mTLS config — file paths
|
|
16
|
+
const mtlsConfigPaths: Mangopay.base.Config = {
|
|
17
|
+
clientId: "your_client_id",
|
|
18
|
+
clientApiKey: "your_client_api_key",
|
|
19
|
+
certFilePath: "/path/to/cert.pem",
|
|
20
|
+
keyFilePath: "/path/to/key.pem",
|
|
21
|
+
caFilePath: "/path/to/ca.pem",
|
|
22
|
+
passphrase: "secret"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// mTLS config — raw content
|
|
26
|
+
const mtlsConfigRaw: Mangopay.base.Config = {
|
|
27
|
+
clientId: "your_client_id",
|
|
28
|
+
clientApiKey: "your_client_api_key",
|
|
29
|
+
cert: "base64_string",
|
|
30
|
+
key: "base64_string",
|
|
31
|
+
passphrase: "secret"
|
|
32
|
+
};
|
|
33
|
+
|
|
15
34
|
// API instance tests
|
|
16
35
|
const api = new Mangopay(validConfig);
|
|
17
36
|
expectType<Mangopay>(api);
|