btrz-api-client 9.28.0 → 9.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.js CHANGED
@@ -1046,6 +1046,10 @@ function createNotifications({
1046
1046
  client,
1047
1047
  internalAuthTokenProvider
1048
1048
  }),
1049
+ operatorNotifications: require("./endpoints/notifications/operator-notifications.js")({
1050
+ client,
1051
+ internalAuthTokenProvider
1052
+ }),
1049
1053
  notify: require("./endpoints/notifications/notify.js")({
1050
1054
  client,
1051
1055
  internalAuthTokenProvider
@@ -48,6 +48,7 @@ const {
48
48
  * @property {boolean} preventMovementsWhenFareSpecificCapacityLimitsAreExceeded - Prevent moves when fare capacity is exceeded.
49
49
  * @property {boolean} sendSMSNotifications - Enable SMS notifications for ticket movements.
50
50
  * @property {boolean} [allowSendingEmailNotification] - Enable email notifications for ticket movements.
51
+ * @property {boolean} [allowSendingWhatsAppNotification] - Enable WhatsApp notifications for bulk ticket movements.
51
52
  * @property {boolean} [useConfirmationRecipientForNotifications] - Send notifications to the confirmation recipient.
52
53
  * @property {number} maxMovementsPerTicket - Maximum ticket movements without authorization.
53
54
  * @property {number} [maxMovementsPerTicketWithAuthorization] - Maximum ticket movements with authorization.
@@ -0,0 +1,170 @@
1
+ const {
2
+ authorizationHeaders
3
+ } = require("./../endpoints_helpers.js");
4
+
5
+ /**
6
+ * Query params for GET /operator-notifications (btrz-api-notifications getSpec).
7
+ * @typedef {Object} OperatorNotificationsListQuery
8
+ * @property {number|string} [page] - Page number for pagination
9
+ */
10
+
11
+ /**
12
+ * Factory for operator-notifications API (btrz-api-notifications).
13
+ * Operator purchase / capacity / SSR notification config documents.
14
+ * @param {Object} deps
15
+ * @param {import("axios").AxiosInstance} deps.client
16
+ * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
17
+ * @returns {Object} operator-notifications API methods
18
+ */
19
+ function operatorNotificationsFactory({
20
+ client,
21
+ internalAuthTokenProvider
22
+ }) {
23
+ /**
24
+ * GET /operator-notifications - list operator notification configs for the account.
25
+ * @param {Object} opts
26
+ * @param {string} [opts.token] - API key
27
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
28
+ * @param {OperatorNotificationsListQuery} [opts.query] - page
29
+ * @param {Object} [opts.headers] - Optional request headers
30
+ * @returns {Promise<import("axios").AxiosResponse>} GetOperatorNotificationsResponse
31
+ */
32
+ function all({
33
+ token,
34
+ jwtToken,
35
+ query = {},
36
+ headers
37
+ }) {
38
+ return client({
39
+ url: "/operator-notifications",
40
+ method: "get",
41
+ headers: authorizationHeaders({
42
+ token,
43
+ jwtToken,
44
+ internalAuthTokenProvider,
45
+ headers
46
+ }),
47
+ params: query
48
+ });
49
+ }
50
+
51
+ /**
52
+ * GET /operator-notifications/:id - get operator notification by id. API does not accept query params.
53
+ * @param {Object} opts
54
+ * @param {string} [opts.token] - API key
55
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
56
+ * @param {string} opts.id - Operator notification id (ObjectId)
57
+ * @param {Object} [opts.headers] - Optional request headers
58
+ * @returns {Promise<import("axios").AxiosResponse>} 404 OPERATOR_NOTIFICATION_NOT_FOUND
59
+ */
60
+ function get({
61
+ token,
62
+ jwtToken,
63
+ id,
64
+ headers
65
+ }) {
66
+ return client({
67
+ url: `/operator-notifications/${id}`,
68
+ method: "get",
69
+ headers: authorizationHeaders({
70
+ token,
71
+ jwtToken,
72
+ internalAuthTokenProvider,
73
+ headers
74
+ })
75
+ });
76
+ }
77
+
78
+ /**
79
+ * POST /operator-notifications - create one document per product. API does not accept query params.
80
+ * @param {Object} opts
81
+ * @param {string} [opts.token] - API key
82
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
83
+ * @param {Object} opts.data - OperatorNotificationCreateData (or {operatorNotification: ...})
84
+ * @param {Object} [opts.headers] - Optional request headers
85
+ * @returns {Promise<import("axios").AxiosResponse>} CreateOperatorNotificationsResponse
86
+ */
87
+ function create({
88
+ token,
89
+ jwtToken,
90
+ data,
91
+ headers
92
+ }) {
93
+ return client({
94
+ url: "/operator-notifications",
95
+ method: "post",
96
+ headers: authorizationHeaders({
97
+ token,
98
+ jwtToken,
99
+ internalAuthTokenProvider,
100
+ headers
101
+ }),
102
+ data
103
+ });
104
+ }
105
+
106
+ /**
107
+ * PUT /operator-notifications/:id - update mutable fields. API does not accept query params.
108
+ * @param {Object} opts
109
+ * @param {string} [opts.token] - API key
110
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
111
+ * @param {string} opts.id - Operator notification id (ObjectId)
112
+ * @param {Object} opts.data - OperatorNotificationUpdateData (or {operatorNotification: ...})
113
+ * @param {Object} [opts.headers] - Optional request headers
114
+ * @returns {Promise<import("axios").AxiosResponse>} 404 OPERATOR_NOTIFICATION_NOT_FOUND
115
+ */
116
+ function update({
117
+ token,
118
+ jwtToken,
119
+ id,
120
+ data,
121
+ headers
122
+ }) {
123
+ return client({
124
+ url: `/operator-notifications/${id}`,
125
+ method: "put",
126
+ headers: authorizationHeaders({
127
+ token,
128
+ jwtToken,
129
+ internalAuthTokenProvider,
130
+ headers
131
+ }),
132
+ data
133
+ });
134
+ }
135
+
136
+ /**
137
+ * DELETE /operator-notifications/:id - hard delete. API does not accept query params.
138
+ * @param {Object} opts
139
+ * @param {string} [opts.token] - API key
140
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
141
+ * @param {string} opts.id - Operator notification id (ObjectId)
142
+ * @param {Object} [opts.headers] - Optional request headers
143
+ * @returns {Promise<import("axios").AxiosResponse>} DeletedOperatorNotificationResponse
144
+ */
145
+ function remove({
146
+ token,
147
+ jwtToken,
148
+ id,
149
+ headers
150
+ }) {
151
+ return client({
152
+ url: `/operator-notifications/${id}`,
153
+ method: "delete",
154
+ headers: authorizationHeaders({
155
+ token,
156
+ jwtToken,
157
+ internalAuthTokenProvider,
158
+ headers
159
+ })
160
+ });
161
+ }
162
+ return {
163
+ all,
164
+ get,
165
+ create,
166
+ update,
167
+ remove
168
+ };
169
+ }
170
+ module.exports = operatorNotificationsFactory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-api-client",
3
- "version": "9.28.0",
3
+ "version": "9.31.0",
4
4
  "description": "Api client for Betterez endpoints",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/client.js CHANGED
@@ -377,6 +377,7 @@ function createNotifications({baseURL, headers, timeout, overrideFn, internalAut
377
377
  twilio: require("./endpoints/notifications/twilio.js")({client, internalAuthTokenProvider}),
378
378
  salesforce: require("./endpoints/notifications/salesforce.js")({client, internalAuthTokenProvider}),
379
379
  shortUrls: require("./endpoints/notifications/short-urls.js")({client, internalAuthTokenProvider}),
380
+ operatorNotifications: require("./endpoints/notifications/operator-notifications.js")({client, internalAuthTokenProvider}),
380
381
  notify: require("./endpoints/notifications/notify.js")({client, internalAuthTokenProvider}),
381
382
  ordersRulesValidations: require("./endpoints/notifications/orders-rules-validations.js")({client, internalAuthTokenProvider}),
382
383
  __test: {
@@ -48,6 +48,7 @@ const {
48
48
  * @property {boolean} preventMovementsWhenFareSpecificCapacityLimitsAreExceeded - Prevent moves when fare capacity is exceeded.
49
49
  * @property {boolean} sendSMSNotifications - Enable SMS notifications for ticket movements.
50
50
  * @property {boolean} [allowSendingEmailNotification] - Enable email notifications for ticket movements.
51
+ * @property {boolean} [allowSendingWhatsAppNotification] - Enable WhatsApp notifications for bulk ticket movements.
51
52
  * @property {boolean} [useConfirmationRecipientForNotifications] - Send notifications to the confirmation recipient.
52
53
  * @property {number} maxMovementsPerTicket - Maximum ticket movements without authorization.
53
54
  * @property {number} [maxMovementsPerTicketWithAuthorization] - Maximum ticket movements with authorization.
@@ -0,0 +1,116 @@
1
+ const {authorizationHeaders} = require("./../endpoints_helpers.js");
2
+
3
+ /**
4
+ * Query params for GET /operator-notifications (btrz-api-notifications getSpec).
5
+ * @typedef {Object} OperatorNotificationsListQuery
6
+ * @property {number|string} [page] - Page number for pagination
7
+ */
8
+
9
+ /**
10
+ * Factory for operator-notifications API (btrz-api-notifications).
11
+ * Operator purchase / capacity / SSR notification config documents.
12
+ * @param {Object} deps
13
+ * @param {import("axios").AxiosInstance} deps.client
14
+ * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
15
+ * @returns {Object} operator-notifications API methods
16
+ */
17
+ function operatorNotificationsFactory({client, internalAuthTokenProvider}) {
18
+ /**
19
+ * GET /operator-notifications - list operator notification configs for the account.
20
+ * @param {Object} opts
21
+ * @param {string} [opts.token] - API key
22
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
23
+ * @param {OperatorNotificationsListQuery} [opts.query] - page
24
+ * @param {Object} [opts.headers] - Optional request headers
25
+ * @returns {Promise<import("axios").AxiosResponse>} GetOperatorNotificationsResponse
26
+ */
27
+ function all({token, jwtToken, query = {}, headers}) {
28
+ return client({
29
+ url: "/operator-notifications",
30
+ method: "get",
31
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
32
+ params: query
33
+ });
34
+ }
35
+
36
+ /**
37
+ * GET /operator-notifications/:id - get operator notification by id. API does not accept query params.
38
+ * @param {Object} opts
39
+ * @param {string} [opts.token] - API key
40
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
41
+ * @param {string} opts.id - Operator notification id (ObjectId)
42
+ * @param {Object} [opts.headers] - Optional request headers
43
+ * @returns {Promise<import("axios").AxiosResponse>} 404 OPERATOR_NOTIFICATION_NOT_FOUND
44
+ */
45
+ function get({token, jwtToken, id, headers}) {
46
+ return client({
47
+ url: `/operator-notifications/${id}`,
48
+ method: "get",
49
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
50
+ });
51
+ }
52
+
53
+ /**
54
+ * POST /operator-notifications - create one document per product. API does not accept query params.
55
+ * @param {Object} opts
56
+ * @param {string} [opts.token] - API key
57
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
58
+ * @param {Object} opts.data - OperatorNotificationCreateData (or {operatorNotification: ...})
59
+ * @param {Object} [opts.headers] - Optional request headers
60
+ * @returns {Promise<import("axios").AxiosResponse>} CreateOperatorNotificationsResponse
61
+ */
62
+ function create({token, jwtToken, data, headers}) {
63
+ return client({
64
+ url: "/operator-notifications",
65
+ method: "post",
66
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
67
+ data
68
+ });
69
+ }
70
+
71
+ /**
72
+ * PUT /operator-notifications/:id - update mutable fields. API does not accept query params.
73
+ * @param {Object} opts
74
+ * @param {string} [opts.token] - API key
75
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
76
+ * @param {string} opts.id - Operator notification id (ObjectId)
77
+ * @param {Object} opts.data - OperatorNotificationUpdateData (or {operatorNotification: ...})
78
+ * @param {Object} [opts.headers] - Optional request headers
79
+ * @returns {Promise<import("axios").AxiosResponse>} 404 OPERATOR_NOTIFICATION_NOT_FOUND
80
+ */
81
+ function update({token, jwtToken, id, data, headers}) {
82
+ return client({
83
+ url: `/operator-notifications/${id}`,
84
+ method: "put",
85
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
86
+ data
87
+ });
88
+ }
89
+
90
+ /**
91
+ * DELETE /operator-notifications/:id - hard delete. API does not accept query params.
92
+ * @param {Object} opts
93
+ * @param {string} [opts.token] - API key
94
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
95
+ * @param {string} opts.id - Operator notification id (ObjectId)
96
+ * @param {Object} [opts.headers] - Optional request headers
97
+ * @returns {Promise<import("axios").AxiosResponse>} DeletedOperatorNotificationResponse
98
+ */
99
+ function remove({token, jwtToken, id, headers}) {
100
+ return client({
101
+ url: `/operator-notifications/${id}`,
102
+ method: "delete",
103
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
104
+ });
105
+ }
106
+
107
+ return {
108
+ all,
109
+ get,
110
+ create,
111
+ update,
112
+ remove
113
+ };
114
+ }
115
+
116
+ module.exports = operatorNotificationsFactory;
package/test/all.test.js CHANGED
@@ -168,6 +168,7 @@ require("./endpoints/notifications/pdfs.test.js");
168
168
  require("./endpoints/notifications/printed-tickets.test.js");
169
169
  require("./endpoints/notifications/salesforce.test.js");
170
170
  require("./endpoints/notifications/short-urls.test.js");
171
+ require("./endpoints/notifications/operator-notifications.test.js");
171
172
  require("./endpoints/notifications/twilio.test.js");
172
173
  require("./endpoints/operations/accounting_items.js");
173
174
  require("./endpoints/operations/applied_insurance.test.js");
@@ -28,6 +28,7 @@ describe("accounts/ticket-movement-settings", () => {
28
28
  preventMovementsWhenFareSpecificCapacityLimitsAreExceeded: true,
29
29
  sendSMSNotifications: true,
30
30
  allowSendingEmailNotification: true,
31
+ allowSendingWhatsAppNotification: false,
31
32
  useConfirmationRecipientForNotifications: false,
32
33
  maxMovementsPerTicket: 1,
33
34
  maxMovementsPerTicketWithAuthorization: 2,
@@ -0,0 +1,82 @@
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("notifications/operator-notifications", () => {
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 a list of operator notifications with query params", () => {
13
+ const query = {page: 1};
14
+ axiosMock.onGet("/operator-notifications").reply(expectRequest({
15
+ statusCode: 200,
16
+ token,
17
+ jwtToken,
18
+ query
19
+ }));
20
+ return api.notifications.operatorNotifications.all({token, jwtToken, query});
21
+ });
22
+
23
+ it("should GET an operator notification by id", () => {
24
+ const id = "5f243d100617680712e78dd7";
25
+ axiosMock.onGet(`/operator-notifications/${id}`).reply(expectRequest({
26
+ statusCode: 200,
27
+ token,
28
+ jwtToken
29
+ }));
30
+ return api.notifications.operatorNotifications.get({token, jwtToken, id});
31
+ });
32
+
33
+ it("should POST create operator notifications", () => {
34
+ const data = {
35
+ operatorNotification: {
36
+ name: "Alert",
37
+ eventType: "purchase",
38
+ systemName: "email",
39
+ products: [{id: "5f243d100617680712e78dd7", name: "Route"}],
40
+ systemValues: {
41
+ senderName: "Ops",
42
+ senderAddress: "ops@example.com",
43
+ recipients: "a@example.com"
44
+ }
45
+ }
46
+ };
47
+ axiosMock.onPost("/operator-notifications").reply(expectRequest({
48
+ statusCode: 200,
49
+ token,
50
+ jwtToken,
51
+ body: data
52
+ }));
53
+ return api.notifications.operatorNotifications.create({token, jwtToken, data});
54
+ });
55
+
56
+ it("should PUT update an operator notification", () => {
57
+ const id = "5f243d100617680712e78dd7";
58
+ const data = {
59
+ operatorNotification: {
60
+ name: "Updated",
61
+ systemValues: {recipients: "b@example.com"}
62
+ }
63
+ };
64
+ axiosMock.onPut(`/operator-notifications/${id}`).reply(expectRequest({
65
+ statusCode: 200,
66
+ token,
67
+ jwtToken,
68
+ body: data
69
+ }));
70
+ return api.notifications.operatorNotifications.update({token, jwtToken, id, data});
71
+ });
72
+
73
+ it("should DELETE an operator notification", () => {
74
+ const id = "5f243d100617680712e78dd7";
75
+ axiosMock.onDelete(`/operator-notifications/${id}`).reply(expectRequest({
76
+ statusCode: 200,
77
+ token,
78
+ jwtToken
79
+ }));
80
+ return api.notifications.operatorNotifications.remove({token, jwtToken, id});
81
+ });
82
+ });
@@ -0,0 +1,44 @@
1
+ export interface OperatorNotificationsListQuery {
2
+ page?: number | string;
3
+ }
4
+
5
+ export interface OperatorNotificationsApi {
6
+ all(opts: {
7
+ token?: string;
8
+ jwtToken?: string;
9
+ query?: OperatorNotificationsListQuery;
10
+ headers?: Record<string, string>;
11
+ }): Promise<import("axios").AxiosResponse>;
12
+ get(opts: {
13
+ token?: string;
14
+ jwtToken?: string;
15
+ id: string;
16
+ headers?: Record<string, string>;
17
+ }): Promise<import("axios").AxiosResponse>;
18
+ create(opts: {
19
+ token?: string;
20
+ jwtToken?: string;
21
+ data: unknown;
22
+ headers?: Record<string, string>;
23
+ }): Promise<import("axios").AxiosResponse>;
24
+ update(opts: {
25
+ token?: string;
26
+ jwtToken?: string;
27
+ id: string;
28
+ data: unknown;
29
+ headers?: Record<string, string>;
30
+ }): Promise<import("axios").AxiosResponse>;
31
+ remove(opts: {
32
+ token?: string;
33
+ jwtToken?: string;
34
+ id: string;
35
+ headers?: Record<string, string>;
36
+ }): Promise<import("axios").AxiosResponse>;
37
+ }
38
+
39
+ declare const operatorNotificationsFactory: (deps: {
40
+ client: import("axios").AxiosInstance;
41
+ internalAuthTokenProvider?: {getToken: () => string};
42
+ }) => OperatorNotificationsApi;
43
+
44
+ export = operatorNotificationsFactory;