Skip to content

Commit 6a50182

Browse files
authored
Merge pull request #360 from webkod3r/define-UA
Setting custom User-Agent for requests
2 parents 89ebba4 + c6028ba commit 6a50182

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

swagger-config/transactional/javascript/templates/ApiClient.mustache

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ var exports = function (apiKey = '') {
1919
'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}
2020
];{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
2121

22+
this.requestConfig = {
23+
headers: {
24+
'User-Agent': 'Transactional-JS/{{{projectVersion}}}',
25+
},
26+
};
27+
2228
// API Routes{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}{{#-first}}
2329
this.{{#tags}}{{{name}}}{{/tags}} = new {{baseName}}(this);{{/-first}}{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
2430
};
@@ -51,7 +57,7 @@ exports.prototype.post = function post(path, body = {}) {
5157
}
5258

5359
return axiosInstance
54-
.post(url, body)
60+
.post(url, body, _this.requestConfig)
5561
.then(function (response) {
5662
return response.data;
5763
})
@@ -72,6 +78,14 @@ exports.prototype.setDefaultTimeoutMs = function (timeoutMs) {
7278
axiosInstance.defaults.timeout = timeoutMs;
7379
}
7480

81+
/**
82+
* @param {Object} headers Add header to request. Example: { 'User-Agent': 'custom-value' }
83+
*/
84+
exports.prototype.setRequestHeaders = function (headers) {
85+
var _this = this;
86+
_this.requestConfig.headers = Object.assign(_this.requestConfig.headers, headers);
87+
};
88+
7589
// The default API client implementation.
7690
exports.instance = function (apiKey) {
7791
return new exports(apiKey);

swagger-config/transactional/javascript/templates/package.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"fs": false
99
},
1010
"dependencies": {
11-
"axios": "^1.6.7"
11+
"axios": "^1.7.0"
1212
},
1313
"homepage": "https://github.com/mailchimp/mailchimp-transactional-node",
1414
"repository": {

0 commit comments

Comments
 (0)