btrz-api-client 3.27.0 → 3.31.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/lib/client-standalone-min.js +1 -1
- package/lib/client.js +201 -167
- package/lib/endpoints/accounts/email-settings.js +85 -0
- package/lib/endpoints/gps/scanner-app-location.js +29 -0
- package/lib/endpoints/inventory/products.js +2 -2
- package/lib/endpoints/invoices/pdfs.js +6 -3
- package/package.json +1 -1
- package/src/client.js +171 -139
- package/src/endpoints/accounts/email-settings.js +55 -0
- package/src/endpoints/gps/scanner-app-location.js +18 -0
- package/src/endpoints/inventory/products.js +7 -9
- package/src/endpoints/invoices/pdfs.js +4 -3
- package/test/endpoints/gps/scanner-app-location.js +26 -0
- package/test/endpoints/inventory/products.test.js +7 -1
- package/test/test-helpers.js +16 -14
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* eslint-disable import/extensions */
|
|
2
|
+
const {authorizationHeaders} = require("./../endpoints_helpers");
|
|
3
|
+
|
|
4
|
+
function emailSettingsFactory({client, internalAuthTokenProvider}) {
|
|
5
|
+
function all({token, jwtToken, query = {}}) {
|
|
6
|
+
return client({
|
|
7
|
+
params: query,
|
|
8
|
+
url: "/email-settings",
|
|
9
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider})
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function getByEmail({token, jwtToken, email, query = {}}) {
|
|
13
|
+
return client({
|
|
14
|
+
params: query,
|
|
15
|
+
url: `/email-settings/${email}`,
|
|
16
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider})
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function create({data, token, jwtToken}) {
|
|
21
|
+
return client({
|
|
22
|
+
url: "/email-settings",
|
|
23
|
+
method: "post",
|
|
24
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider}),
|
|
25
|
+
data
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function update({token, jwtToken, email, data}) {
|
|
30
|
+
return client({
|
|
31
|
+
url: `/email-settings/${email}`,
|
|
32
|
+
method: "put",
|
|
33
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider}),
|
|
34
|
+
data
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function remove({email, token, jwtToken}) {
|
|
39
|
+
return client({
|
|
40
|
+
url: `/email-settings/${email}`,
|
|
41
|
+
method: "delete",
|
|
42
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider})
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
all,
|
|
48
|
+
getByEmail,
|
|
49
|
+
create,
|
|
50
|
+
update,
|
|
51
|
+
remove
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = emailSettingsFactory;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const {authorizationHeaders} = require("./../endpoints_helpers.js");
|
|
2
|
+
|
|
3
|
+
//TODO: add docs function when docs published
|
|
4
|
+
function scannerAppLocationFactory({client}) {
|
|
5
|
+
function get({token, query = {}}) {
|
|
6
|
+
return client({
|
|
7
|
+
url: "/scanner-app-location",
|
|
8
|
+
headers: authorizationHeaders({token}),
|
|
9
|
+
params: query
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
get
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = scannerAppLocationFactory;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {authorizationHeaders} = require("./../endpoints_helpers");
|
|
2
2
|
|
|
3
|
-
function productsFactory({
|
|
4
|
-
|
|
5
|
-
function all({ token, query = {} }) {
|
|
3
|
+
function productsFactory({client, internalAuthTokenProvider}) {
|
|
4
|
+
function all({token, query = {}}) {
|
|
6
5
|
return client({
|
|
7
6
|
url: "/products",
|
|
8
7
|
params: query,
|
|
@@ -10,19 +9,18 @@ function productsFactory({ client, internalAuthTokenProvider }) {
|
|
|
10
9
|
});
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
function get({
|
|
12
|
+
function get({productId, token, jwtToken, query = {}}) {
|
|
14
13
|
return client({
|
|
15
14
|
url: `/products/${productId}`,
|
|
16
15
|
params: query,
|
|
17
|
-
headers: authorizationHeaders({token, internalAuthTokenProvider})
|
|
16
|
+
headers: authorizationHeaders({token, internalAuthTokenProvider, jwtToken})
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
return {
|
|
20
|
+
return {
|
|
22
21
|
all,
|
|
23
22
|
get
|
|
24
23
|
};
|
|
25
|
-
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
module.exports = productsFactory;
|
|
26
|
+
module.exports = productsFactory;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const {authorizationHeaders} = require("./../endpoints_helpers");
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
function all({token, jwtToken, query = {}}) {
|
|
3
|
+
function pdfsFactory({client, internalAuthTokenProvider}) {
|
|
4
|
+
function all({token, jwtToken, query = {}, responseType = "json"}) {
|
|
5
5
|
return client({
|
|
6
6
|
url: "/pdfs",
|
|
7
7
|
method: "get",
|
|
8
|
+
responseType,
|
|
8
9
|
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider}),
|
|
9
10
|
params: query
|
|
10
11
|
});
|
|
@@ -15,4 +16,4 @@ function providersFactory({client, internalAuthTokenProvider}) {
|
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
module.exports =
|
|
19
|
+
module.exports = pdfsFactory;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const {axiosMock, expectRequest} = require("./../../test-helpers.js");
|
|
2
|
+
const api = require("./../../../src/client.js")
|
|
3
|
+
.createApiClient({baseURL: "http://test.com"});
|
|
4
|
+
|
|
5
|
+
describe("gps/scanner-app-location", () => {
|
|
6
|
+
const apiKey = "yourAccountAPIKey";
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
axiosMock.reset();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should GET a location", () => {
|
|
13
|
+
const routeId = "myRoute";
|
|
14
|
+
const scheduleId = "myScheduleId";
|
|
15
|
+
const date = "2020-01-01";
|
|
16
|
+
const includeTravelledPath = true;
|
|
17
|
+
const query = {
|
|
18
|
+
routeId,
|
|
19
|
+
scheduleId,
|
|
20
|
+
date,
|
|
21
|
+
includeTravelledPath
|
|
22
|
+
};
|
|
23
|
+
axiosMock.onGet("/scanner-app-location").reply(expectRequest({statusCode: 200, token: apiKey}));
|
|
24
|
+
return api.gps.scannerAppLocation.get({token: apiKey, query});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -3,6 +3,7 @@ const api = require("./../../../src/client").createApiClient({ baseURL: "http://
|
|
|
3
3
|
|
|
4
4
|
describe('inventory/products', function() {
|
|
5
5
|
const token = 'I owe you a token';
|
|
6
|
+
const jwtToken = 'I owe you a JWT token';
|
|
6
7
|
|
|
7
8
|
afterEach(function() {
|
|
8
9
|
axiosMock.reset();
|
|
@@ -13,9 +14,14 @@ describe('inventory/products', function() {
|
|
|
13
14
|
return api.inventory.products.all({ token });
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
it("should get product by id", function() {
|
|
17
|
+
it("should get product by id without jwtToken", function() {
|
|
17
18
|
axiosMock.onGet(`/products/1`).reply(expectRequest({ statusCode: 200, token }));
|
|
18
19
|
return api.inventory.products.get({ token, productId: 1 });
|
|
19
20
|
});
|
|
20
21
|
|
|
22
|
+
it("should get product by id when called with jwtToken", function() {
|
|
23
|
+
axiosMock.onGet(`/products/1`).reply(expectRequest({ statusCode: 200, token, jwtToken, requireJwtTokenOnGet:true }));
|
|
24
|
+
return api.inventory.products.get({ token, productId: 1, jwtToken });
|
|
25
|
+
});
|
|
26
|
+
|
|
21
27
|
});
|
package/test/test-helpers.js
CHANGED
|
@@ -3,22 +3,24 @@ const MockAdapter = require('axios-mock-adapter');
|
|
|
3
3
|
|
|
4
4
|
module.exports = {
|
|
5
5
|
axiosMock: new MockAdapter(axios),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
// eslint-disable-next-line max-len
|
|
7
|
+
expectRequest: function _expectRequest({statusCode, token, jwtToken, internalAuthTokenProvider, withoutApiKey = false, requireJwtTokenOnGet = false}) {
|
|
8
|
+
return ({headers, method}) => {
|
|
9
|
+
if ((headers["x-api-key"] && headers["x-api-key"] === token) || withoutApiKey) {
|
|
10
|
+
const methods = ["post", "put", "delete", "patch"];
|
|
11
|
+
if (requireJwtTokenOnGet) {
|
|
12
|
+
methods.push("get");
|
|
13
|
+
}
|
|
14
|
+
if (methods.includes(method)) {
|
|
15
|
+
if (headers.authorization && (headers.authorization === `Bearer ${jwtToken}` ||
|
|
11
16
|
headers.authorization === `Bearer ${internalAuthTokenProvider.getToken()}`)) {
|
|
12
|
-
return [statusCode]
|
|
13
|
-
} else {
|
|
14
|
-
return [403];
|
|
17
|
+
return [statusCode];
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
return [statusCode];
|
|
19
|
+
return [403];
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
return [403];
|
|
21
|
+
return [statusCode];
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
return [403];
|
|
24
|
+
};
|
|
23
25
|
}
|
|
24
|
-
};
|
|
26
|
+
};
|