Skip to content

Commit b20eb22

Browse files
author
Baptiste Jamin
committed
v10.0.18
1 parent eceaeda commit b20eb22

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
## v10.0.18
5+
6+
* Added the new `CrispClient.setCustomHeaders` method to set custom headers for all API requests.
7+
48
## v10.0.17
59

610
* Add `stamped` to `ConversationMessage`.

lib/crisp.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ class Crisp {
240240

241241
protected _useragent = (DEFAULT_USERAGENT_PREFIX + VERSION);
242242

243+
protected _customHeaders: Record<string, string> = {};
244+
243245
protected _emitter = mitt();
244246

245247
protected _socket: Socket | null = null;
@@ -297,6 +299,17 @@ class Crisp {
297299
}
298300
}
299301

302+
/**
303+
* Sets custom headers to be included in all API requests
304+
*/
305+
setCustomHeaders(headers: Record<string, string>) {
306+
if (typeof headers === "object" && headers !== null) {
307+
this._customHeaders = headers;
308+
} else {
309+
throw new Error("[Crisp] setCustomHeaders: parameter headers should be an object");
310+
}
311+
}
312+
300313
/**
301314
* Sets the authentication tier
302315
*/
@@ -866,7 +879,8 @@ class Crisp {
866879

867880
headers: {
868881
"User-Agent": this._useragent,
869-
"X-Crisp-Tier": this.auth.tier
882+
"X-Crisp-Tier": this.auth.tier,
883+
...this._customHeaders
870884
},
871885

872886
throwHttpErrors: false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "crisp-api",
33
"description": "Crisp API wrapper for Node - official, maintained by Crisp",
4-
"version": "10.0.17",
4+
"version": "10.0.18",
55
"homepage": "https://github.com/crisp-im/node-crisp-api",
66
"license": "MIT",
77
"author": {

0 commit comments

Comments
 (0)