btrz-api-client 9.20.0 → 9.21.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 +5 -5
- package/lib/client.js +4 -0
- package/lib/endpoints/accounts/audit-records.js +60 -0
- package/package.json +1 -1
- package/src/client.js +1 -0
- package/src/endpoints/accounts/audit-records.js +45 -0
- package/test/all.test.js +1 -0
- package/test/endpoints/accounts/audit-records.test.js +54 -0
- package/types/endpoints/accounts/audit-records.d.ts +16 -0
package/lib/client.js
CHANGED
|
@@ -501,6 +501,10 @@ function createAccounts({
|
|
|
501
501
|
client,
|
|
502
502
|
internalAuthTokenProvider
|
|
503
503
|
}),
|
|
504
|
+
auditRecords: require("./endpoints/accounts/audit-records.js")({
|
|
505
|
+
client,
|
|
506
|
+
internalAuthTokenProvider
|
|
507
|
+
}),
|
|
504
508
|
application: require("./endpoints/accounts/application.js")({
|
|
505
509
|
client,
|
|
506
510
|
internalAuthTokenProvider
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const {
|
|
2
|
+
authorizationHeaders
|
|
3
|
+
} = require("./../endpoints_helpers.js");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Factory for audit-records API (btrz-api-accounts).
|
|
7
|
+
* @param {Object} deps
|
|
8
|
+
* @param {import("axios").AxiosInstance} deps.client
|
|
9
|
+
* @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
|
|
10
|
+
* @returns {{ get: function }}
|
|
11
|
+
*/
|
|
12
|
+
function auditRecordsFactory({
|
|
13
|
+
client,
|
|
14
|
+
internalAuthTokenProvider
|
|
15
|
+
}) {
|
|
16
|
+
/**
|
|
17
|
+
* GET /audit-records/:providerId/:folder/:itemId – get audit events for one object.
|
|
18
|
+
* Requires BETTEREZ_APP JWT. No query params.
|
|
19
|
+
* @param {Object} opts
|
|
20
|
+
* @param {string} [opts.token] - API key
|
|
21
|
+
* @param {string} [opts.jwtToken] - JWT or internal auth symbol
|
|
22
|
+
* @param {string} opts.providerId - Account (provider) ID
|
|
23
|
+
* @param {string} opts.folder - Audit folder / entity name
|
|
24
|
+
* @param {string} opts.itemId - Audited object ID
|
|
25
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
26
|
+
* @returns {Promise<import("axios").AxiosResponse<{
|
|
27
|
+
* accountId: string,
|
|
28
|
+
* folder: string,
|
|
29
|
+
* objectId: string,
|
|
30
|
+
* events: Array<{
|
|
31
|
+
* ts: string,
|
|
32
|
+
* userId: string,
|
|
33
|
+
* operation: string,
|
|
34
|
+
* changes: Array<{path: string, from: *, to: *}>
|
|
35
|
+
* }>
|
|
36
|
+
* }>>}
|
|
37
|
+
*/
|
|
38
|
+
function get({
|
|
39
|
+
token,
|
|
40
|
+
jwtToken,
|
|
41
|
+
providerId,
|
|
42
|
+
folder,
|
|
43
|
+
itemId,
|
|
44
|
+
headers
|
|
45
|
+
}) {
|
|
46
|
+
return client({
|
|
47
|
+
url: `/audit-records/${providerId}/${folder}/${itemId}`,
|
|
48
|
+
headers: authorizationHeaders({
|
|
49
|
+
token,
|
|
50
|
+
jwtToken,
|
|
51
|
+
internalAuthTokenProvider,
|
|
52
|
+
headers
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
get
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
module.exports = auditRecordsFactory;
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -189,6 +189,7 @@ function createAccounts({baseURL, headers, timeout, overrideFn, internalAuthToke
|
|
|
189
189
|
agencies: require("./endpoints/accounts/agencies.js")({client, internalAuthTokenProvider}),
|
|
190
190
|
agencyTypes: require("./endpoints/accounts/agency-types.js")({client, internalAuthTokenProvider}),
|
|
191
191
|
authorizedExternalMessaging: require("./endpoints/accounts/authorized-external-messaging.js")({client, internalAuthTokenProvider}),
|
|
192
|
+
auditRecords: require("./endpoints/accounts/audit-records.js")({client, internalAuthTokenProvider}),
|
|
192
193
|
application: require("./endpoints/accounts/application.js")({client, internalAuthTokenProvider}),
|
|
193
194
|
applications: require("./endpoints/accounts/applications.js")({client, internalAuthTokenProvider}),
|
|
194
195
|
applicationSettings: require("./endpoints/accounts/application-settings.js")({client, internalAuthTokenProvider}),
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const {authorizationHeaders} = require("./../endpoints_helpers.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Factory for audit-records API (btrz-api-accounts).
|
|
5
|
+
* @param {Object} deps
|
|
6
|
+
* @param {import("axios").AxiosInstance} deps.client
|
|
7
|
+
* @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
|
|
8
|
+
* @returns {{ get: function }}
|
|
9
|
+
*/
|
|
10
|
+
function auditRecordsFactory({client, internalAuthTokenProvider}) {
|
|
11
|
+
/**
|
|
12
|
+
* GET /audit-records/:providerId/:folder/:itemId – get audit events for one object.
|
|
13
|
+
* Requires BETTEREZ_APP JWT. No query params.
|
|
14
|
+
* @param {Object} opts
|
|
15
|
+
* @param {string} [opts.token] - API key
|
|
16
|
+
* @param {string} [opts.jwtToken] - JWT or internal auth symbol
|
|
17
|
+
* @param {string} opts.providerId - Account (provider) ID
|
|
18
|
+
* @param {string} opts.folder - Audit folder / entity name
|
|
19
|
+
* @param {string} opts.itemId - Audited object ID
|
|
20
|
+
* @param {Object} [opts.headers] - Optional headers
|
|
21
|
+
* @returns {Promise<import("axios").AxiosResponse<{
|
|
22
|
+
* accountId: string,
|
|
23
|
+
* folder: string,
|
|
24
|
+
* objectId: string,
|
|
25
|
+
* events: Array<{
|
|
26
|
+
* ts: string,
|
|
27
|
+
* userId: string,
|
|
28
|
+
* operation: string,
|
|
29
|
+
* changes: Array<{path: string, from: *, to: *}>
|
|
30
|
+
* }>
|
|
31
|
+
* }>>}
|
|
32
|
+
*/
|
|
33
|
+
function get({token, jwtToken, providerId, folder, itemId, headers}) {
|
|
34
|
+
return client({
|
|
35
|
+
url: `/audit-records/${providerId}/${folder}/${itemId}`,
|
|
36
|
+
headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
get
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = auditRecordsFactory;
|
package/test/all.test.js
CHANGED
|
@@ -5,6 +5,7 @@ require("./endpoints/accounts/accounts.js");
|
|
|
5
5
|
require("./endpoints/accounts/agencies.test.js");
|
|
6
6
|
require("./endpoints/accounts/agency-types.test.js");
|
|
7
7
|
require("./endpoints/accounts/application-settings.test.js");
|
|
8
|
+
require("./endpoints/accounts/audit-records.test.js");
|
|
8
9
|
require("./endpoints/accounts/applications.test.js");
|
|
9
10
|
require("./endpoints/accounts/current-shifts.test.js");
|
|
10
11
|
require("./endpoints/accounts/customers.js");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const assert = require("node:assert/strict");
|
|
2
|
+
const {axiosMock, expectRequest} = require("./../../test-helpers.js");
|
|
3
|
+
const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
|
|
4
|
+
|
|
5
|
+
describe("accounts/audit-records", () => {
|
|
6
|
+
const token = "I owe you a token";
|
|
7
|
+
const jwtToken = "secret";
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
axiosMock.reset();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should GET audit records by providerId, folder, and itemId", () => {
|
|
14
|
+
const providerId = "507f1f77bcf86cd799439011";
|
|
15
|
+
const folder = "fares";
|
|
16
|
+
const itemId = "64f1aaaaaaaaaaaaaaaaaaaa";
|
|
17
|
+
const auditRecord = {
|
|
18
|
+
accountId: providerId,
|
|
19
|
+
folder,
|
|
20
|
+
objectId: itemId,
|
|
21
|
+
events: [{
|
|
22
|
+
ts: "2026-08-14T08:03:12.123Z",
|
|
23
|
+
userId: "user-1",
|
|
24
|
+
operation: "update",
|
|
25
|
+
changes: [{path: "name", from: "A", to: "B"}]
|
|
26
|
+
}]
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
axiosMock.onGet(`/audit-records/${providerId}/${folder}/${itemId}`)
|
|
30
|
+
.reply((config) => {
|
|
31
|
+
const result = expectRequest({
|
|
32
|
+
statusCode: 200,
|
|
33
|
+
token,
|
|
34
|
+
jwtToken,
|
|
35
|
+
requireJwtTokenOnGet: true
|
|
36
|
+
})(config);
|
|
37
|
+
if (result[0] !== 200) {
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
return [200, auditRecord];
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return api.accounts.auditRecords.get({
|
|
44
|
+
token,
|
|
45
|
+
jwtToken,
|
|
46
|
+
providerId,
|
|
47
|
+
folder,
|
|
48
|
+
itemId
|
|
49
|
+
}).then((res) => {
|
|
50
|
+
assert.deepStrictEqual(res.status, 200);
|
|
51
|
+
assert.deepStrictEqual(res.data, auditRecord);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export = auditRecordsFactory;
|
|
2
|
+
/**
|
|
3
|
+
* Factory for audit-records API (btrz-api-accounts).
|
|
4
|
+
* @param {Object} deps
|
|
5
|
+
* @param {import("axios").AxiosInstance} deps.client
|
|
6
|
+
* @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
|
|
7
|
+
* @returns {{ get: function }}
|
|
8
|
+
*/
|
|
9
|
+
declare function auditRecordsFactory({ client, internalAuthTokenProvider }: {
|
|
10
|
+
client: import("axios").AxiosInstance;
|
|
11
|
+
internalAuthTokenProvider?: {
|
|
12
|
+
getToken: () => string;
|
|
13
|
+
};
|
|
14
|
+
}): {
|
|
15
|
+
get: Function;
|
|
16
|
+
};
|