@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.2.1 → 4.2.3

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 (47) hide show
  1. package/dpr/all.mjs +7 -7
  2. package/dpr/assets/js/all.mjs +7 -7
  3. package/dpr/components/_async/async-polling/view.njk +1 -1
  4. package/dpr/components/_async/async-request/utils.js +0 -1
  5. package/dpr/components/_async/async-request/utils.ts +0 -2
  6. package/dpr/components/_reports/report-actions/view.njk +1 -1
  7. package/dpr/components/download-feeback-form/view.njk +1 -1
  8. package/dpr/components/user-reports/bookmarks/utils.js +1 -2
  9. package/dpr/components/user-reports/bookmarks/utils.ts +1 -4
  10. package/dpr/data/dashboardClient.js +9 -12
  11. package/dpr/data/dashboardClient.ts +8 -12
  12. package/dpr/data/reportingClient.js +14 -17
  13. package/dpr/data/reportingClient.ts +15 -18
  14. package/dpr/middleware/setUpDprResources.js +86 -0
  15. package/dpr/middleware/setUpDprResources.ts +102 -0
  16. package/dpr/routes/DprEmbeddedReports.js +10 -5
  17. package/dpr/routes/DprEmbeddedReports.ts +18 -6
  18. package/dpr/routes/asyncReports.js +12 -50
  19. package/dpr/routes/asyncReports.ts +20 -56
  20. package/dpr/routes/bookmarks.js +5 -5
  21. package/dpr/routes/bookmarks.ts +6 -6
  22. package/dpr/routes/download.js +11 -8
  23. package/dpr/routes/download.ts +12 -9
  24. package/dpr/routes/recentlyViewed.js +5 -5
  25. package/dpr/routes/recentlyViewed.ts +6 -6
  26. package/dpr/routes/syncReports.js +10 -7
  27. package/dpr/routes/syncReports.ts +11 -8
  28. package/dpr/services/recentlyViewedService.ts +8 -2
  29. package/dpr/services/requestedReportService.ts +1 -1
  30. package/dpr/types/DprConfig.js +2 -0
  31. package/dpr/types/DprConfig.ts +4 -0
  32. package/dpr/utils/definitionUtils.js +8 -0
  33. package/dpr/utils/definitionUtils.ts +6 -2
  34. package/dpr/utils/embeddedRouteUtils.js +2 -3
  35. package/dpr/utils/embeddedRouteUtils.ts +2 -3
  36. package/dpr/utils/localsHelper.js +2 -0
  37. package/dpr/utils/localsHelper.ts +2 -0
  38. package/dpr/utils/reportListsHelper.js +3 -3
  39. package/dpr/utils/reportListsHelper.ts +3 -3
  40. package/dpr/utils/urlHelper.js +13 -1
  41. package/dpr/utils/urlHelper.ts +13 -0
  42. package/package.json +1 -1
  43. package/package.zip +0 -0
  44. package/dpr/middleware/populateDefinitions.js +0 -45
  45. package/dpr/middleware/populateDefinitions.ts +0 -64
  46. package/dpr/middleware/populateRequestedReports.js +0 -24
  47. package/dpr/middleware/populateRequestedReports.ts +0 -26
package/dpr/all.mjs CHANGED
@@ -276,7 +276,7 @@ class BookmarkToggle extends DprClientClass {
276
276
  }
277
277
 
