btrz-api-client 8.31.0 → 8.33.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.
Files changed (93) hide show
  1. package/.cursor/rules/jsdoc-endpoints.mdc +1 -1
  2. package/lib/client-standalone-min.js +3 -3
  3. package/lib/client.js +5 -0
  4. package/lib/endpoints/accounts/agencies.js +52 -0
  5. package/lib/endpoints/accounts/application-settings.js +19 -18
  6. package/lib/endpoints/accounts/applications.js +8 -7
  7. package/lib/endpoints/accounts/customers.js +27 -24
  8. package/lib/endpoints/accounts/domains.js +16 -11
  9. package/lib/endpoints/accounts/email-settings.js +22 -18
  10. package/lib/endpoints/accounts/email-templates.js +8 -4
  11. package/lib/endpoints/accounts/exchange-rates.js +12 -7
  12. package/lib/endpoints/accounts/exchange-receipts.js +10 -6
  13. package/lib/endpoints/accounts/external-customers.js +50 -0
  14. package/lib/endpoints/accounts/goal-settings.js +8 -6
  15. package/lib/endpoints/accounts/images.js +14 -13
  16. package/lib/endpoints/accounts/interline.js +35 -27
  17. package/lib/endpoints/accounts/journey-prices-settings.js +8 -6
  18. package/lib/endpoints/accounts/lexicons.js +13 -13
  19. package/lib/endpoints/accounts/market-pricing-settings.js +7 -6
  20. package/lib/endpoints/accounts/multiproduct-sales-settings.js +7 -6
  21. package/lib/endpoints/accounts/network.js +28 -13
  22. package/lib/endpoints/accounts/operation-settings.js +8 -6
  23. package/lib/endpoints/accounts/people-lookups.js +17 -17
  24. package/lib/endpoints/accounts/point-to-point-settings.js +6 -6
  25. package/lib/endpoints/accounts/print-settings.js +9 -6
  26. package/lib/endpoints/accounts/print-templates.js +37 -21
  27. package/lib/endpoints/accounts/printers.js +10 -4
  28. package/lib/endpoints/accounts/rms-settings.js +19 -11
  29. package/lib/endpoints/accounts/salesforce-settings.js +8 -6
  30. package/lib/endpoints/accounts/shift-settings.js +7 -6
  31. package/lib/endpoints/accounts/shifts.js +13 -9
  32. package/lib/endpoints/accounts/sms-templates.js +28 -19
  33. package/lib/endpoints/accounts/sub-print-templates.js +5 -3
  34. package/lib/endpoints/accounts/ticket-movement-settings.js +8 -5
  35. package/lib/endpoints/accounts/travellers.js +18 -12
  36. package/lib/endpoints/accounts/trusted-machines.js +11 -8
  37. package/lib/endpoints/accounts/twilio-settings.js +8 -5
  38. package/lib/endpoints/accounts/users.js +105 -63
  39. package/lib/endpoints/accounts/verified-emails.js +130 -0
  40. package/lib/endpoints/accounts/websales-config.js +7 -5
  41. package/lib/endpoints/coltrane/healthcheck.js +35 -0
  42. package/lib/endpoints/coltrane/info.js +35 -0
  43. package/lib/endpoints/coltrane/paths.js +17 -13
  44. package/package.json +1 -1
  45. package/src/client.js +5 -0
  46. package/src/endpoints/accounts/agencies.js +40 -0
  47. package/src/endpoints/accounts/application-settings.js +19 -18
  48. package/src/endpoints/accounts/applications.js +8 -7
  49. package/src/endpoints/accounts/customers.js +27 -24
  50. package/src/endpoints/accounts/domains.js +16 -11
  51. package/src/endpoints/accounts/email-settings.js +22 -18
  52. package/src/endpoints/accounts/email-templates.js +8 -4
  53. package/src/endpoints/accounts/exchange-rates.js +12 -7
  54. package/src/endpoints/accounts/exchange-receipts.js +10 -6
  55. package/src/endpoints/accounts/external-customers.js +37 -0
  56. package/src/endpoints/accounts/goal-settings.js +8 -6
  57. package/src/endpoints/accounts/images.js +14 -13
  58. package/src/endpoints/accounts/interline.js +35 -28
  59. package/src/endpoints/accounts/journey-prices-settings.js +8 -6
  60. package/src/endpoints/accounts/lexicons.js +13 -13
  61. package/src/endpoints/accounts/market-pricing-settings.js +7 -6
  62. package/src/endpoints/accounts/multiproduct-sales-settings.js +7 -6
  63. package/src/endpoints/accounts/network.js +28 -14
  64. package/src/endpoints/accounts/operation-settings.js +8 -6
  65. package/src/endpoints/accounts/people-lookups.js +17 -17
  66. package/src/endpoints/accounts/point-to-point-settings.js +6 -6
  67. package/src/endpoints/accounts/print-settings.js +9 -7
  68. package/src/endpoints/accounts/print-templates.js +31 -19
  69. package/src/endpoints/accounts/printers.js +10 -5
  70. package/src/endpoints/accounts/rms-settings.js +19 -11
  71. package/src/endpoints/accounts/salesforce-settings.js +8 -6
  72. package/src/endpoints/accounts/shift-settings.js +7 -6
  73. package/src/endpoints/accounts/shifts.js +13 -9
  74. package/src/endpoints/accounts/sms-templates.js +28 -19
  75. package/src/endpoints/accounts/sub-print-templates.js +5 -3
  76. package/src/endpoints/accounts/ticket-movement-settings.js +8 -5
  77. package/src/endpoints/accounts/travellers.js +18 -12
  78. package/src/endpoints/accounts/trusted-machines.js +11 -8
  79. package/src/endpoints/accounts/twilio-settings.js +8 -5
  80. package/src/endpoints/accounts/users.js +42 -5
  81. package/src/endpoints/accounts/verified-emails.js +100 -0
  82. package/src/endpoints/accounts/websales-config.js +7 -5
  83. package/src/endpoints/coltrane/healthcheck.js +28 -0
  84. package/src/endpoints/coltrane/info.js +28 -0
  85. package/src/endpoints/coltrane/paths.js +17 -13
  86. package/test/endpoints/accounts/agencies.test.js +58 -0
  87. package/test/endpoints/accounts/external-customers.test.js +62 -0
  88. package/test/endpoints/accounts/users.js +10 -0
  89. package/test/endpoints/accounts/verified-emails.test.js +35 -0
  90. package/test/endpoints/coltrane/healthcheck.test.js +13 -0
  91. package/test/endpoints/coltrane/info.test.js +13 -0
  92. package/types/endpoints/accounts/users.d.ts +2 -1
  93. package/types/endpoints/accounts/verified-emails.d.ts +19 -0
