btrz-api-client 5.224.0 → 5.225.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.
@@ -16,6 +16,10 @@ function authorizationHeaders(_ref) {
16
16
  _headers["x-api-key"] = "" + token;
17
17
  }
18
18
 
19
+ if (headers && headers.cookie && headers.cookie.includes("btrz-trusted")) {
20
+ _headers.cookie = headers.cookie;
21
+ }
22
+
19
23
  if (jwtToken && jwtToken === constants.INTERNAL_AUTH_TOKEN_SYMBOL) {
20
24
  if (!internalAuthTokenProvider || typeof internalAuthTokenProvider.getToken !== "function") {
21
25
  throw new Error("Tried to make an internal API request, but no 'internalAuthTokenProvider' with a 'getToken' function " + "was supplied to the API client");
@@ -9,6 +9,7 @@ function payOnAccountsFactory(_ref) {
9
9
 
10
10
  function all(_ref2) {
11
11
  var token = _ref2.token,
12
+ jwtToken = _ref2.jwtToken,
12
13
  _ref2$query = _ref2.query,
13
14
  query = _ref2$query === undefined ? {} : _ref2$query,
14
15
  _ref2$responseType = _ref2.responseType,
@@ -18,7 +19,7 @@ function payOnAccountsFactory(_ref) {
18
19
  return client.get("/pay-on-accounts", {
19
20
  params: query,
20
21
  responseType: responseType,
21
- headers: authorizationHeaders({ token: token, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
22
+ headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
22
23
  });
23
24
  }
24
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-api-client",
3
- "version": "5.224.0",
3
+ "version": "5.225.0",
4
4
  "description": "Api client for Betterez endpoints",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,6 +9,10 @@ function authorizationHeaders({
9
9
  _headers["x-api-key"] = `${token}`;
10
10
  }
11
11
 
12
+ if (headers && headers.cookie && headers.cookie.includes("btrz-trusted")) {
13
+ _headers.cookie = headers.cookie;
14
+ }
15
+
12
16
  if (jwtToken && jwtToken === constants.INTERNAL_AUTH_TOKEN_SYMBOL) {
13
17
  if (!internalAuthTokenProvider || typeof internalAuthTokenProvider.getToken !== "function") {
14
18
  throw new Error("Tried to make an internal API request, but no 'internalAuthTokenProvider' with a 'getToken' function " +
@@ -1,11 +1,11 @@
1
1
  const {authorizationHeaders} = require("../endpoints_helpers.js");
2
2
 
3
3
  function payOnAccountsFactory({client, internalAuthTokenProvider}) {
4
- function all({token, query = {}, responseType = "json", headers}) {
4
+ function all({token, jwtToken, query = {}, responseType = "json", headers}) {
5
5
  return client.get("/pay-on-accounts", {
6
6
  params: query,
7
7
  responseType,
8
- headers: authorizationHeaders({token, internalAuthTokenProvider, headers})
8
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
9
9
  });
10
10
  }
11
11
 
@@ -16,6 +16,16 @@ describe("endpoints helpers", () => {
16
16
  });
17
17
  });
18
18
 
19
+ it("should return a headers object which includes the btrz-trusted cookie", () => {
20
+ const jwtToken = "7A0mvzROJIucrSPYHlgd";
21
+ const headers = authorizationHeaders({jwtToken, headers: {cookie: "btrz-trusted=teststuff"}});
22
+
23
+ expect(headers).to.deep.equal({
24
+ authorization: `Bearer ${jwtToken}`,
25
+ cookie: "btrz-trusted=teststuff"
26
+ });
27
+ });
28
+
19
29
  it("should return a headers object which includes an auth token created using the 'internalAuthTokenProvider', when the caller " +
20
30
  "is trying to make an internal service-to-service API request", () => {
21
31
  const jwtToken = constants.INTERNAL_AUTH_TOKEN_SYMBOL,
@@ -3,19 +3,20 @@ const api = require("../../../src/client.js").createApiClient({baseURL: "http://
3
3
 
4
4
  describe("inventory/pay-on-accounts", () => {
5
5
  const token = "I owe you a token";
6
+ const jwtToken = "I owe you a JWT token";
6
7
 
7
8
  afterEach(() => {
8
9
  axiosMock.reset();
9
10
  });
10
11
 
11
12
  it("should list pay-on-accounts", () => {
12
- axiosMock.onGet("/pay-on-accounts").reply(expectRequest({statusCode: 200, token}));
13
- return api.inventory.payOnAccounts.all({token});
13
+ axiosMock.onGet("/pay-on-accounts").reply(expectRequest({statusCode: 200, token, jwtToken}));
14
+ return api.inventory.payOnAccounts.all({token, jwtToken});
14
15
  });
15
16
 
16
17
  it("should list pay-on-accounts with responseType blob", () => {
17
18
  const responseType = "blob";
18
- axiosMock.onGet("/pay-on-accounts").reply(expectRequest({statusCode: 200, token}));
19
- return api.inventory.payOnAccounts.all({token, responseType});
19
+ axiosMock.onGet("/pay-on-accounts").reply(expectRequest({statusCode: 200, token, jwtToken, responseType}));
20
+ return api.inventory.payOnAccounts.all({token, jwtToken, responseType});
20
21
  });
21
22
  });
package/types/client.d.ts CHANGED
@@ -828,8 +828,9 @@ export function createApiClient(options: {
828
828
  }) => any;
829
829
  };
830
830
  payOnAccounts: {
831
- all: ({ token, query, responseType, headers }: {
831
+ all: ({ token, jwtToken, query, responseType, headers }: {
832
832
  token: any;
833
+ jwtToken: any;
833
834
  query?: {};
834
835
  responseType?: string;
835
836
  headers: any;
@@ -5,5 +5,6 @@ export function authorizationHeaders({ token, jwtToken, internalAuthTokenProvide
5
5
  headers: any;
6
6
  }): {
7
7
  "x-api-key": string;
8
+ cookie: any;
8
9
  authorization: string;
9
10
  };
@@ -3,8 +3,9 @@ declare function payOnAccountsFactory({ client, internalAuthTokenProvider }: {
3
3
  client: any;
4
4
  internalAuthTokenProvider: any;
5
5
  }): {
6
- all: ({ token, query, responseType, headers }: {
6
+ all: ({ token, jwtToken, query, responseType, headers }: {
7
7
  token: any;
8
+ jwtToken: any;
8
9
  query?: {};
9
10
  responseType?: string;
10
11
  headers: any;
@@ -782,8 +782,9 @@ declare const _exports: {
782
782
  }) => any;
783
783
  };
784
784
  payOnAccounts: {
785
- all: ({ token, query, responseType, headers }: {
785
+ all: ({ token, jwtToken, query, responseType, headers }: {
786
786
  token: any;
787
+ jwtToken: any;
787
788
  query?: {};
788
789
  responseType?: string;
789
790
  headers: any;