btrz-api-client 8.61.0 → 8.63.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/fetch-test.js +16 -0
- package/lib/client-standalone-min.js +3 -3
- package/lib/endpoints/inventory/promos.js +4 -2
- package/lib/endpoints/notifications/external-customers.js +28 -3
- package/package.json +7 -6
- package/src/endpoints/inventory/promos.js +4 -4
- package/src/endpoints/notifications/external-customers.js +23 -3
- package/test/endpoints/inventory/promos.test.js +21 -0
- package/test/endpoints/invoices/invoices.test.js +4 -4
- package/test/endpoints/notifications/external-customers.test.js +31 -0
- package/test/endpoints/sales/cart.test.js +3 -5
|
@@ -67,13 +67,14 @@ function promosFactory(_ref) {
|
|
|
67
67
|
*/
|
|
68
68
|
function all(_ref2) {
|
|
69
69
|
var token = _ref2.token,
|
|
70
|
+
jwtToken = _ref2.jwtToken,
|
|
70
71
|
_ref2$query = _ref2.query,
|
|
71
72
|
query = _ref2$query === undefined ? {} : _ref2$query,
|
|
72
73
|
headers = _ref2.headers;
|
|
73
74
|
|
|
74
75
|
return client.get("/promos", {
|
|
75
76
|
params: query,
|
|
76
|
-
headers: authorizationHeaders({ token: token, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
|
|
77
|
+
headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -89,13 +90,14 @@ function promosFactory(_ref) {
|
|
|
89
90
|
function get(_ref3) {
|
|
90
91
|
var promoId = _ref3.promoId,
|
|
91
92
|
token = _ref3.token,
|
|
93
|
+
jwtToken = _ref3.jwtToken,
|
|
92
94
|
_ref3$query = _ref3.query,
|
|
93
95
|
query = _ref3$query === undefined ? {} : _ref3$query,
|
|
94
96
|
headers = _ref3.headers;
|
|
95
97
|
|
|
96
98
|
return client.get("/promos/" + promoId, {
|
|
97
99
|
params: query,
|
|
98
|
-
headers: authorizationHeaders({ token: token, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
|
|
100
|
+
headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
|
|
@@ -10,11 +10,11 @@ var _require = require("../endpoints_helpers.js"),
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Factory for external-customers API (btrz-api-notifications). Saldo Max (ADO) verification-code registration.
|
|
13
|
+
* Factory for external-customers API (btrz-api-notifications). Saldo Max (ADO) verification-code registration and statement email.
|
|
14
14
|
* @param {Object} deps
|
|
15
15
|
* @param {import("axios").AxiosInstance} deps.client
|
|
16
16
|
* @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
|
|
17
|
-
* @returns {{ requestSaldoMaxVerificationCode: function }}
|
|
17
|
+
* @returns {{ requestSaldoMaxVerificationCode: function, sendSaldoMaxStatementEmail: function }}
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
|
|
@@ -46,8 +46,33 @@ function externalCustomersFactory(_ref) {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* POST /external-customers/ado/external-wallets/:walletId/statements — Request Saldo Max wallet statement email.
|
|
51
|
+
* Notifications proxies to Inventory with sendMail. No query; body is empty JSON.
|
|
52
|
+
* @param {Object} opts
|
|
53
|
+
* @param {string} [opts.token] - API key
|
|
54
|
+
* @param {string} [opts.jwtToken] - JWT (BETTEREZ_APP audience)
|
|
55
|
+
* @param {string} opts.walletId - Saldo Max wallet id (path segment; encoded in the URL)
|
|
56
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
57
|
+
* @returns {Promise<import("axios").AxiosResponse<{ success: boolean }>>}
|
|
58
|
+
*/
|
|
59
|
+
function sendSaldoMaxStatementEmail(_ref3) {
|
|
60
|
+
var token = _ref3.token,
|
|
61
|
+
jwtToken = _ref3.jwtToken,
|
|
62
|
+
walletId = _ref3.walletId,
|
|
63
|
+
headers = _ref3.headers;
|
|
64
|
+
|
|
65
|
+
return client({
|
|
66
|
+
url: "/external-customers/ado/external-wallets/" + encodeURIComponent(walletId) + "/statements",
|
|
67
|
+
method: "post",
|
|
68
|
+
headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers }),
|
|
69
|
+
data: {}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
49
73
|
return {
|
|
50
|
-
requestSaldoMaxVerificationCode: requestSaldoMaxVerificationCode
|
|
74
|
+
requestSaldoMaxVerificationCode: requestSaldoMaxVerificationCode,
|
|
75
|
+
sendSaldoMaxStatementEmail: sendSaldoMaxStatementEmail
|
|
51
76
|
};
|
|
52
77
|
}
|
|
53
78
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "btrz-api-client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.63.0",
|
|
4
4
|
"description": "Api client for Betterez endpoints",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/Betterez/btrz-api-client#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"axios-mock-adapter": "
|
|
29
|
+
"axios-mock-adapter": "2.1.0",
|
|
30
30
|
"babel-cli": "^6.26.0",
|
|
31
31
|
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
|
32
32
|
"babel-preset-es2015": "^6.24.1",
|
|
@@ -40,11 +40,12 @@
|
|
|
40
40
|
"eslint-plugin-mocha": "^5.3.0",
|
|
41
41
|
"form-data": "^3.0.0",
|
|
42
42
|
"mocha": "11.7.5",
|
|
43
|
-
"tinyify": "
|
|
44
|
-
"uuid": "
|
|
43
|
+
"tinyify": "4.0.0",
|
|
44
|
+
"uuid": "14.0.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"axios": "
|
|
48
|
-
"base-64": "^1.0.0"
|
|
47
|
+
"axios": "1.15.2",
|
|
48
|
+
"base-64": "^1.0.0",
|
|
49
|
+
"undici": "^8.1.0"
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -57,10 +57,10 @@ function promosFactory({client, internalAuthTokenProvider}) {
|
|
|
57
57
|
* Resolves with paginated promos; response.data has Promos shape.
|
|
58
58
|
* @throws When the request fails (400/401/404/500). Body: WRONG_DATA, PROMO_NOT_FOUND.
|
|
59
59
|
*/
|
|
60
|
-
function all({token, query = {}, headers}) {
|
|
60
|
+
function all({token, jwtToken, query = {}, headers}) {
|
|
61
61
|
return client.get("/promos", {
|
|
62
62
|
params: query,
|
|
63
|
-
headers: authorizationHeaders({token, internalAuthTokenProvider, headers})
|
|
63
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -73,10 +73,10 @@ function promosFactory({client, internalAuthTokenProvider}) {
|
|
|
73
73
|
* @param {Object} [opts.headers] - Optional headers
|
|
74
74
|
* @returns {Promise<import("axios").AxiosResponse>}
|
|
75
75
|
*/
|
|
76
|
-
function get({promoId, token, query = {}, headers}) {
|
|
76
|
+
function get({promoId, token, jwtToken, query = {}, headers}) {
|
|
77
77
|
return client.get(`/promos/${promoId}`, {
|
|
78
78
|
params: query,
|
|
79
|
-
headers: authorizationHeaders({token, internalAuthTokenProvider, headers})
|
|
79
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -7,11 +7,11 @@ const {authorizationHeaders} = require("../endpoints_helpers.js");
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Factory for external-customers API (btrz-api-notifications). Saldo Max (ADO) verification-code registration.
|
|
10
|
+
* Factory for external-customers API (btrz-api-notifications). Saldo Max (ADO) verification-code registration and statement email.
|
|
11
11
|
* @param {Object} deps
|
|
12
12
|
* @param {import("axios").AxiosInstance} deps.client
|
|
13
13
|
* @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
|
|
14
|
-
* @returns {{ requestSaldoMaxVerificationCode: function }}
|
|
14
|
+
* @returns {{ requestSaldoMaxVerificationCode: function, sendSaldoMaxStatementEmail: function }}
|
|
15
15
|
*/
|
|
16
16
|
function externalCustomersFactory({client, internalAuthTokenProvider}) {
|
|
17
17
|
/**
|
|
@@ -33,8 +33,28 @@ function externalCustomersFactory({client, internalAuthTokenProvider}) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* POST /external-customers/ado/external-wallets/:walletId/statements — Request Saldo Max wallet statement email.
|
|
38
|
+
* Notifications proxies to Inventory with sendMail. No query; body is empty JSON.
|
|
39
|
+
* @param {Object} opts
|
|
40
|
+
* @param {string} [opts.token] - API key
|
|
41
|
+
* @param {string} [opts.jwtToken] - JWT (BETTEREZ_APP audience)
|
|
42
|
+
* @param {string} opts.walletId - Saldo Max wallet id (path segment; encoded in the URL)
|
|
43
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
44
|
+
* @returns {Promise<import("axios").AxiosResponse<{ success: boolean }>>}
|
|
45
|
+
*/
|
|
46
|
+
function sendSaldoMaxStatementEmail({token, jwtToken, walletId, headers}) {
|
|
47
|
+
return client({
|
|
48
|
+
url: `/external-customers/ado/external-wallets/${encodeURIComponent(walletId)}/statements`,
|
|
49
|
+
method: "post",
|
|
50
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
|
|
51
|
+
data: {}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
36
55
|
return {
|
|
37
|
-
requestSaldoMaxVerificationCode
|
|
56
|
+
requestSaldoMaxVerificationCode,
|
|
57
|
+
sendSaldoMaxStatementEmail
|
|
38
58
|
};
|
|
39
59
|
}
|
|
40
60
|
|
|
@@ -32,12 +32,33 @@ describe('inventory/promos', function() {
|
|
|
32
32
|
return api.inventory.promos.all({ token });
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
it("should send jwt token when listing promos", function() {
|
|
36
|
+
axiosMock.onGet(`/promos`).reply(expectRequest({
|
|
37
|
+
statusCode: 200,
|
|
38
|
+
token,
|
|
39
|
+
jwtToken,
|
|
40
|
+
requireJwtTokenOnGet: true
|
|
41
|
+
}));
|
|
42
|
+
return api.inventory.promos.all({ token, jwtToken });
|
|
43
|
+
});
|
|
44
|
+
|
|
35
45
|
it("should get single promo", function() {
|
|
36
46
|
axiosMock.onGet(`/promos/${promoId}`).reply(expectRequest({ statusCode: 200, token }));
|
|
37
47
|
const query = {accountId};
|
|
38
48
|
return api.inventory.promos.get({ promoId, accountId, token, query });
|
|
39
49
|
});
|
|
40
50
|
|
|
51
|
+
it("should send jwt token when getting a promo by id", function() {
|
|
52
|
+
axiosMock.onGet(`/promos/${promoId}`).reply(expectRequest({
|
|
53
|
+
statusCode: 200,
|
|
54
|
+
token,
|
|
55
|
+
jwtToken,
|
|
56
|
+
requireJwtTokenOnGet: true
|
|
57
|
+
}));
|
|
58
|
+
const query = {accountId};
|
|
59
|
+
return api.inventory.promos.get({ promoId, accountId, token, jwtToken, query });
|
|
60
|
+
});
|
|
61
|
+
|
|
41
62
|
it("should create new promo", function() {
|
|
42
63
|
axiosMock.onPost(`/promos`).reply(expectRequest({ statusCode: 200, token, jwtToken }));
|
|
43
64
|
return api.inventory.promos.create({ jwtToken, promo, token });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const {axiosMock, expectRequest} = require("./../../test-helpers");
|
|
2
|
-
const api = require("./../../../src/client").createApiClient({baseURL: "http://test.com"});
|
|
1
|
+
const {axiosMock, expectRequest} = require("./../../test-helpers.js");
|
|
2
|
+
const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
|
|
3
3
|
|
|
4
4
|
describe("invoices/invoices", () => {
|
|
5
5
|
const token = "I owe you a token";
|
|
@@ -11,7 +11,7 @@ describe("invoices/invoices", () => {
|
|
|
11
11
|
|
|
12
12
|
it("should list invoices", () => {
|
|
13
13
|
const query = {transactionId: "12312312312312"};
|
|
14
|
-
axiosMock.onGet("/invoices", query).reply(expectRequest({statusCode: 200, token, jwtToken}));
|
|
14
|
+
axiosMock.onGet("/invoices", {params: query}).reply(expectRequest({statusCode: 200, token, jwtToken}));
|
|
15
15
|
return api.invoices.invoices.all({token, jwtToken, query});
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -28,7 +28,7 @@ describe("invoices/invoices", () => {
|
|
|
28
28
|
|
|
29
29
|
it("should list invoices failures", () => {
|
|
30
30
|
const query = {transactionId: "12312312312312"};
|
|
31
|
-
axiosMock.onGet("/failures", query).reply(expectRequest({statusCode: 200, token, jwtToken}));
|
|
31
|
+
axiosMock.onGet("/failures", {params: query}).reply(expectRequest({statusCode: 200, token, jwtToken}));
|
|
32
32
|
return api.invoices.invoices.getInvoicesFailures({token, jwtToken, query});
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -27,4 +27,35 @@ describe("notifications/external-customers", () => {
|
|
|
27
27
|
expect(res.data).to.eql({code: "success", message: "Registration successful"});
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
|
+
|
|
31
|
+
it("should POST Saldo Max statement email (ado/external-wallets/:walletId/statements)", () => {
|
|
32
|
+
const walletId = "15154";
|
|
33
|
+
axiosMock.onPost(`/external-customers/ado/external-wallets/${walletId}/statements`).reply((config) => {
|
|
34
|
+
expect(config.data).to.equal(JSON.stringify({}));
|
|
35
|
+
expect(config.headers["x-api-key"]).to.eql(token);
|
|
36
|
+
expect(config.headers.authorization).to.eql(`Bearer ${jwtToken}`);
|
|
37
|
+
return [200, {success: true}];
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return api.notifications.externalCustomers.sendSaldoMaxStatementEmail({
|
|
41
|
+
token,
|
|
42
|
+
jwtToken,
|
|
43
|
+
walletId
|
|
44
|
+
}).then((res) => {
|
|
45
|
+
expect(res.data).to.eql({success: true});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should encode walletId in statement email path", () => {
|
|
50
|
+
const walletId = "id/with chars";
|
|
51
|
+
axiosMock.onPost("/external-customers/ado/external-wallets/id%2Fwith%20chars/statements").reply(200, {success: true});
|
|
52
|
+
|
|
53
|
+
return api.notifications.externalCustomers.sendSaldoMaxStatementEmail({
|
|
54
|
+
token,
|
|
55
|
+
jwtToken,
|
|
56
|
+
walletId
|
|
57
|
+
}).then((res) => {
|
|
58
|
+
expect(res.data.success).to.equal(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
30
61
|
});
|
|
@@ -31,11 +31,9 @@ describe("sales/cart", () => {
|
|
|
31
31
|
const cartId = "someCartId";
|
|
32
32
|
axiosMock.onDelete(`/cart/${cartId}/items`).reply((request) => {
|
|
33
33
|
expect(request.params).to.eql({operationId: 1234, providerId: 123});
|
|
34
|
-
expect(request.headers).to.eql(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"authorization": "Bearer I owe you a JWT token"
|
|
38
|
-
});
|
|
34
|
+
expect(request.headers.Accept).to.eql("application/json");
|
|
35
|
+
expect(request.headers["x-api-key"]).to.eql("I owe you a token");
|
|
36
|
+
expect(request.headers.authorization).to.eql("Bearer I owe you a JWT token");
|
|
39
37
|
expect(request.method).to.eql("delete");
|
|
40
38
|
expect(request.url).to.eql(`/cart/${cartId}/items`);
|
|
41
39
|
return [200];
|