@@ -0,0 +1,28 @@
1
+ /* eslint-disable max-len */
2
+ /**
3
+ * Factory for Coltrane info API (btrz-api-coltrane) — service and dependency status.
4
+ * @param {Object} deps
5
+ * @param {import("axios").AxiosInstance} deps.client
6
+ * @returns {{ get: function }}
7
+ */
8
+ function infoFactory({client}) {
9
+ /**
10
+ * GET /info — get Coltrane API service status and dependency health. No authentication required.
11
+ * @param {Object} [opts]
12
+ * @param {Object} [opts.headers] - Optional request headers
13
+ * @returns {Promise<import("axios").AxiosResponse<{ data: { status: number, services: Array<{ name: string, status: number }>, build?: string, instanceId?: string, commit?: string } }>>}
14
+ * @throws {import("axios").AxiosError} 500 Internal server error or dependency check failure
15
+ */
16
+ function get({headers} = {}) {
17
+ return client({
18
+ url: "/info",
19
+ headers: headers || {}
20
+ });
21
+ }
22
+
23
+ return {
24
+ get
25
+ };
26
+ }
27
+
28
+ module.exports = infoFactory;
@@ -2,15 +2,16 @@
2
2
  const {authorizationHeaders} = require("./../endpoints_helpers.js");
3
3
 
