btrz-api-client 9.26.0 → 9.28.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.
@@ -127,6 +127,7 @@ const {
127
127
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
128
128
  * @returns {Object} manifest API methods
129
129
  */
130
+ // eslint-disable-next-line max-statements
130
131
  function manifestFactory({
131
132
  client,
132
133
  internalAuthTokenProvider
@@ -595,6 +596,66 @@ function manifestFactory({
595
596
  });
596
597
  }
597
598
 
599
+ /**
600
+ * GET /manifests/:manifestKey/fare-capacity-limits - get the manifest's per-fare capacity limit overrides.
601
+ * @param {Object} opts
602
+ * @param {string} [opts.token] - API key
603
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
604
+ * @param {string} opts.manifestKey - Manifest id or {scheduleId}+{date}
605
+ * @param {Object} [opts.headers] - Optional headers
606
+ * @returns {Promise<import("axios").AxiosResponse>}
607
+ */
608
+ function getFareCapacityLimits({
609
+ token,
610
+ jwtToken,
611
+ manifestKey,
612
+ headers
613
+ }) {
614
+ return client({
615
+ url: `/manifests/${manifestKey}/fare-capacity-limits`,
616
+ method: "get",
617
+ headers: authorizationHeaders({
618
+ token,
619
+ jwtToken,
620
+ internalAuthTokenProvider,
621
+ headers
622
+ })
623
+ });
624
+ }
625
+
626
+ /**
627
+ * PUT /manifests/:manifestKey/fare-capacity-limits - replace the per-fare capacity limit overrides.
628
+ * @param {Object} opts
629
+ * @param {string} [opts.token] - API key
630
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
631
+ * @param {string} opts.manifestKey - Manifest id or {scheduleId}+{date}
632
+ * @param {Object} [opts.query] - Optional query, e.g. {routeId}
633
+ * @param {Object} opts.data - Request body, {passengerLimitOverrides: [...]}
634
+ * @param {Object} [opts.headers] - Optional headers
635
+ * @returns {Promise<import("axios").AxiosResponse>}
636
+ */
637
+ function updateFareCapacityLimits({
638
+ token,
639
+ jwtToken,
640
+ manifestKey,
641
+ query = {},
642
+ data,
643
+ headers
644
+ }) {
645
+ return client({
646
+ url: `/manifests/${manifestKey}/fare-capacity-limits`,
647
+ method: "put",
648
+ headers: authorizationHeaders({
649
+ token,
650
+ jwtToken,
651
+ internalAuthTokenProvider,
652
+ headers
653
+ }),
654
+ params: query,
655
+ data
656
+ });
657
+ }
658
+
598
659
  /**
599
660
  * DELETE /manifests/:manifestId/capacity-exceptions/:exceptionId - remove capacity exception.
600
661
  * @param {Object} opts
@@ -1241,6 +1302,8 @@ function manifestFactory({
1241
1302
  updateStatus,
1242
1303
  addCapacityException,
1243
1304
  removeCapacityException,
1305
+ getFareCapacityLimits,
1306
+ updateFareCapacityLimits,
1244
1307
  dispatch,
1245
1308
  updateDispatchReporting,
1246
1309
  createDispatchReporting,
@@ -15,7 +15,7 @@ const {
15
15
  * @param {Object} deps
16
16
  * @param {import("axios").AxiosInstance} deps.client
17
17
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
18
- * @returns {{ create: function, all: function, remove: function }}
18
+ * @returns {{ create: function, all: function, get: function, update: function, remove: function }}
19
19
  */
20
20
  function customReportsFactory({
21
21
  client,
@@ -78,6 +78,65 @@ function customReportsFactory({
78
78
  });
79
79
  }
80
80
 
81
+ /**
82
+ * GET /custom-report/:customReportId - get one custom report.
83
+ * @param {Object} opts
84
+ * @param {string} [opts.token] - API key
85
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
86
+ * @param {string} opts.customReportId - Custom report id
87
+ * @param {Object} [opts.headers] - Optional headers
88
+ * @returns {Promise<import("axios").AxiosResponse>}
89
+ */
90
+ function get({
91
+ token,
92
+ jwtToken,
93
+ customReportId,
94
+ headers
95
+ }) {
96
+ return client({
97
+ url: `/custom-report/${customReportId}`,
98
+ headers: authorizationHeaders({
99
+ token,
100
+ jwtToken,
101
+ internalAuthTokenProvider,
102
+ headers
103
+ })
104
+ });
105
+ }
106
+
107
+ /**
108
+ * PUT /custom-reports/:customReportId - update a custom report.
109
+ * Today the API only accepts deliveryMethod inside customReport.
110
+ * @param {Object} opts
111
+ * @param {string} [opts.token] - API key
112
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
113
+ * @param {string} opts.customReportId - Custom report id
114
+ * @param {Object} opts.customReport - Fields to update
115
+ * @param {Object} [opts.headers] - Optional headers
116
+ * @returns {Promise<import("axios").AxiosResponse>}
117
+ */
118
+ function update({
119
+ token,
120
+ jwtToken,
121
+ customReportId,
122
+ customReport,
123
+ headers
124
+ }) {
125
+ return client({
126
+ url: `/custom-reports/${customReportId}`,
127
+ method: "put",
128
+ headers: authorizationHeaders({
129
+ token,
130
+ jwtToken,
131
+ internalAuthTokenProvider,
132
+ headers
133
+ }),
134
+ data: {
135
+ customReport
136
+ }
137
+ });
138
+ }
139
+
81
140
  /**
82
141
  * DELETE /custom-reports/:customReportId - remove custom report.
83
142
  * @param {Object} opts
@@ -107,6 +166,8 @@ function customReportsFactory({
107
166
  return {
108
167
  create,
109
168
  all,
169
+ get,
170
+ update,
110
171
  remove
111
172
  };
112
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-api-client",
3
- "version": "9.26.0",
3
+ "version": "9.28.0",
4
4
  "description": "Api client for Betterez endpoints",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -123,6 +123,7 @@ const {
123
123
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
124
124
  * @returns {Object} manifest API methods
125
125
  */
126
+ // eslint-disable-next-line max-statements
126
127
  function manifestFactory({
127
128
  client, internalAuthTokenProvider
128
129
  }) {
@@ -447,6 +448,52 @@ function manifestFactory({
447
448
  }
448
449
 
449
450
 
451
+ /**
452
+ * GET /manifests/:manifestKey/fare-capacity-limits - get the manifest's per-fare capacity limit overrides.
453
+ * @param {Object} opts
454
+ * @param {string} [opts.token] - API key
455
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
456
+ * @param {string} opts.manifestKey - Manifest id or {scheduleId}+{date}
457
+ * @param {Object} [opts.headers] - Optional headers
458
+ * @returns {Promise<import("axios").AxiosResponse>}
459
+ */
460
+ function getFareCapacityLimits({
461
+ token, jwtToken, manifestKey, headers
462
+ }) {
463
+ return client({
464
+ url: `/manifests/${manifestKey}/fare-capacity-limits`,
465
+ method: "get",
466
+ headers: authorizationHeaders({
467
+ token, jwtToken, internalAuthTokenProvider, headers
468
+ })
469
+ });
470
+ }
471
+
472
+ /**
473
+ * PUT /manifests/:manifestKey/fare-capacity-limits - replace the per-fare capacity limit overrides.
474
+ * @param {Object} opts
475
+ * @param {string} [opts.token] - API key
476
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
477
+ * @param {string} opts.manifestKey - Manifest id or {scheduleId}+{date}
478
+ * @param {Object} [opts.query] - Optional query, e.g. {routeId}
479
+ * @param {Object} opts.data - Request body, {passengerLimitOverrides: [...]}
480
+ * @param {Object} [opts.headers] - Optional headers
481
+ * @returns {Promise<import("axios").AxiosResponse>}
482
+ */
483
+ function updateFareCapacityLimits({
484
+ token, jwtToken, manifestKey, query = {}, data, headers
485
+ }) {
486
+ return client({
487
+ url: `/manifests/${manifestKey}/fare-capacity-limits`,
488
+ method: "put",
489
+ headers: authorizationHeaders({
490
+ token, jwtToken, internalAuthTokenProvider, headers
491
+ }),
492
+ params: query,
493
+ data
494
+ });
495
+ }
496
+
450
497
  /**
451
498
  * DELETE /manifests/:manifestId/capacity-exceptions/:exceptionId - remove capacity exception.
452
499
  * @param {Object} opts
@@ -885,6 +932,8 @@ function manifestFactory({
885
932
  updateStatus,
886
933
  addCapacityException,
887
934
  removeCapacityException,
935
+ getFareCapacityLimits,
936
+ updateFareCapacityLimits,
888
937
  dispatch,
889
938
  updateDispatchReporting,
890
939
  createDispatchReporting,
@@ -13,7 +13,7 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
13
13
  * @param {Object} deps
14
14
  * @param {import("axios").AxiosInstance} deps.client
15
15
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
16
- * @returns {{ create: function, all: function, remove: function }}
16
+ * @returns {{ create: function, all: function, get: function, update: function, remove: function }}
17
17
  */
18
18
  function customReportsFactory({client, internalAuthTokenProvider}) {
19
19
  /**
@@ -51,6 +51,42 @@ function customReportsFactory({client, internalAuthTokenProvider}) {
51
51
  });
52
52
  }
53
53
 
54
+ /**
55
+ * GET /custom-report/:customReportId - get one custom report.
56
+ * @param {Object} opts
57
+ * @param {string} [opts.token] - API key
58
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
59
+ * @param {string} opts.customReportId - Custom report id
60
+ * @param {Object} [opts.headers] - Optional headers
61
+ * @returns {Promise<import("axios").AxiosResponse>}
62
+ */
63
+ function get({token, jwtToken, customReportId, headers}) {
64
+ return client({
65
+ url: `/custom-report/${customReportId}`,
66
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
67
+ });
68
+ }
69
+
70
+ /**
71
+ * PUT /custom-reports/:customReportId - update a custom report.
72
+ * Today the API only accepts deliveryMethod inside customReport.
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.customReportId - Custom report id
77
+ * @param {Object} opts.customReport - Fields to update
78
+ * @param {Object} [opts.headers] - Optional headers
79
+ * @returns {Promise<import("axios").AxiosResponse>}
80
+ */
81
+ function update({token, jwtToken, customReportId, customReport, headers}) {
82
+ return client({
83
+ url: `/custom-reports/${customReportId}`,
84
+ method: "put",
85
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
86
+ data: {customReport}
87
+ });
88
+ }
89
+
54
90
  /**
55
91
  * DELETE /custom-reports/:customReportId - remove custom report.
56
92
  * @param {Object} opts
@@ -71,6 +107,8 @@ function customReportsFactory({client, internalAuthTokenProvider}) {
71
107
  return {
72
108
  create,
73
109
  all,
110
+ get,
111
+ update,
74
112
  remove
75
113
  };
76
114
  }
@@ -222,6 +222,40 @@ describe("operations/manifest", () => {
222
222
  });
223
223
  });
224
224
 
225
+ it("should read the fare capacity limits from the manifest", async () => {
226
+ const manifestKey = "theId";
227
+
228
+ axiosMock.onGet(`/manifests/${manifestKey}/fare-capacity-limits`).reply(expectRequest({statusCode: 200, token, jwtToken}));
229
+ return api.operations.manifest.getFareCapacityLimits({token, jwtToken, manifestKey});
230
+ });
231
+
232
+ it("should replace the fare capacity limits on the manifest", async () => {
233
+ const manifestKey = "theId";
234
+ const data = {
235
+ passengerLimitOverrides: [
236
+ {fareId: "610aebf7476dc22c1f2d0fee", maxPassengers: 5},
237
+ {fareId: "60b94ceb1516d01a41ccbbc4", unlimited: true}
238
+ ]
239
+ };
240
+
241
+ axiosMock.onPut(`/manifests/${manifestKey}/fare-capacity-limits`).reply(expectRequest({statusCode: 200, token, jwtToken}));
242
+ const call = await api.operations.manifest.updateFareCapacityLimits({token, jwtToken, manifestKey, data});
243
+ assert.deepStrictEqual(JSON.parse(call.config.data), data);
244
+ return call;
245
+ });
246
+
247
+ it("should replace the fare capacity limits addressed by a composite key, passing routeId", async () => {
248
+ // routeId is required only when the composite key names a manifest that does not exist yet.
249
+ const manifestKey = "5cab127c-2c70-4fea-9031-4131e2751cdb+2024-07-25";
250
+ const data = {passengerLimitOverrides: []};
251
+ const query = {routeId: "61a8d5e4adb79606bba26a3f"};
252
+
253
+ axiosMock.onPut(`/manifests/${manifestKey}/fare-capacity-limits`).reply(expectRequest({statusCode: 200, token, jwtToken}));
254
+ const call = await api.operations.manifest.updateFareCapacityLimits({token, jwtToken, manifestKey, data, query});
255
+ assert.deepStrictEqual(call.config.params, query);
256
+ return call;
257
+ });
258
+
225
259
  it("should add user to the manifest", async () => {
226
260
  const manifestId = "theId";
227
261
  const data = {
@@ -28,4 +28,25 @@ describe("reports/custom-reports", () => {
28
28
  axiosMock.onDelete(`/custom-reports/${customReportId}`).reply(expectRequest({statusCode: 200, token, jwtToken}));
29
29
  return api.reports.customReports.remove({jwtToken, token, customReportId});
30
30
  });
31
+
32
+ it("should get a custom report by id", () => {
33
+ axiosMock.onGet(`/custom-report/${customReportId}`).reply(expectRequest({statusCode: 200, token, jwtToken}));
34
+ return api.reports.customReports.get({token, jwtToken, customReportId});
35
+ });
36
+
37
+ it("should update a custom report", () => {
38
+ const customReport = {
39
+ deliveryMethod: {
40
+ method: "S3",
41
+ options: {bucket: "507f1f77bcf86cd799439011"}
42
+ }
43
+ };
44
+ axiosMock.onPut(`/custom-reports/${customReportId}`).reply(expectRequest({
45
+ statusCode: 200,
46
+ token,
47
+ jwtToken,
48
+ body: {customReport}
49
+ }));
50
+ return api.reports.customReports.update({token, jwtToken, customReportId, customReport});
51
+ });
31
52
  });
@@ -68,4 +68,23 @@ describe("reports/custom-report", () => {
68
68
  assert.deepStrictEqual(err.response.status, 401);
69
69
  });
70
70
  });
71
+
72
+ it("should not get a custom report when unauthorized", () => {
73
+ return api.reports.customReports.get({token, jwtToken, customReportId: "5a959a4aa7114ffd7f000001"})
74
+ .catch((err) => {
75
+ assert.deepStrictEqual(err.response.status, 401);
76
+ });
77
+ });
78
+
79
+ it("should not update a custom report when unauthorized", () => {
80
+ return api.reports.customReports.update({
81
+ token,
82
+ jwtToken,
83
+ customReportId: "5a959a4aa7114ffd7f000001",
84
+ customReport: {deliveryMethod: {method: "S3", options: {bucket: "bucket-1"}}}
85
+ })
86
+ .catch((err) => {
87
+ assert.deepStrictEqual(err.response.status, 401);
88
+ });
89
+ });
71
90
  });
@@ -10,7 +10,7 @@ export = customReportsFactory;
10
10
  * @param {Object} deps
11
11
  * @param {import("axios").AxiosInstance} deps.client
12
12
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
13
- * @returns {{ create: function, all: function, remove: function }}
13
+ * @returns {{ create: function, all: function, get: function, update: function, remove: function }}
14
14
  */
15
15
  declare function customReportsFactory({ client, internalAuthTokenProvider }: {
16
16
  client: import("axios").AxiosInstance;
@@ -20,6 +20,8 @@ declare function customReportsFactory({ client, internalAuthTokenProvider }: {
20
20
  }): {
21
21
  create: Function;
22
22
  all: Function;
23
+ get: Function;
24
+ update: Function;
23
25
  remove: Function;
24
26
  };
25
27
  declare namespace customReportsFactory {