278
278
  async toggleBookmark(type, id, reportId, reportType, csrfToken) {
279
- const endpoint = type === 'add' ? '/addBookmark/' : '/removeBookmark/';
279
+ const endpoint = type === 'add' ? '/dpr/addBookmark/' : '/dpr/removeBookmark/';
280
280
  await fetch(endpoint, {
281
281
  method: 'post',
282
282
  headers: {
@@ -1065,7 +1065,7 @@ class DprPollingStatusClass extends DprClientClass {
1065
1065
  }
1066
1066
 
1067
1067
  async getRequestStatus(metaData, csrfToken) {
1068
- return this.getStatus('/getStatus/', metaData, csrfToken)
1068
+ return this.getStatus('/dpr/getStatus/', metaData, csrfToken)
1069
1069
  }
1070
1070
 
1071
1071
  async getExpiredStatus(endpoint, metaData, csrfToken) {
@@ -1161,7 +1161,7 @@ class DprAsyncPolling extends DprPollingStatusClass {
1161
1161
  const csrfToken = this.cancelRequestButton.getAttribute('data-csrf-token');
1162
1162
 
1163
1163
  this.cancelRequestButton.addEventListener('click', async () => {
1164
- await fetch('/cancelRequest/', {
1164
+ await fetch('/dpr/cancelRequest/', {
1165
1165
  method: 'post',
1166
1166
  headers: {
1167
1167
  Accept: 'application/json',
@@ -1851,7 +1851,7 @@ class DprAsyncRequestList extends DprPollingStatusClass {
1851
1851
  await Promise.all(
1852
1852
  JSON.parse(this.requestData).map(async (metaData) => {
1853
1853
  if (!this.EXPIRED_END_STATUSES.includes(metaData.status)) {
1854
- const response = await this.getExpiredStatus('/getRequestedExpiredStatus/', metaData, this.csrfToken);
1854
+ const response = await this.getExpiredStatus('/dpr/getRequestedExpiredStatus/', metaData, this.csrfToken);
1855
1855
 
1856
1856
  if (response && response.isExpired) {
1857
1857
  clearInterval(this.expiredInterval);
@@ -1891,7 +1891,7 @@ class DprAsyncRequestList extends DprPollingStatusClass {
1891
1891
 
1892
1892
  async removeItemFromList(executionId) {
1893
1893
  let response;
1894
- await fetch('/removeRequestedItem/', {
1894
+ await fetch('/dpr/removeRequestedItem/', {
1895
1895
  method: 'post',
1896
1896
  headers: {
1897
1897
  Accept: 'application/json',
@@ -1945,7 +1945,7 @@ class DprRecentlyViewedList extends DprPollingStatusClass {
1945
1945
  await Promise.all(
1946
1946
  JSON.parse(this.viewedReportData).map(async (metaData) => {
1947
1947
  if (metaData.status !== 'EXPIRED') {
1948
- const response = await this.getExpiredStatus('/getExpiredStatus/', metaData, this.csrfToken);
1948
+ const response = await this.getExpiredStatus('/dpr/getExpiredStatus/', metaData, this.csrfToken);
1949
1949
  if (response && response.isExpired) {
1950
1950
  window.location.reload();
1951
1951
  clearInterval(this.expiredViewedInterval);
@@ -1967,7 +1967,7 @@ class DprRecentlyViewedList extends DprPollingStatusClass {
1967
1967
 
1968
1968
  async removeItemFromList(executionId) {
1969
1969
  let response;
1970
- await fetch('/removeViewedItem/', {
1970
+ await fetch('/dpr/removeViewedItem/', {
1971
1971
  method: 'post',
1972
1972
  headers: {
1973
1973
  Accept: 'application/json',
@@ -249,7 +249,7 @@ class BookmarkToggle extends DprClientClass {
249
249
  }
250
250
 
251
251
  async toggleBookmark(type, id, reportId, reportType, csrfToken) {
252
- const endpoint = type === 'add' ? '/addBookmark/' : '/removeBookmark/';
252
+ const endpoint = type === 'add' ? '/dpr/addBookmark/' : '/dpr/removeBookmark/';
253
253
  await fetch(endpoint, {
254
254
  method: 'post',
255
255
  headers: {
@@ -1038,7 +1038,7 @@ class DprPollingStatusClass extends DprClientClass {
1038
1038
  }
1039
1039
 
1040
1040
  async getRequestStatus(metaData, csrfToken) {
1041
- return this.getStatus('/getStatus/', metaData, csrfToken)
1041
+ return this.getStatus('/dpr/getStatus/', metaData, csrfToken)
1042
1042
  }
1043
1043
 
1044
1044
  async getExpiredStatus(endpoint, metaData, csrfToken) {
@@ -1134,7 +1134,7 @@ class DprAsyncPolling extends DprPollingStatusClass {
1134
1134
  const csrfToken = this.cancelRequestButton.getAttribute('data-csrf-token');
1135
1135
 
1136
1136
  this.cancelRequestButton.addEventListener('click', async () => {
1137
- await fetch('/cancelRequest/', {
1137
+ await fetch('/dpr/cancelRequest/', {
1138
1138
  method: 'post',
1139
1139
  headers: {
1140
1140
  Accept: 'application/json',
@@ -1824,7 +1824,7 @@ class DprAsyncRequestList extends DprPollingStatusClass {
1824
1824
  await Promise.all(
1825
1825
  JSON.parse(this.requestData).map(async (metaData) => {
1826
1826
  if (!this.EXPIRED_END_STATUSES.includes(metaData.status)) {
1827
- const response = await this.getExpiredStatus('/getRequestedExpiredStatus/', metaData, this.csrfToken);
1827
+ const response = await this.getExpiredStatus('/dpr/getRequestedExpiredStatus/', metaData, this.csrfToken);
1828
1828
 
1829
1829
  if (response && response.isExpired) {
1830
1830
  clearInterval(this.expiredInterval);
@@ -1864,7 +1864,7 @@ class DprAsyncRequestList extends DprPollingStatusClass {
1864
1864
 
1865
1865
  async removeItemFromList(executionId) {
1866
1866
  let response;
1867
- await fetch('/removeRequestedItem/', {
1867
+ await fetch('/dpr/removeRequestedItem/', {
1868
1868
  method: 'post',
1869
1869
  headers: {
1870
1870
  Accept: 'application/json',
@@ -1918,7 +1918,7 @@ class DprRecentlyViewedList extends DprPollingStatusClass {
1918
1918
  await Promise.all(
1919
1919
  JSON.parse(this.viewedReportData).map(async (metaData) => {
1920
1920
  if (metaData.status !== 'EXPIRED') {
1921
- const response = await this.getExpiredStatus('/getExpiredStatus/', metaData, this.csrfToken);
1921
+ const response = await this.getExpiredStatus('/dpr/getExpiredStatus/', metaData, this.csrfToken);
1922
1922
  if (response && response.isExpired) {
1923
1923
  window.location.reload();
1924
1924
  clearInterval(this.expiredViewedInterval);
@@ -1940,7 +1940,7 @@ class DprRecentlyViewedList extends DprPollingStatusClass {
1940
1940
 
1941
1941
  async removeItemFromList(executionId) {
1942
1942
  let response;
1943
- await fetch('/removeViewedItem/', {
1943
+ await fetch('/dpr/removeViewedItem/', {
1944
1944
  method: 'post',
1945
1945
  headers: {
1946
1946
  Accept: 'application/json',
@@ -60,7 +60,7 @@
60
60
  {{ dprRequestDetails(data)}}
61
61
 
62
62
  {{ govukInsetText({
63
- html: "<p>It can take up to 10 minutes to generate a " + type + ".</p> <p>You can close and revisit this page at anytime. Navigate to the homepage to check on its status or your " + type + ".</p>"
63
+ html: "<p>It can take up to 10 minutes to generate a " + type + ".</p> <p>You can close and revisit this page at anytime. Navigate to the homepage to check on the status of your " + type + ".</p>"
64
64
  }) }}
65
65
 
66
66
  {{ govukButton({
@@ -59,7 +59,6 @@ const updateStore = async ({ req, res, services, queryData, executionData, child
59
59
  default:
60
60
  break;
61
61
  }
62
- console.log(JSON.stringify(requestedReportData, null, 2));
63
62
  await services.requestedReportService.addReport(userId, requestedReportData);
64
63
  return requestedReportData.url.polling.pathname;
65
64
  };
@@ -85,8 +85,6 @@ export const updateStore = async ({
85
85
  break
86
86
  }
87
87
 
88
- console.log(JSON.stringify(requestedReportData, null, 2))
89
-
90
88
  await services.requestedReportService.addReport(userId, requestedReportData)
91
89
 
92
90
  return requestedReportData.url.polling.pathname
@@ -20,7 +20,7 @@
20
20
  } %}
21
21
 
22
22
  {% if not button.disabled %}
23
- <form id="download-report-form" action="/downloadReport/" method="post">
23
+ <form id="download-report-form" action="/dpr/downloadReport/" method="post">
24
24
  <input type="hidden" name="dataProductDefinitionsPath" value="{{ button.attributes.definitionPath }}">
25
25
  <input type="hidden" name="_csrf" value="{{ button.attributes.csrfToken }}">
26
26
  <input type="hidden" name="reportId" value="{{ button.attributes.reportId }}">
@@ -23,7 +23,7 @@
23
23
 
24
24
  <div class="dpr-download-feedback-form-wrapper" data-dpr-module="download-feedback-form">
25
25
 
26
- <form action="/submitFeedback/" method="post" id="download-feedback-form" class="download-feedback-form--hidden">
26
+ <form action="/dpr/submitFeedback/" method="post" id="download-feedback-form" class="download-feedback-form--hidden">
27
27
 
28
28
  <p>To enable downloads for this report (<strong>{{ reportName}} - {{ variantName }}</strong>), take a few moments to fill out this request form.</p><p>Once you have submitted the form you the download button will be enabled immediately.</p>
29
29
 
@@ -70,7 +70,7 @@ const formatTableData = async (bookmarksData, bookmarkService, csrfToken, userId
70
70
  };
71
71
  const mapBookmarkIdsToDefinition = async (bookmarks, req, res, token, services) => {
72
72
  const bookmarkData = [];
73
- const { pathSuffix, definitionsPath } = localsHelper_1.default.getValues(res);
73
+ const { definitionsPath } = localsHelper_1.default.getValues(res);
74
74
  await Promise.all(bookmarks.map(async (bookmark) => {
75
75
  var _a;
76
76
  let definition;
@@ -122,7 +122,6 @@ const mapBookmarkIdsToDefinition = async (bookmarks, req, res, token, services)
122
122
  exports.default = {
123
123
  renderBookmarkList: async ({ services, maxRows, res, req, }) => {
124
124
  const { token, csrfToken, userId, bookmarks } = localsHelper_1.default.getValues(res);
125
- console.log({ bookmarks });
126
125
  const bookmarksData = await mapBookmarkIdsToDefinition(bookmarks, req, res, token, services);
127
126
  const formatted = await (0, exports.formatBookmarks)(bookmarksData, maxRows);
128
127
  const tableData = await formatTable(bookmarksData, services.bookmarkService, csrfToken, userId, maxRows);
@@ -96,7 +96,7 @@ const mapBookmarkIdsToDefinition = async (
96
96
  services: Services,
97
97
  ): Promise<BookmarkedReportData[]> => {
98
98
  const bookmarkData: BookmarkedReportData[] = []
99
- const { pathSuffix, definitionsPath } = LocalsHelper.getValues(res)
99
+ const { definitionsPath } = LocalsHelper.getValues(res)
100
100
 
101
101
  await Promise.all(
102
102
  bookmarks.map(async (bookmark) => {
@@ -180,9 +180,6 @@ export default {
180
180
  req: Request
181
181
  }) => {
182
182
  const { token, csrfToken, userId, bookmarks } = LocalsHelper.getValues(res)
183
-
184
- console.log({ bookmarks })
185
-
186
183
  const bookmarksData: BookmarkedReportData[] = await mapBookmarkIdsToDefinition(bookmarks, req, res, token, services)
187
184
  const formatted = await formatBookmarks(bookmarksData, maxRows)
188
185
  const tableData = await formatTable(bookmarksData, services.bookmarkService, csrfToken, userId, maxRows)
@@ -10,7 +10,7 @@ class DashboardClient {
10
10
  this.restClient = new restClient_1.default('Dashboard API Client', config);
11
11
  }
12
12
  getDefinition(token, dashboardId, dpdId, definitionsPath) {
13
- this.logInfo('Get definition:', { dpdId, dashboardId }, { definitionsPath });
13
+ this.logInfo('Get definition:', { dpdId, dashboardId });
14
14
  const query = {
15
15
  dataProductDefinitionsPath: definitionsPath,
16
16
  };
@@ -23,7 +23,7 @@ class DashboardClient {
23
23
  .then((response) => response);
24
24
  }
25
25
  requestAsyncDashboard(token, reportId, dashboardId, query) {
26
- this.logInfo('Request dashboard:', { reportId, dashboardId }, query);
26
+ this.logInfo('Request dashboard:', { reportId, dashboardId });
27
27
  return this.restClient
28
28
  .get({
29
29
  path: `/async/dashboards/${reportId}/${dashboardId}`,
@@ -33,7 +33,7 @@ class DashboardClient {
33
33
  .then((response) => response);
34
34
  }
35
35
  getAsyncDashboard(token, reportId, dashboardId, tableId, query) {
36
- this.logInfo('Get dashboard:', { reportId, dashboardId, tableId }, query);
36
+ this.logInfo('Get dashboard:', { reportId, dashboardId, tableId });
37
37
  return this.restClient
38
38
  .get({
39
39
  path: `/reports/${reportId}/dashboards/${dashboardId}/tables/${tableId}/result`,
@@ -43,7 +43,7 @@ class DashboardClient {
43
43
  .then((response) => response);
44
44
  }
45
45
  getAsyncStatus(token, reportId, dashboardId, executionId, dataProductDefinitionsPath, tableId) {
46
- this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId }, { dataProductDefinitionsPath });
46
+ this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId });
47
47
  return this.restClient
48
48
  .get({
49
49
  path: `/reports/${reportId}/dashboards/${dashboardId}/statements/${executionId}/status`,
@@ -56,7 +56,7 @@ class DashboardClient {
56
56
  .then((response) => response);
57
57
  }
58
58
  cancelAsyncRequest(token, reportId, dashboardId, executionId, dataProductDefinitionsPath) {
59
- this.logInfo('Cancel request:', { reportId, dashboardId, executionId }, { dataProductDefinitionsPath });
59
+ this.logInfo('Cancel request:', { reportId, dashboardId, executionId });
60
60
  return this.restClient
61
61
  .delete({
62
62
  path: `/reports/${reportId}/dashboards/${dashboardId}/statements/${executionId}`,
@@ -67,13 +67,10 @@ class DashboardClient {
67
67
  })
68
68
  .then((response) => response);
69
69
  }
70
- logInfo(title, args, query) {
71
- logger_1.default.info(`
72
- Dashboard client: ${title}:`);
73
- logger_1.default.info(JSON.stringify(args, null, 2));
74
- if (query) {
75
- logger_1.default.info(JSON.stringify(query, null, 2));
76
- }
70
+ logInfo(title, args) {
71
+ logger_1.default.info(`Dashboard client: ${title}:`);
72
+ if (args && Object.keys(args).length)
73
+ logger_1.default.info(JSON.stringify(args, null, 2));
77
74
  }
78
75
  }
79
76
  exports.default = DashboardClient;
@@ -17,7 +17,7 @@ export default class DashboardClient {
17
17
  dpdId: string,
18
18
  definitionsPath?: string,
19
19
  ): Promise<DashboardDefinition> {
20
- this.logInfo('Get definition:', { dpdId, dashboardId }, { definitionsPath })
20
+ this.logInfo('Get definition:', { dpdId, dashboardId })
21
21
  const query = {
22
22
  dataProductDefinitionsPath: definitionsPath,
23
23
  }
@@ -36,7 +36,7 @@ export default class DashboardClient {
36
36
  dashboardId: string,
37
37
  query: Record<string, string | boolean | number>,
38
38
  ): Promise<Dict<string>> {
39
- this.logInfo('Request dashboard:', { reportId, dashboardId }, query)
39
+ this.logInfo('Request dashboard:', { reportId, dashboardId })
40
40
 
41
41
  return this.restClient
42
42
  .get({
@@ -54,7 +54,7 @@ export default class DashboardClient {
54
54
  tableId: string,
55
55
  query: Dict<string | number>,
56
56
  ): Promise<Array<Dict<string>>> {
57
- this.logInfo('Get dashboard:', { reportId, dashboardId, tableId }, query)
57
+ this.logInfo('Get dashboard:', { reportId, dashboardId, tableId })
58
58
 
59
59
  return this.restClient
60
60
  .get({
@@ -73,7 +73,7 @@ export default class DashboardClient {
73
73
  dataProductDefinitionsPath?: string,
74
74
  tableId?: string,
75
75
  ): Promise<Dict<string>> {
76
- this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId }, { dataProductDefinitionsPath })
76
+ this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId })
77
77
 
78
78
  return this.restClient
79
79
  .get({
@@ -94,7 +94,7 @@ export default class DashboardClient {
94
94
  executionId: string,
95
95
  dataProductDefinitionsPath: string,
96
96
  ): Promise<Dict<string>> {
97
- this.logInfo('Cancel request:', { reportId, dashboardId, executionId }, { dataProductDefinitionsPath })
97
+ this.logInfo('Cancel request:', { reportId, dashboardId, executionId })
98
98
 
99
99
  return this.restClient
100
100
  .delete({
@@ -107,12 +107,8 @@ export default class DashboardClient {
107
107
  .then((response) => <Dict<string>>response)
108
108
  }
109
109
 
110
- logInfo(title: string, args?: Dict<string>, query?: Dict<string | number | boolean>) {
111
- logger.info(`
112
- Dashboard client: ${title}:`)
113
- logger.info(JSON.stringify(args, null, 2))
114
- if (query) {
115
- logger.info(JSON.stringify(query, null, 2))
116
- }
110
+ logInfo(title: string, args?: Dict<string>) {
111
+ logger.info(`Dashboard client: ${title}:`)
112
+ if (args && Object.keys(args).length) logger.info(JSON.stringify(args, null, 2))
117
113
  }
118
114
  }
@@ -38,7 +38,7 @@ class ReportingClient {
38
38
  }));
39
39
  }
40
40
  getDefinitions(token, definitionsPath) {
41
- this.logInfo('Get definitions:', {}, { definitionsPath });
41
+ this.logInfo('Get definitions', { definitionsPath });
42
42
  const params = {
43
43
  query: {
44
44
  renderMethod: 'HTML',
@@ -54,10 +54,10 @@ class ReportingClient {
54
54
  .then((response) => response);
55
55
  }
56
56
  getDefinition(token, reportId, variantId, definitionsPath) {
57
- this.logInfo('Get single variant definition:', { reportId, variantId }, { definitionsPath });
58
57
  const query = {
59
58
  dataProductDefinitionsPath: definitionsPath,
60
59
  };
60
+ this.logInfo('Get definition', { reportId, variantId });
61
61
  return this.restClient
62
62
  .get({
63
63
  path: `/definitions/${reportId}/${variantId}`,
@@ -71,7 +71,7 @@ class ReportingClient {
71
71
  dataProductDefinitionsPath: definitionsPath,
72
72
  prefix,
73
73
  };
74
- this.logInfo('Get field values:', { definitionName, variantName, fieldName }, query);
74
+ this.logInfo('Get field values', { definitionName, variantName, fieldName, prefix });
75
75
  return this.restClient
76
76
  .get({
77
77
  path: `/reports/${definitionName}/${variantName}/${fieldName}`,
@@ -81,7 +81,7 @@ class ReportingClient {
81
81
  .then((response) => response);
82
82
  }
83
83
  requestAsyncReport(token, reportId, variantId, query) {
84
- this.logInfo('Request report:', { reportId, variantId }, query);
84
+ this.logInfo('Request report', { reportId, variantId });
85
85
  return this.restClient
86
86
  .get({
87
87
  path: `/async/reports/${reportId}/${variantId}`,
@@ -91,7 +91,7 @@ class ReportingClient {
91
91
  .then((response) => response);
92
92
  }
93
93
  cancelAsyncRequest(token, reportId, variantId, executionId, dataProductDefinitionsPath) {
94
- this.logInfo('Cancel request:', { reportId, variantId, executionId }, { dataProductDefinitionsPath });
94
+ this.logInfo('Cancel Request', { reportId, variantId, executionId });
95
95
  return this.restClient
96
96
  .delete({
97
97
  path: `/reports/${reportId}/${variantId}/statements/${executionId}`,
@@ -103,7 +103,7 @@ class ReportingClient {
103
103
  .then((response) => response);
104
104
  }
105
105
  getAsyncReport(token, reportId, variantId, tableId, query) {
106
- this.logInfo('Get Data:', { reportId, variantId, tableId }, query);
106
+ this.logInfo('Get Data', { reportId, variantId, tableId });
107
107
  return this.restClient
108
108
  .get({
109
109
  path: `/reports/${reportId}/${variantId}/tables/${tableId}/result`,
@@ -113,7 +113,7 @@ class ReportingClient {
113
113
  .then((response) => response);
114
114
  }
115
115
  getAsyncSummaryReport(token, reportId, variantId, tableId, summaryId, query) {
116
- this.logInfo('Get summary report data:', { reportId, variantId, summaryId, tableId }, query);
116
+ this.logInfo('Get summary data', { reportId, variantId, tableId, summaryId });
117
117
  return this.restClient
118
118
  .get({
119
119
  path: `/reports/${reportId}/${variantId}/tables/${tableId}/result/summary/${summaryId}`,
@@ -123,7 +123,7 @@ class ReportingClient {
123
123
  .then((response) => response);
124
124
  }
125
125
  getAsyncReportStatus(token, reportId, variantId, executionId, dataProductDefinitionsPath, tableId) {
126
- this.logInfo('Get status:', { reportId, variantId, executionId, tableId }, { dataProductDefinitionsPath });
126
+ this.logInfo('Get status', { reportId, variantId, tableId, executionId });
127
127
  return this.restClient
128
128
  .get({
129
129
  path: `/reports/${reportId}/${variantId}/statements/${executionId}/status`,
@@ -136,7 +136,7 @@ class ReportingClient {
136
136
  .then((response) => response);
137
137
  }
138
138
  getAsyncCount(token, tableId, dataProductDefinitionsPath) {
139
- this.logInfo('Get count:', { tableId });
139
+ this.logInfo('Get count', { tableId });
140
140
  return this.restClient
141
141
  .get({
142
142
  path: `/report/tables/${tableId}/count`,
@@ -148,7 +148,7 @@ class ReportingClient {
148
148
  .then((response) => response.count);
149
149
  }
150
150
  getAsyncInteractiveCount(token, tableId, reportId, id, filters) {
151
- this.logInfo('Get interactive count', { tableId });
151
+ this.logInfo('Get interactive count', { tableId, reportId, id });
152
152
  return this.restClient
153
153
  .get({
154
154
  path: `/reports/${reportId}/${id}/tables/${tableId}/count`,
@@ -157,13 +157,10 @@ class ReportingClient {
157
157
  })
158
158
  .then((response) => response.count);
159
159
  }
160
- logInfo(title, args, query) {
161
- logger_1.default.info(`
162
- Reporting client: ${title}:`);
163
- logger_1.default.info(JSON.stringify(args, null, 2));
164
- if (query) {
165
- logger_1.default.info(JSON.stringify(query, null, 2));
166
- }
160
+ logInfo(title, args) {
161
+ logger_1.default.info(`Reporting Client: ${title}:`);
162
+ if (args && Object.keys(args).length)
163
+ logger_1.default.info(JSON.stringify(args, null, 2));
167
164
  }
168
165
  }
169
166
  exports.default = ReportingClient;
@@ -50,7 +50,7 @@ export default class ReportingClient {
50
50
  token: string,
51
51
  definitionsPath?: string,
52
52
  ): Promise<Array<components['schemas']['ReportDefinitionSummary']>> {
53
- this.logInfo('Get definitions:', {}, { definitionsPath })
53
+ this.logInfo('Get definitions', { definitionsPath })
54
54
 
55
55
  const params: operations['definitions_1']['parameters'] = {
56
56
  query: {
@@ -74,11 +74,11 @@ export default class ReportingClient {
74
74
  variantId: string,
75
75
  definitionsPath?: string,
76
76
  ): Promise<components['schemas']['SingleVariantReportDefinition']> {
77
- this.logInfo('Get single variant definition:', { reportId, variantId }, { definitionsPath })
78
-
79
77
  const query = {
80
78
  dataProductDefinitionsPath: definitionsPath,
81
79
  }
80
+ this.logInfo('Get definition', { reportId, variantId })
81
+
82
82
  return this.restClient
83
83
  .get({
84
84
  path: `/definitions/${reportId}/${variantId}`,
@@ -100,7 +100,7 @@ export default class ReportingClient {
100
100
  dataProductDefinitionsPath: definitionsPath,
101
101
  prefix,
102
102
  }
103
- this.logInfo('Get field values:', { definitionName, variantName, fieldName }, query)
103
+ this.logInfo('Get field values', { definitionName, variantName, fieldName, prefix })
104
104
 
105
105
  return this.restClient
106
106
  .get({
@@ -117,7 +117,7 @@ export default class ReportingClient {
117
117
  variantId: string,
118
118
  query: Record<string, string | boolean | number>,
119
119
  ): Promise<Dict<string>> {
120
- this.logInfo('Request report:', { reportId, variantId }, query)
120
+ this.logInfo('Request report', { reportId, variantId })
121
121
 
122
122
  return this.restClient
123
123
  .get({
@@ -135,7 +135,7 @@ export default class ReportingClient {
135
135
  executionId: string,
136
136
  dataProductDefinitionsPath?: string,
137
137
  ): Promise<Dict<string>> {
138
- this.logInfo('Cancel request:', { reportId, variantId, executionId }, { dataProductDefinitionsPath })
138
+ this.logInfo('Cancel Request', { reportId, variantId, executionId })
139
139
 
140
140
  return this.restClient
141
141
  .delete({
@@ -155,7 +155,7 @@ export default class ReportingClient {
155
155
  tableId: string,
156
156
  query: Dict<string | number>,
157
157
  ): Promise<Array<Dict<string>>> {
158
- this.logInfo('Get Data:', { reportId, variantId, tableId }, query)
158
+ this.logInfo('Get Data', { reportId, variantId, tableId })
159
159
 
160
160
  return this.restClient
161
161
  .get({
@@ -174,7 +174,7 @@ export default class ReportingClient {
174
174
  summaryId: string,
175
175
  query: Dict<string | number>,
176
176
  ): Promise<Array<Dict<string>>> {
177
- this.logInfo('Get summary report data:', { reportId, variantId, summaryId, tableId }, query)
177
+ this.logInfo('Get summary data', { reportId, variantId, tableId, summaryId })
178
178
 
179
179
  return this.restClient
180
180
  .get({
@@ -193,7 +193,8 @@ export default class ReportingClient {
193
193
  dataProductDefinitionsPath?: string,
194
194
  tableId?: string,
195
195
  ): Promise<Dict<string>> {
196
- this.logInfo('Get status:', { reportId, variantId, executionId, tableId }, { dataProductDefinitionsPath })
196
+ this.logInfo('Get status', { reportId, variantId, tableId, executionId })
197
+
197
198
  return this.restClient
198
199
  .get({
199
200
  path: `/reports/${reportId}/${variantId}/statements/${executionId}/status`,
@@ -207,7 +208,7 @@ export default class ReportingClient {
207
208
  }
208
209
 
209
210
  getAsyncCount(token: string, tableId: string, dataProductDefinitionsPath?: string): Promise<number> {
210
- this.logInfo('Get count:', { tableId })
211
+ this.logInfo('Get count', { tableId })
211
212
 
212
213
  return this.restClient
213
214
  .get({
@@ -227,7 +228,7 @@ export default class ReportingClient {
227
228
  id: string,
228
229
  filters: ReportQuery,
229
230
  ): Promise<number> {
230
- this.logInfo('Get interactive count', { tableId })
231
+ this.logInfo('Get interactive count', { tableId, reportId, id })
231
232
 
232
233
  return this.restClient
233
234
  .get({
@@ -238,12 +239,8 @@ export default class ReportingClient {
238
239
  .then((response) => (<Count>response).count)
239
240
  }
240
241
 
241
- logInfo(title: string, args?: Dict<string>, query?: Dict<string | number | boolean>) {
242
- logger.info(`
243
- Reporting client: ${title}:`)
244
- logger.info(JSON.stringify(args, null, 2))
245
- if (query) {
246
- logger.info(JSON.stringify(query, null, 2))
247
- }
242
+ logInfo(title: string, args?: Dict<string>) {
243
+ logger.info(`Reporting Client: ${title}:`)
244
+ if (args && Object.keys(args).length) logger.info(JSON.stringify(args, null, 2))
248
245
  }
249
246
  }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.populateRequestedReports = exports.populateDefinitions = exports.setRoutePrefix = void 0;
7
+ const definitionUtils_1 = __importDefault(require("../utils/definitionUtils"));
8
+ const urlHelper_1 = require("../utils/urlHelper");
9
+ const getQueryParamAsString = (query, name) => (query[name] ? query[name].toString() : null);
10
+ const getDefinitionsPath = (query) => getQueryParamAsString(query, 'dataProductDefinitionsPath');
11
+ const deriveDefinitionsPath = (query) => {
12
+ const definitionsPath = getDefinitionsPath(query);
13
+ if (definitionsPath) {
14
+ return definitionsPath;
15
+ }
16
+ return null;
17
+ };
18
+ exports.default = (services, config) => {
19
+ return async (req, res, next) => {
20
+ try {
21
+ await (0, exports.populateDefinitions)(services, req, res, config);
22
+ await (0, exports.populateRequestedReports)(services, res);
23
+ (0, exports.setRoutePrefix)(res, config);
24
+ return next();
25
+ }
26
+ catch (error) {
27
+ return next(error);
28
+ }
29
+ };
30
+ };
31
+ const setRoutePrefix = async (res, config) => {
32
+ res.locals.routePrefix = (0, urlHelper_1.getRoutePrefix)(config);
33
+ };
34
+ exports.setRoutePrefix = setRoutePrefix;
35
+ const populateDefinitions = async (services, req, res, config) => {
36
+ // Get the DPD path from the query
37
+ const dpdPathFromQuery = deriveDefinitionsPath(req.query);
38
+ const dpdPathFromBody = req.body.dataProductDefinitionsPath;
39
+ const definitionsPathFromQuery = dpdPathFromQuery || dpdPathFromBody;
40
+ if (definitionsPathFromQuery) {
41
+ res.locals.dpdPathFromQuery = true;
42
+ }
43
+ // Get the DPD path from the config
44
+ const dpdPathFromConfig = config === null || config === void 0 ? void 0 : config.dprDataProductDefinitionPath;
45
+ if (dpdPathFromConfig) {
46
+ res.locals.dpdPathFromConfig = true;
47
+ }
48
+ // query takes presedence over config
49
+ res.locals.definitionsPath = definitionsPathFromQuery || dpdPathFromConfig;
50
+ res.locals.pathSuffix = `?dataProductDefinitionsPath=${res.locals.definitionsPath}`;
51
+ if (res.locals.user.token && services.reportingService) {
52
+ res.locals.definitions = await services.reportingService.getDefinitions(res.locals.user.token, res.locals.definitionsPath);
53
+ }
54
+ };
55
+ exports.populateDefinitions = populateDefinitions;
56
+ const populateRequestedReports = async (services, res) => {
57
+ if (res.locals.user) {
58
+ const { uuid: userId } = res.locals.user;
59
+ const { definitions, definitionsPath } = res.locals;
60
+ const requested = await services.requestedReportService.getAllReports(userId);
61
+ res.locals.requestedReports = !definitionsPath
62
+ ? requested
63
+ : requested.filter((report) => {
64
+ return definitionUtils_1.default.getCurrentVariantDefinition(definitions, report.reportId, report.id);
65
+ });
66
+ const recent = await services.recentlyViewedService.getAllReports(userId);
67
+ res.locals.recentlyViewedReports = !definitionsPath
68
+ ? recent
69
+ : recent.filter((report) => {
70
+ return definitionUtils_1.default.getCurrentVariantDefinition(definitions, report.reportId, report.id);
71
+ });
72
+ if (services.bookmarkService) {
73
+ res.locals.bookmarkingEnabled = true;
74
+ const bookmarks = await services.bookmarkService.getAllBookmarks(userId);
75
+ res.locals.bookmarks = !definitionsPath
76
+ ? bookmarks
77
+ : bookmarks.filter((bookmark) => {
78
+ return definitionUtils_1.default.getCurrentVariantDefinition(definitions, bookmark.reportId, bookmark.id);
79
+ });
80
+ }
81
+ if (services.downloadPermissionService) {
82
+ res.locals.downloadingEnabled = true;
83
+ }
84
+ }
85
+ };
86
+ exports.populateRequestedReports = populateRequestedReports;