4
4
  /**
5
- * Query params for GET /paths (btrz-api-coltrane). See get-paths getSpec().
5
+ * Query params for GET /paths (btrz-api-coltrane). All except metrics and preferredAlgorithm are required by the API.
6
6
  * @typedef {Object} ColtranePathsListQuery
7
- * @property {string} [providerId] - Account ID of the travel provider (required by API)
8
- * @property {string} [productId] - Product ID belonging to the provider (required by API)
9
- * @property {string} [originId] - Origin station id (required by API)
10
- * @property {string} [destinationId] - Destination station id (required by API)
11
- * @property {string} [departureFromDate] - Start of search interval; ISO 8601 (e.g. 2021-10-07T17:30:00.000-0400)
12
- * @property {string} [departureToDate] - End of search interval; ISO 8601; interval max 25h
13
- * @property {string} [metrics] - If true, response includes metrics (debugging)
7
+ * @property {string} [providerId] - Account ID of the travel provider (24-char hex)
8
+ * @property {string} [productId] - Product ID belonging to the provider (24-char hex)
9
+ * @property {string} [originId] - Origin station ID (24-char hex); must differ from destinationId
10
+ * @property {string} [destinationId] - Destination station ID (24-char hex)
11
+ * @property {string} [departureFromDate] - Start of departure interval; ISO 8601 (e.g. 2021-10-07T17:30:00.000-0400)
12
+ * @property {string} [departureToDate] - End of departure interval; ISO 8601; interval max 25h, must be after departureFromDate
13
+ * @property {string} [preferredAlgorithm] - "search_algorithm_fast" or "search_algorithm_exhaustive"
14
+ * @property {string|boolean} [metrics] - If true, response includes metrics object (debugging)
14
15
  */
15
16
 
16
17
  /**
@@ -22,12 +23,15 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
22
23
  */
