btrz-api-client 9.20.0 → 9.22.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/lib/endpoints/notifications/notify.js +3 -7
- package/package.json +1 -1
- package/src/client.js +1 -0
- package/src/endpoints/accounts/audit-records.js +45 -0
- package/src/endpoints/notifications/notify.js +3 -7
- 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;
|
|
@@ -32,12 +32,8 @@ const {
|
|
|
32
32
|
* @typedef {Object} NotifyWhatsappPostData
|
|
33
33
|
* @property {string} type - Document/template type (e.g. product, voucher, order)
|
|
34
34
|
* @property {string} itemId - ObjectId of the item (24-char hex)
|
|
35
|
-
* @property {string} [templateType] - Accounts template type when it differs from `type` (same enum as GET /sms-templates/types). Twilio only: the Salesforce branch uses the Meta approved template referenced by the account `waDefinitionKey`
|
|
36
35
|
* @property {string} [to] - Recipient phone (E.164). Optional; derived from item when omitted. The Salesforce branch only supports Mexican numbers with the 52 country code (12 digits starting with 52)
|
|
37
|
-
* @property {string} [lang] - ISO language code. Twilio only: used for template selection
|
|
38
|
-
* @property {string} [channel] - Channel filter for template selection. Twilio only
|
|
39
36
|
* @property {string} [family] - Required when type is 'product'. One of: ticket, reservation, paid in, paid out, parcel, flexpass, bundle
|
|
40
|
-
* @property {string} [humanDate] - "mm" | "dd". Twilio only
|
|
41
37
|
*/
|
|
42
38
|
|
|
43
39
|
/**
|
|
@@ -337,12 +333,12 @@ function notifyTicketFactory({
|
|
|
337
333
|
whatsapp: {
|
|
338
334
|
/**
|
|
339
335
|
* POST /notify/whatsapp - sends WhatsApp notification specifying document type and id
|
|
340
|
-
* Uses the account's WhatsApp provider: for
|
|
341
|
-
*
|
|
336
|
+
* Uses the account's WhatsApp provider: for Salesforce it uses a Meta approved WhatsApp template
|
|
337
|
+
* configured via `waDefinitionKey` in the account.
|
|
342
338
|
* @param {Object} opts
|
|
343
339
|
* @param {string} [opts.token] - API key
|
|
344
340
|
* @param {string} [opts.jwtToken] - JWT or internal auth symbol
|
|
345
|
-
* @param {NotifyWhatsappPostData} opts.data - Request body (type, itemId; optional
|
|
341
|
+
* @param {NotifyWhatsappPostData} opts.data - Request body (type, itemId; optional to, family)
|
|
346
342
|
* @param {Object} [opts.headers] - Optional headers
|
|
347
343
|
* @returns {Promise<import("axios").AxiosResponse<{ success: boolean }>>}
|
|
348
344
|
*/
|
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;
|
|
@@ -32,12 +32,8 @@ const {
|
|
|
32
32
|
* @typedef {Object} NotifyWhatsappPostData
|
|
33
33
|
* @property {string} type - Document/template type (e.g. product, voucher, order)
|
|
34
34
|
* @property {string} itemId - ObjectId of the item (24-char hex)
|
|
35
|
-
* @property {string} [templateType] - Accounts template type when it differs from `type` (same enum as GET /sms-templates/types). Twilio only: the Salesforce branch uses the Meta approved template referenced by the account `waDefinitionKey`
|
|
36
35
|
* @property {string} [to] - Recipient phone (E.164). Optional; derived from item when omitted. The Salesforce branch only supports Mexican numbers with the 52 country code (12 digits starting with 52)
|
|
37
|
-
* @property {string} [lang] - ISO language code. Twilio only: used for template selection
|
|
38
|
-
* @property {string} [channel] - Channel filter for template selection. Twilio only
|
|
39
36
|
* @property {string} [family] - Required when type is 'product'. One of: ticket, reservation, paid in, paid out, parcel, flexpass, bundle
|
|
40
|
-
* @property {string} [humanDate] - "mm" | "dd". Twilio only
|
|
41
37
|
*/
|
|
42
38
|
|
|
43
39
|
/**
|
|
@@ -247,12 +243,12 @@ function notifyTicketFactory({
|
|
|
247
243
|
whatsapp: {
|
|
248
244
|
/**
|
|
249
245
|
* POST /notify/whatsapp - sends WhatsApp notification specifying document type and id
|
|
250
|
-
* Uses the account's WhatsApp provider: for
|
|
251
|
-
*
|
|
246
|
+
* Uses the account's WhatsApp provider: for Salesforce it uses a Meta approved WhatsApp template
|
|
247
|
+
* configured via `waDefinitionKey` in the account.
|
|
252
248
|
* @param {Object} opts
|
|
253
249
|
* @param {string} [opts.token] - API key
|
|
254
250
|
* @param {string} [opts.jwtToken] - JWT or internal auth symbol
|
|
255
|
-
* @param {NotifyWhatsappPostData} opts.data - Request body (type, itemId; optional
|
|
251
|
+
* @param {NotifyWhatsappPostData} opts.data - Request body (type, itemId; optional to, family)
|
|
256
252
|
* @param {Object} [opts.headers] - Optional headers
|
|
257
253
|
* @returns {Promise<import("axios").AxiosResponse<{ success: boolean }>>}
|
|
258
254
|
*/
|
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
|
+
};
|