23
24
  function coltraneFactory({client, internalAuthTokenProvider}) {
24
25
  /**
25
- * GET /paths - list Coltrane paths.
26
+ * GET /paths search for travel paths between two stations in a departure time interval.
26
27
  * @param {Object} opts
27
- * @param {string} [opts.token] - API key
28
- * @param {ColtranePathsListQuery} [opts.query] - Query params (providerId, productId, originId, destinationId, etc.)
29
- * @param {Object} [opts.headers] - Optional headers
30
- * @returns {Promise<import("axios").AxiosResponse>}
28
+ * @param {string} [opts.token] - API key (X-API-KEY)
29
+ * @param {ColtranePathsListQuery} [opts.query] - Query params; providerId, productId, originId, destinationId, departureFromDate, departureToDate required
30
+ * @param {Object} [opts.headers] - Optional request headers
31
+ * @returns {Promise<import("axios").AxiosResponse<{ data: { paths: Array<{ segments: Array<{ scheduleId: string, manifestDay: string, fromLegIndex: number, toLegIndex: number }> }>, metrics?: object } }>>}
32
+ * @throws {import("axios").AxiosError} 400 INVALID_QUERY_PARAMETERS (invalid params, originId=destinationId, interval &gt; 25h, or invalid preferredAlgorithm)
33
+ * @throws {import("axios").AxiosError} 401 Unauthorized
34
+ * @throws {import("axios").AxiosError} 500 Internal server error
31
35
  */
32
36
  function all({token, query = {}, headers}) {
33
37
  return client({
@@ -0,0 +1,58 @@
1
+ const {
2
+ axiosMock,
3
+ expectRequest
4
+ } = require("./../../test-helpers.js");
5
+ const api = require("./../../../src/client.js").createApiClient({
6
+ baseURL: "http://test.com"
7
+ });
8
+
9
+ describe("accounts/agencies", () => {
10
+ const jwtToken = "I owe you a JWT token";
11
+ const token = "I owe you a token";
12
+
13
+ afterEach(() => {
14
+ axiosMock.reset();
15
+ });
16
+
17
+ it("should PUT credit limit for an agency", () => {
18
+ const agencyId = "507f1f77bcf86cd799439011";
19
+ const data = {
20
+ limitAmount: 1000,
21
+ unlimited: false
22
+ };
23
+ axiosMock.onPut(`/agencies/${agencyId}/credit-limit`).reply(expectRequest({
24
+ statusCode: 200,
25
+ token,
26
+ jwtToken,
27
+ body: data
28
+ }));
29
+ return api.accounts.agencies.putCreditLimit({
30
+ token,
31
+ jwtToken,
32
+ agencyId,
33
+ data
34
+ });
35
+ });
36
+
37
+ it("should PUT credit limit with wrapped creditLimit body", () => {
38
+ const agencyId = "507f1f77bcf86cd799439012";
39
+ const data = {
40
+ creditLimit: {
41
+ limitAmount: 2000,
42
+ unlimited: true
43
+ }
44
+ };
45
+ axiosMock.onPut(`/agencies/${agencyId}/credit-limit`).reply(expectRequest({
46
+ statusCode: 200,
47
+ token,
48
+ jwtToken,
49
+ body: data
50
+ }));
51
+ return api.accounts.agencies.putCreditLimit({
52
+ token,
53
+ jwtToken,
54
+ agencyId,
55
+ data
56
+ });
57
+ });
58
+ });
@@ -0,0 +1,62 @@
1
+ const {
2
+ axiosMock,
3
+ expectRequest
4
+ } = require("./../../test-helpers.js");
5
+ const api = require("./../../../src/client.js").createApiClient({
6
+ baseURL: "http://test.com"
7
+ });
8
+
9
+ describe("accounts/external-customers", () => {
10
+ const jwtToken = "I owe you a JWT token";
11
+ const token = "I owe you a token";
12
+
13
+ afterEach(() => {
14
+ axiosMock.reset();
15
+ });
16
+
17
+ it("should POST Saldo Max registration (external-customers/ado)", () => {
18
+ const data = {
19
+ firstName: "TestName",
20
+ lastName: "TestLastName",
21
+ email: "test@betterez.com",
22
+ password: "YmFzZTY0cGFzc3dvcmQ=",
23
+ verificationCode: "689411",
24
+ isoCode: "AR"
25
+ };
26
+ axiosMock.onPost("/external-customers/ado").reply(expectRequest({
27
+ statusCode: 201,
28
+ token,
29
+ jwtToken,
30
+ body: data
31
+ }));
32
+ return api.accounts.externalCustomers.registerSaldoMax({
33
+ token,
34
+ jwtToken,
35
+ data
36
+ });
37
+ });
38
+
39
+ it("should POST with body wrapper when using body key", () => {
40
+ const data = {
41
+ body: {
42
+ firstName: "A",
43
+ lastName: "B",
44
+ email: "a@b.com",
45
+ password: "cGFzcw==",
46
+ verificationCode: "123",
47
+ isoCode: "MX"
48
+ }
49
+ };
50
+ const withoutApiKey = true;
51
+ axiosMock.onPost("/external-customers/ado").reply(expectRequest({
52
+ statusCode: 201,
53
+ jwtToken,
54
+ withoutApiKey,
55
+ body: data
56
+ }));
57
+ return api.accounts.externalCustomers.registerSaldoMax({
58
+ jwtToken,
59
+ data
60
+ });
61
+ });
62
+ });
@@ -61,6 +61,16 @@ describe("accounts/user/{id}", () => {
61
61
  });
62
62
  });
63
63
 
64
+ it("should delete a user", () => {
65
+ const userId = "627a25404a761f0fcbdbdfc1";
66
+ axiosMock.onDelete(`/users/${userId}`).reply(expectRequest({statusCode: 204, token, jwtToken}));
67
+ return api.accounts.users.delete({
68
+ jwtToken,
69
+ token,
70
+ id: userId
71
+ });
72
+ });
73
+
64
74
  it("should create a user", () => {
65
75
  const user = {
66
76
  firstName: "Jane",
@@ -0,0 +1,35 @@
1
+ const {axiosMock, expectRequest} = require("./../../test-helpers.js");
2
+ const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("accounts/verified-emails", () => {
5
+ const token = "someToken";
6
+ const jwtToken = "I owe you a JWT token";
7
+
8
+ afterEach(() => {
9
+ axiosMock.restore();
10
+ });
11
+
12
+ it("should get all verified emails", () => {
13
+ const query = {page: 1, pageSize: 20};
14
+ axiosMock.onGet("/verified-emails").reply(expectRequest({statusCode: 200, token, jwtToken, query}));
15
+ return api.accounts.verifiedEmails.all({token, jwtToken, query});
16
+ });
17
+
18
+ it("should get verified email by email address", () => {
19
+ const email = "user@example.com";
20
+ axiosMock.onGet(`/verified-emails/${encodeURIComponent(email)}`).reply(expectRequest({statusCode: 200, token, jwtToken}));
21
+ return api.accounts.verifiedEmails.get({token, jwtToken, email});
22
+ });
23
+ it("should create a verified email", () => {
24
+ const data = {email: "test@example.com", status: "WHITELISTED"};
25
+ axiosMock.onPost("/verified-emails").reply(expectRequest({statusCode: 200, token, jwtToken, body: data}));
26
+ return api.accounts.verifiedEmails.create({token, jwtToken, data});
27
+ });
28
+
29
+ it("should update a verified email", () => {
30
+ const email = "user@example.com";
31
+ const data = {status: "BLACKLISTED"};
32
+ axiosMock.onPut(`/verified-emails/${encodeURIComponent(email)}`).reply(expectRequest({statusCode: 200, token, jwtToken, body: data}));
33
+ return api.accounts.verifiedEmails.update({token, jwtToken, email, data});
34
+ });
35
+ });
@@ -0,0 +1,13 @@
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("coltrane/healthcheck", () => {
5
+ afterEach(() => {
6
+ axiosMock.reset();
7
+ });
8
+
9
+ it("should get healthcheck (liveness)", () => {
10
+ axiosMock.onGet("/healthcheck").reply(expectRequest({statusCode: 200, withoutApiKey: true}));
11
+ return api.coltrane.healthcheck.get();
12
+ });
13
+ });
@@ -0,0 +1,13 @@
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("coltrane/info", () => {
5
+ afterEach(() => {
6
+ axiosMock.reset();
7
+ });
8
+
9
+ it("should get Coltrane service info (status and dependencies)", () => {
10
+ axiosMock.onGet("/info").reply(expectRequest({statusCode: 200, withoutApiKey: true}));
11
+ return api.coltrane.info.get();
12
+ });
13
+ });
@@ -4,7 +4,7 @@ export = usersFactory;
4
4
  * @param {Object} deps
5
5
  * @param {import("axios").AxiosInstance} deps.client
6
6
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
7
- * @returns {{ get: function, getV2: function, all: function, create: function, login: function, update: function, createOrUpdateMany: function, impersonate: function, startMfa: function, confirmMfa: function, disableMfa: function, sequences: { get: function, all: function, create: function, update: function, transfer: function } }}
7
+ * @returns {{ get: function, getV2: function, all: function, create: function, login: function, update: function, delete: function, createOrUpdateMany: function, impersonate: function, startMfa: function, confirmMfa: function, disableMfa: function, sequences: { get: function, all: function, create: function, update: function, transfer: function } }}
8
8
  */
9
9
  declare function usersFactory({ client, internalAuthTokenProvider }: {
10
10
  client: import("axios").AxiosInstance;
@@ -18,6 +18,7 @@ declare function usersFactory({ client, internalAuthTokenProvider }: {
18
18
  create: Function;
19
19
  login: Function;
20
20
  update: Function;
21
+ delete: Function;
21
22
  createOrUpdateMany: Function;
22
23
  impersonate: Function;
23
24
  startMfa: Function;
@@ -0,0 +1,19 @@
1
+ export = verifiedEmailsFactory;
2
+ /**
3
+ * Factory for verified-emails API (btrz-api-accounts).
4
+ * @param {Object} deps
5
+ * @param {import("axios").AxiosInstance} deps.client
6
+ * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
7
+ * @returns {{ all: function, get: function, create: function, update: function }}
8
+ */
9
+ declare function verifiedEmailsFactory({ client, internalAuthTokenProvider }: {
10
+ client: import("axios").AxiosInstance;
11
+ internalAuthTokenProvider?: {
12
+ getToken: () => string;
13
+ };
14
+ }): {
15
+ all: Function;
16
+ get: Function;
17
+ create: Function;
18
+ update: Function;
19
+ };