@lighthouse/common 6.3.0-canary.0 → 6.3.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/dist/helpers/fetch-image-for-pdf-generator-service/index.js +61 -24
- package/dist/pdf/audit/index.js +5 -8
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js +57 -24
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js.map +1 -1
- package/lib/pdf/audit/index.js +4 -8
- package/lib/pdf/audit/index.js.map +1 -1
- package/package.json +3 -4
|
@@ -27,20 +27,24 @@ const fetchImageForPdfGeneratorService = async function (url) {
|
|
|
27
27
|
if (!applicationId) {
|
|
28
28
|
throw new Error('Requestor has insufficient permissions');
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const {
|
|
31
|
+
path,
|
|
32
|
+
queryString,
|
|
33
|
+
searchParamsObject
|
|
34
|
+
} = parseUrlString(url);
|
|
35
|
+
const transformedBucketImagePath = path + (queryString ? `/${queryString}` : '');
|
|
31
36
|
const alreadyTransformedImage = await fetchResourceFromS3({
|
|
32
|
-
bucketName:
|
|
33
|
-
key:
|
|
37
|
+
bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,
|
|
38
|
+
key: transformedBucketImagePath
|
|
34
39
|
});
|
|
35
40
|
if (alreadyTransformedImage?.body) {
|
|
36
41
|
const fullDataUrl = formatBase64Image({
|
|
37
42
|
base64String: alreadyTransformedImage.body.toString('base64'),
|
|
38
|
-
key:
|
|
43
|
+
key: transformedBucketImagePath
|
|
39
44
|
});
|
|
40
45
|
return fullDataUrl;
|
|
41
46
|
}
|
|
42
|
-
const
|
|
43
|
-
const transformerResponse = await requestImageTransformation(keyWithoutTransformations);
|
|
47
|
+
const transformerResponse = await requestImageTransformation(`/${path}`, searchParamsObject);
|
|
44
48
|
const statusCode = transformerResponse.statusCode;
|
|
45
49
|
switch (statusCode) {
|
|
46
50
|
case 200:
|
|
@@ -48,27 +52,27 @@ const fetchImageForPdfGeneratorService = async function (url) {
|
|
|
48
52
|
console.debug('Image transformation successful');
|
|
49
53
|
const fullDataUrl = formatBase64Image({
|
|
50
54
|
base64String: transformerResponse.body.toString('base64'),
|
|
51
|
-
key:
|
|
55
|
+
key: url
|
|
52
56
|
});
|
|
53
57
|
return fullDataUrl;
|
|
54
58
|
}
|
|
55
59
|
case 302:
|
|
56
60
|
{
|
|
57
61
|
console.debug('Image transformation successful but image is too big for lambda delivery, fetching directly from S3');
|
|
58
|
-
const redirectLocation = transformerResponse.headers
|
|
59
|
-
if (redirectLocation) {
|
|
60
|
-
|
|
61
|
-
bucketName: `${process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE}`,
|
|
62
|
-
key: keyWithTransformations
|
|
63
|
-
});
|
|
64
|
-
console.debug('Image successfully fetched from S3 at:', redirectLocation);
|
|
65
|
-
const fullDataUrl = formatBase64Image({
|
|
66
|
-
base64String: newlyTransformedImage.body.toString('base64'),
|
|
67
|
-
key: keyWithTransformations
|
|
68
|
-
});
|
|
69
|
-
return fullDataUrl;
|
|
62
|
+
const redirectLocation = transformerResponse.headers.Location;
|
|
63
|
+
if (!redirectLocation) {
|
|
64
|
+
throw new Error('Redirect response received but no location provided');
|
|
70
65
|
}
|
|
71
|
-
|
|
66
|
+
const newlyTransformedImage = await fetchResourceFromS3({
|
|
67
|
+
bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,
|
|
68
|
+
key: transformedBucketImagePath
|
|
69
|
+
});
|
|
70
|
+
console.debug('Image successfully fetched from S3 at:', redirectLocation);
|
|
71
|
+
const fullDataUrl = formatBase64Image({
|
|
72
|
+
base64String: newlyTransformedImage.body.toString('base64'),
|
|
73
|
+
key: transformedBucketImagePath
|
|
74
|
+
});
|
|
75
|
+
return fullDataUrl;
|
|
72
76
|
}
|
|
73
77
|
case 400:
|
|
74
78
|
throw new Error(`Bad request to image transformer: ${transformerResponse.body}`);
|
|
@@ -83,16 +87,20 @@ const fetchImageForPdfGeneratorService = async function (url) {
|
|
|
83
87
|
}
|
|
84
88
|
};
|
|
85
89
|
exports.fetchImageForPdfGeneratorService = fetchImageForPdfGeneratorService;
|
|
86
|
-
async function requestImageTransformation(
|
|
87
|
-
if (!
|
|
90
|
+
async function requestImageTransformation(path, searchParamsObject) {
|
|
91
|
+
if (!path) {
|
|
88
92
|
throw new Error('Image Path is required for image transformation');
|
|
89
93
|
}
|
|
90
|
-
console.debug('ImageTransformation: Invoking image transformer lambda for path:',
|
|
94
|
+
console.debug('ImageTransformation: Invoking image transformer lambda for path:', {
|
|
95
|
+
path,
|
|
96
|
+
searchParamsObject
|
|
97
|
+
});
|
|
91
98
|
const lambdaEvent = {
|
|
99
|
+
queryStringParameters: searchParamsObject,
|
|
92
100
|
requestContext: {
|
|
93
101
|
http: {
|
|
94
102
|
method: 'GET',
|
|
95
|
-
path
|
|
103
|
+
path
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
};
|
|
@@ -160,4 +168,33 @@ function formatBase64Image({
|
|
|
160
168
|
throw new Error('InvalidImageError');
|
|
161
169
|
}
|
|
162
170
|
return fullDataUrl;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Parses a URL-like string into path and query parameters
|
|
175
|
+
* @param {string} urlString - String like "https://example.cloudfront.net/<applicationId>/<path>/filename.jpeg?width=100&height=100"
|
|
176
|
+
* @returns {Object} - Object with { path: string, queryString: string, searchParamsObject: Object }
|
|
177
|
+
* @example
|
|
178
|
+
* parseUrlString("https://example.cloudfront.net/abc123/folder/image.jpeg?width=100&height=100")
|
|
179
|
+
* // Returns: { path: "abc123/folder/image.jpeg", queryString: "width=100,t=456", searchParamsObject: { width: "100", height: "100" } }
|
|
180
|
+
*/
|
|
181
|
+
function parseUrlString(urlString) {
|
|
182
|
+
if (!urlString || typeof urlString !== 'string') {
|
|
183
|
+
throw new Error('URL string is required and must be a string');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Extract the path after the domain
|
|
187
|
+
const url = new URL(urlString);
|
|
188
|
+
let searchParamsObject = {};
|
|
189
|
+
url.searchParams.forEach((value, key) => {
|
|
190
|
+
searchParamsObject[key] = value;
|
|
191
|
+
});
|
|
192
|
+
let queryString = url.searchParams.toString();
|
|
193
|
+
queryString = queryString ? queryString.replace(/&/g, ',') : '';
|
|
194
|
+
return {
|
|
195
|
+
path: url.pathname.substring(1),
|
|
196
|
+
// Remove leading '/'
|
|
197
|
+
queryString,
|
|
198
|
+
searchParamsObject
|
|
199
|
+
};
|
|
163
200
|
}
|
package/dist/pdf/audit/index.js
CHANGED
|
@@ -39,11 +39,14 @@ function buildAuditPdf(pdfOptions, data) {
|
|
|
39
39
|
entity,
|
|
40
40
|
timezone
|
|
41
41
|
} = data;
|
|
42
|
+
const {
|
|
43
|
+
flags = {}
|
|
44
|
+
} = pdfOptions;
|
|
42
45
|
const sequenceId = entity.sequenceId;
|
|
43
46
|
const timestamp = entity.createdAt;
|
|
44
47
|
const title = entity.title || 'Unknown';
|
|
45
48
|
const fileTitle = `Audit Report - ${title}`;
|
|
46
|
-
return generateContent(data).then(content => (0, _helpers.generateDefinition)({
|
|
49
|
+
return generateContent(data, flags).then(content => (0, _helpers.generateDefinition)({
|
|
47
50
|
content,
|
|
48
51
|
fileTitle,
|
|
49
52
|
sequenceId,
|
|
@@ -59,9 +62,6 @@ function generateContent(data) {
|
|
|
59
62
|
const {
|
|
60
63
|
entity
|
|
61
64
|
} = data;
|
|
62
|
-
console.log('GENERATE AUDIT CONTENT:', JSON.stringify({
|
|
63
|
-
data
|
|
64
|
-
}, null, 2));
|
|
65
65
|
const {
|
|
66
66
|
followUps = [],
|
|
67
67
|
footerFields = {},
|
|
@@ -72,9 +72,6 @@ function generateContent(data) {
|
|
|
72
72
|
} = entity;
|
|
73
73
|
const timezone = entity?.timezone || data?.timezone || 'UTC';
|
|
74
74
|
const entityDetails = (0, _helpers2.getAuditEntryDetails)(data);
|
|
75
|
-
console.log({
|
|
76
|
-
entryDetails: entityDetails
|
|
77
|
-
});
|
|
78
75
|
const {
|
|
79
76
|
gpsText,
|
|
80
77
|
groupedData,
|
|
@@ -215,6 +212,6 @@ function generateContent(data) {
|
|
|
215
212
|
footerTemplate,
|
|
216
213
|
headerTemplate
|
|
217
214
|
}) => [titleTable, followUpItems, ...auditItemsTitle, ...headerTemplate, ...entry, hLineTop, totalScoreTable, hLineBottom, ...footerTemplate]).catch(err => {
|
|
218
|
-
throw new Error(`GenerateContentError: ${err}`);
|
|
215
|
+
throw new Error(`GenerateContentError: ${err.message}`);
|
|
219
216
|
});
|
|
220
217
|
}
|
|
@@ -11,7 +11,7 @@ var s3 = new AWS.S3({
|
|
|
11
11
|
});
|
|
12
12
|
export var fetchImageForPdfGeneratorService = /*#__PURE__*/function () {
|
|
13
13
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
|
|
14
|
-
var urlMatch, applicationId,
|
|
14
|
+
var urlMatch, applicationId, _parseUrlString, path, queryString, searchParamsObject, transformedBucketImagePath, alreadyTransformedImage, fullDataUrl, transformerResponse, statusCode, _fullDataUrl, redirectLocation, newlyTransformedImage, _fullDataUrl2, _t;
|
|
15
15
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
16
16
|
while (1) switch (_context.prev = _context.next) {
|
|
17
17
|
case 0:
|
|
@@ -30,11 +30,12 @@ export var fetchImageForPdfGeneratorService = /*#__PURE__*/function () {
|
|
|
30
30
|
}
|
|
31
31
|
throw new Error('Requestor has insufficient permissions');
|
|
32
32
|
case 2:
|
|
33
|
-
|
|
33
|
+
_parseUrlString = parseUrlString(url), path = _parseUrlString.path, queryString = _parseUrlString.queryString, searchParamsObject = _parseUrlString.searchParamsObject;
|
|
34
|
+
transformedBucketImagePath = path + (queryString ? "/".concat(queryString) : '');
|
|
34
35
|
_context.next = 3;
|
|
35
36
|
return fetchResourceFromS3({
|
|
36
|
-
bucketName:
|
|
37
|
-
key:
|
|
37
|
+
bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,
|
|
38
|
+
key: transformedBucketImagePath
|
|
38
39
|
});
|
|
39
40
|
case 3:
|
|
40
41
|
alreadyTransformedImage = _context.sent;
|
|
@@ -44,13 +45,12 @@ export var fetchImageForPdfGeneratorService = /*#__PURE__*/function () {
|
|
|
44
45
|
}
|
|
45
46
|
fullDataUrl = formatBase64Image({
|
|
46
47
|
base64String: alreadyTransformedImage.body.toString('base64'),
|
|
47
|
-
key:
|
|
48
|
+
key: transformedBucketImagePath
|
|
48
49
|
});
|
|
49
50
|
return _context.abrupt("return", fullDataUrl);
|
|
50
51
|
case 4:
|
|
51
|
-
keyWithoutTransformations = "/".concat(keyWithTransformations.split('?')[0]);
|
|
52
52
|
_context.next = 5;
|
|
53
|
-
return requestImageTransformation(
|
|
53
|
+
return requestImageTransformation("/".concat(path), searchParamsObject);
|
|
54
54
|
case 5:
|
|
55
55
|
transformerResponse = _context.sent;
|
|
56
56
|
statusCode = transformerResponse.statusCode;
|
|
@@ -61,31 +61,31 @@ export var fetchImageForPdfGeneratorService = /*#__PURE__*/function () {
|
|
|
61
61
|
console.debug('Image transformation successful');
|
|
62
62
|
_fullDataUrl = formatBase64Image({
|
|
63
63
|
base64String: transformerResponse.body.toString('base64'),
|
|
64
|
-
key:
|
|
64
|
+
key: url
|
|
65
65
|
});
|
|
66
66
|
return _context.abrupt("return", _fullDataUrl);
|
|
67
67
|
case 7:
|
|
68
68
|
console.debug('Image transformation successful but image is too big for lambda delivery, fetching directly from S3');
|
|
69
|
-
redirectLocation =
|
|
70
|
-
if (
|
|
71
|
-
_context.next =
|
|
69
|
+
redirectLocation = transformerResponse.headers.Location;
|
|
70
|
+
if (redirectLocation) {
|
|
71
|
+
_context.next = 8;
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
throw new Error('Redirect response received but no location provided');
|
|
75
|
+
case 8:
|
|
76
|
+
_context.next = 9;
|
|
75
77
|
return fetchResourceFromS3({
|
|
76
|
-
bucketName:
|
|
77
|
-
key:
|
|
78
|
+
bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,
|
|
79
|
+
key: transformedBucketImagePath
|
|
78
80
|
});
|
|
79
|
-
case
|
|
81
|
+
case 9:
|
|
80
82
|
newlyTransformedImage = _context.sent;
|
|
81
83
|
console.debug('Image successfully fetched from S3 at:', redirectLocation);
|
|
82
84
|
_fullDataUrl2 = formatBase64Image({
|
|
83
85
|
base64String: newlyTransformedImage.body.toString('base64'),
|
|
84
|
-
key:
|
|
86
|
+
key: transformedBucketImagePath
|
|
85
87
|
});
|
|
86
88
|
return _context.abrupt("return", _fullDataUrl2);
|
|
87
|
-
case 9:
|
|
88
|
-
throw new Error('Redirect response received but no location provided');
|
|
89
89
|
case 10:
|
|
90
90
|
throw new Error("Bad request to image transformer: ".concat(transformerResponse.body));
|
|
91
91
|
case 11:
|
|
@@ -106,27 +106,31 @@ export var fetchImageForPdfGeneratorService = /*#__PURE__*/function () {
|
|
|
106
106
|
return _ref.apply(this, arguments);
|
|
107
107
|
};
|
|
108
108
|
}();
|
|
109
|
-
export function requestImageTransformation(_x2) {
|
|
109
|
+
export function requestImageTransformation(_x2, _x3) {
|
|
110
110
|
return _requestImageTransformation.apply(this, arguments);
|
|
111
111
|
}
|
|
112
112
|
function _requestImageTransformation() {
|
|
113
|
-
_requestImageTransformation = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(
|
|
113
|
+
_requestImageTransformation = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(path, searchParamsObject) {
|
|
114
114
|
var lambdaEvent, params, result, response, errorMessage, _t2;
|
|
115
115
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
116
116
|
while (1) switch (_context2.prev = _context2.next) {
|
|
117
117
|
case 0:
|
|
118
|
-
if (
|
|
118
|
+
if (path) {
|
|
119
119
|
_context2.next = 1;
|
|
120
120
|
break;
|
|
121
121
|
}
|
|
122
122
|
throw new Error('Image Path is required for image transformation');
|
|
123
123
|
case 1:
|
|
124
|
-
console.debug('ImageTransformation: Invoking image transformer lambda for path:',
|
|
124
|
+
console.debug('ImageTransformation: Invoking image transformer lambda for path:', {
|
|
125
|
+
path: path,
|
|
126
|
+
searchParamsObject: searchParamsObject
|
|
127
|
+
});
|
|
125
128
|
lambdaEvent = {
|
|
129
|
+
queryStringParameters: searchParamsObject,
|
|
126
130
|
requestContext: {
|
|
127
131
|
http: {
|
|
128
132
|
method: 'GET',
|
|
129
|
-
path:
|
|
133
|
+
path: path
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
};
|
|
@@ -156,7 +160,7 @@ function _requestImageTransformation() {
|
|
|
156
160
|
}));
|
|
157
161
|
return _requestImageTransformation.apply(this, arguments);
|
|
158
162
|
}
|
|
159
|
-
export function fetchResourceFromS3(
|
|
163
|
+
export function fetchResourceFromS3(_x4) {
|
|
160
164
|
return _fetchResourceFromS.apply(this, arguments);
|
|
161
165
|
}
|
|
162
166
|
function _fetchResourceFromS() {
|
|
@@ -228,4 +232,33 @@ export function formatBase64Image(_ref3) {
|
|
|
228
232
|
}
|
|
229
233
|
return fullDataUrl;
|
|
230
234
|
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Parses a URL-like string into path and query parameters
|
|
238
|
+
* @param {string} urlString - String like "https://example.cloudfront.net/<applicationId>/<path>/filename.jpeg?width=100&height=100"
|
|
239
|
+
* @returns {Object} - Object with { path: string, queryString: string, searchParamsObject: Object }
|
|
240
|
+
* @example
|
|
241
|
+
* parseUrlString("https://example.cloudfront.net/abc123/folder/image.jpeg?width=100&height=100")
|
|
242
|
+
* // Returns: { path: "abc123/folder/image.jpeg", queryString: "width=100,t=456", searchParamsObject: { width: "100", height: "100" } }
|
|
243
|
+
*/
|
|
244
|
+
function parseUrlString(urlString) {
|
|
245
|
+
if (!urlString || typeof urlString !== 'string') {
|
|
246
|
+
throw new Error('URL string is required and must be a string');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Extract the path after the domain
|
|
250
|
+
var url = new URL(urlString);
|
|
251
|
+
var searchParamsObject = {};
|
|
252
|
+
url.searchParams.forEach(function (value, key) {
|
|
253
|
+
searchParamsObject[key] = value;
|
|
254
|
+
});
|
|
255
|
+
var queryString = url.searchParams.toString();
|
|
256
|
+
queryString = queryString ? queryString.replace(/&/g, ',') : '';
|
|
257
|
+
return {
|
|
258
|
+
path: url.pathname.substring(1),
|
|
259
|
+
// Remove leading '/'
|
|
260
|
+
queryString: queryString,
|
|
261
|
+
searchParamsObject: searchParamsObject
|
|
262
|
+
};
|
|
263
|
+
}
|
|
231
264
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["validateBase64Image","AWS","REGION","process","env","AWS_REGION","lambda","Lambda","region","s3","S3","fetchImageForPdfGeneratorService","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","url","urlMatch","applicationId","keyWithTransformations","alreadyTransformedImage","fullDataUrl","keyWithoutTransformations","transformerResponse","statusCode","_fullDataUrl","_transformerResponse$","redirectLocation","newlyTransformedImage","_fullDataUrl2","_t","wrap","_context","prev","next","console","debug","Error","match","substring","indexOf","fetchResourceFromS3","bucketName","concat","S3_BUCKET_IMAGE_TRANSFORMER_CACHE","key","sent","body","formatBase64Image","base64String","toString","abrupt","split","requestImageTransformation","headers","Location","stop","_x","apply","arguments","_x2","_requestImageTransformation","_callee2","lambdaEvent","params","result","response","errorMessage","_t2","_context2","requestContext","http","method","path","FunctionName","IMAGE_TRANSFORMER_ARN","InvocationType","Payload","JSON","stringify","invoke","promise","parse","message","error","_x3","_fetchResourceFromS","_callee3","_ref2","_t3","_context3","Bucket","Key","getObject","Body","contentType","ContentType","contentLength","ContentLength","lastModified","LastModified","etag","ETag","code","_ref3","imageType","toLowerCase","includes","base64Flag","isValid"],"sources":["../../../src/helpers/fetch-image-for-pdf-generator-service/index.js"],"sourcesContent":["import { validateBase64Image } from '../image-validators'\nimport AWS from 'aws-sdk'\nconst REGION = process.env.AWS_REGION\n\nconst lambda = new AWS.Lambda({\n region: REGION,\n})\nconst s3 = new AWS.S3({\n region: REGION,\n})\n\nexport const fetchImageForPdfGeneratorService = async function (url) {\n console.debug(\n 'Fetching image via CloudFront For Serverless Pdf Generator Service'\n )\n\n if (!url) {\n throw new Error('URL is required to fetch image for PDF generator service')\n }\n\n const urlMatch = url && url.match(/([a-f0-9]{24})\\//)\n const applicationId = urlMatch && urlMatch[1]\n\n if (!applicationId) {\n throw new Error('Requestor has insufficient permissions')\n }\n\n const keyWithTransformations = url.substring(url.indexOf(applicationId))\n\n const alreadyTransformedImage = await fetchResourceFromS3({\n bucketName: `${process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE}`,\n key: keyWithTransformations,\n })\n\n if (alreadyTransformedImage?.body) {\n const fullDataUrl = formatBase64Image({\n base64String: alreadyTransformedImage.body.toString('base64'),\n key: keyWithTransformations,\n })\n return fullDataUrl\n }\n\n const keyWithoutTransformations = `/${keyWithTransformations.split('?')[0]}`\n\n const transformerResponse = await requestImageTransformation(\n keyWithoutTransformations\n )\n\n const statusCode = transformerResponse.statusCode\n\n switch (statusCode) {\n case 200: {\n console.debug('Image transformation successful')\n\n const fullDataUrl = formatBase64Image({\n base64String: transformerResponse.body.toString('base64'),\n key: keyWithTransformations,\n })\n\n return fullDataUrl\n }\n case 302: {\n console.debug(\n 'Image transformation successful but image is too big for lambda delivery, fetching directly from S3'\n )\n const redirectLocation = transformerResponse.headers?.Location\n if (redirectLocation) {\n const newlyTransformedImage = await fetchResourceFromS3({\n bucketName: `${process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE}`,\n key: keyWithTransformations,\n })\n console.debug(\n 'Image successfully fetched from S3 at:',\n redirectLocation\n )\n\n const fullDataUrl = formatBase64Image({\n base64String: newlyTransformedImage.body.toString('base64'),\n key: keyWithTransformations,\n })\n\n return fullDataUrl\n }\n throw new Error('Redirect response received but no location provided')\n }\n case 400:\n throw new Error(\n `Bad request to image transformer: ${transformerResponse.body}`\n )\n case 403:\n throw new Error('Requested transformed image is too big')\n case 404:\n throw new Error('The requested image does not exist')\n case 500:\n throw new Error(\n `Image transformation failed: ${transformerResponse.body}`\n )\n default:\n throw new Error(\n `Unexpected response from image transformer: ${statusCode} - ${transformerResponse.body}`\n )\n }\n}\n\nexport async function requestImageTransformation(key) {\n if (!key) {\n throw new Error('Image Path is required for image transformation')\n }\n\n console.debug(\n 'ImageTransformation: Invoking image transformer lambda for path:',\n key\n )\n\n const lambdaEvent = {\n requestContext: {\n http: {\n method: 'GET',\n path: key,\n },\n },\n }\n\n const params = {\n FunctionName: process.env.IMAGE_TRANSFORMER_ARN,\n InvocationType: 'RequestResponse',\n Payload: JSON.stringify(lambdaEvent),\n }\n\n try {\n const result = await lambda.invoke(params).promise()\n\n const response = JSON.parse(result.Payload)\n\n return response\n } catch (error) {\n const errorMessage = `Failed to invoke image transformer lambda: ${error.message}`\n console.error(errorMessage, error)\n throw new Error(errorMessage)\n }\n}\n\nexport async function fetchResourceFromS3({ bucketName, key }) {\n console.debug(\n `Fetching resource from S3 Bucket: '${bucketName}' at path: '${key}'`\n )\n if (!bucketName || !key) {\n throw new Error(\n 'bucketName and key are required for S3 resource fetch ' +\n JSON.stringify({ bucketName, key })\n )\n }\n\n const params = {\n Bucket: bucketName,\n Key: key,\n }\n\n try {\n const result = await s3.getObject(params).promise()\n\n return {\n body: result.Body,\n contentType: result.ContentType,\n contentLength: result.ContentLength,\n lastModified: result.LastModified,\n etag: result.ETag,\n }\n } catch (error) {\n if (error.code !== 'NoSuchKey') {\n console.error('Failed to fetch image:', error)\n throw new Error(`Failed to fetch image: ${bucketName}/${key}`)\n }\n\n console.debug('Image not found in transformed bucket, invoking transformer')\n }\n}\n\nexport function formatBase64Image({ base64String, key }) {\n if (!key) {\n throw new Error('Key is required for image formatting')\n }\n\n const imageType = key.toLowerCase().includes('.png') ? 'png' : 'jpeg'\n const base64Flag = `data:image/${imageType};base64,`\n const fullDataUrl = `${base64Flag}${base64String}`\n\n // Validate the formatted data URL\n const isValid = validateBase64Image(fullDataUrl)\n if (!isValid) {\n throw new Error('InvalidImageError')\n }\n\n return fullDataUrl\n}\n"],"mappings":";;AAAA,SAASA,mBAAmB,QAAQ,qBAAqB;AACzD,OAAOC,GAAG,MAAM,SAAS;AACzB,IAAMC,MAAM,GAAGC,OAAO,CAACC,GAAG,CAACC,UAAU;AAErC,IAAMC,MAAM,GAAG,IAAIL,GAAG,CAACM,MAAM,CAAC;EAC5BC,MAAM,EAAEN;AACV,CAAC,CAAC;AACF,IAAMO,EAAE,GAAG,IAAIR,GAAG,CAACS,EAAE,CAAC;EACpBF,MAAM,EAAEN;AACV,CAAC,CAAC;AAEF,OAAO,IAAMS,gCAAgC;EAAA,IAAAC,IAAA,GAAAC,iBAAA,cAAAC,mBAAA,CAAAC,IAAA,CAAG,SAAAC,QAAgBC,GAAG;IAAA,IAAAC,QAAA,EAAAC,aAAA,EAAAC,sBAAA,EAAAC,uBAAA,EAAAC,WAAA,EAAAC,yBAAA,EAAAC,mBAAA,EAAAC,UAAA,EAAAC,YAAA,EAAAC,qBAAA,EAAAC,gBAAA,EAAAC,qBAAA,EAAAC,aAAA,EAAAC,EAAA;IAAA,OAAAjB,mBAAA,CAAAkB,IAAA,WAAAC,QAAA;MAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;QAAA;UACjEC,OAAO,CAACC,KAAK,CACX,oEACF,CAAC;UAAA,IAEIpB,GAAG;YAAAgB,QAAA,CAAAE,IAAA;YAAA;UAAA;UAAA,MACA,IAAIG,KAAK,CAAC,0DAA0D,CAAC;QAAA;UAGvEpB,QAAQ,GAAGD,GAAG,IAAIA,GAAG,CAACsB,KAAK,CAAC,kBAAkB,CAAC;UAC/CpB,aAAa,GAAGD,QAAQ,IAAIA,QAAQ,CAAC,CAAC,CAAC;UAAA,IAExCC,aAAa;YAAAc,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AiBA,CAAAwD,KAAA,EAAwB;EAAA,IAArBvD,YAAY,GAAAuD,KAAA,CAAZvD,YAAY;IAAEJ,GAAG,GAAA2D,KAAA,CAAH3D,GAAG;EACnD,IAAI,CAACA,GAAG,EAAE;IACR,MAAM,IAAIR,KAAK,CAAC,sCAAsC,CAAC;EACzD;EAEA,IAAMoE,SAAS,GAAG5D,GAAG,CAAC6D,WAAW,CAAC,CAAC,CAACC,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,MAAM;EACrE,IAAMC,UAAU,iBAAAjE,MAAA,CAAiB8D,SAAS,aAAU;EACpD,IAAMpF,WAAW,MAAAsB,MAAA,CAAMiE,UAAU,EAAAjE,MAAA,CAAGM,YAAY,CAAE;;EAElD;EACA,IAAM4D,OAAO,GAAG9G,mBAAmB,CAACsB,WAAW,CAAC;EAChD,IAAI,CAACwF,OAAO,EAAE;IACZ,MAAM,IAAIxE,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,OAAOhB,WAAW;AACpB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["validateBase64Image","AWS","REGION","process","env","AWS_REGION","lambda","Lambda","region","s3","S3","fetchImageForPdfGeneratorService","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","url","urlMatch","applicationId","_parseUrlString","path","queryString","searchParamsObject","transformedBucketImagePath","alreadyTransformedImage","fullDataUrl","transformerResponse","statusCode","_fullDataUrl","redirectLocation","newlyTransformedImage","_fullDataUrl2","_t","wrap","_context","prev","next","console","debug","Error","match","parseUrlString","concat","fetchResourceFromS3","bucketName","S3_BUCKET_IMAGE_TRANSFORMER_CACHE","key","sent","body","formatBase64Image","base64String","toString","abrupt","requestImageTransformation","headers","Location","stop","_x","apply","arguments","_x2","_x3","_requestImageTransformation","_callee2","lambdaEvent","params","result","response","errorMessage","_t2","_context2","queryStringParameters","requestContext","http","method","FunctionName","IMAGE_TRANSFORMER_ARN","InvocationType","Payload","JSON","stringify","invoke","promise","parse","message","error","_x4","_fetchResourceFromS","_callee3","_ref2","_t3","_context3","Bucket","Key","getObject","Body","contentType","ContentType","contentLength","ContentLength","lastModified","LastModified","etag","ETag","code","_ref3","imageType","toLowerCase","includes","base64Flag","isValid","urlString","URL","searchParams","forEach","value","replace","pathname","substring"],"sources":["../../../src/helpers/fetch-image-for-pdf-generator-service/index.js"],"sourcesContent":["import { validateBase64Image } from '../image-validators'\nimport AWS from 'aws-sdk'\nconst REGION = process.env.AWS_REGION\n\nconst lambda = new AWS.Lambda({\n region: REGION,\n})\nconst s3 = new AWS.S3({\n region: REGION,\n})\n\nexport const fetchImageForPdfGeneratorService = async function (url) {\n console.debug(\n 'Fetching image via CloudFront For Serverless Pdf Generator Service'\n )\n\n if (!url) {\n throw new Error('URL is required to fetch image for PDF generator service')\n }\n\n const urlMatch = url && url.match(/([a-f0-9]{24})\\//)\n const applicationId = urlMatch && urlMatch[1]\n\n if (!applicationId) {\n throw new Error('Requestor has insufficient permissions')\n }\n\n const { path, queryString, searchParamsObject } = parseUrlString(url)\n\n const transformedBucketImagePath =\n path + (queryString ? `/${queryString}` : '')\n\n const alreadyTransformedImage = await fetchResourceFromS3({\n bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,\n key: transformedBucketImagePath,\n })\n\n if (alreadyTransformedImage?.body) {\n const fullDataUrl = formatBase64Image({\n base64String: alreadyTransformedImage.body.toString('base64'),\n key: transformedBucketImagePath,\n })\n return fullDataUrl\n }\n\n const transformerResponse = await requestImageTransformation(\n `/${path}`,\n searchParamsObject\n )\n\n const statusCode = transformerResponse.statusCode\n\n switch (statusCode) {\n case 200: {\n console.debug('Image transformation successful')\n\n const fullDataUrl = formatBase64Image({\n base64String: transformerResponse.body.toString('base64'),\n key: url,\n })\n\n return fullDataUrl\n }\n case 302: {\n console.debug(\n 'Image transformation successful but image is too big for lambda delivery, fetching directly from S3'\n )\n const redirectLocation = transformerResponse.headers.Location\n\n if (!redirectLocation) {\n throw new Error('Redirect response received but no location provided')\n }\n const newlyTransformedImage = await fetchResourceFromS3({\n bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,\n key: transformedBucketImagePath,\n })\n console.debug('Image successfully fetched from S3 at:', redirectLocation)\n\n const fullDataUrl = formatBase64Image({\n base64String: newlyTransformedImage.body.toString('base64'),\n key: transformedBucketImagePath,\n })\n\n return fullDataUrl\n }\n case 400:\n throw new Error(\n `Bad request to image transformer: ${transformerResponse.body}`\n )\n case 403:\n throw new Error('Requested transformed image is too big')\n case 404:\n throw new Error('The requested image does not exist')\n case 500:\n throw new Error(\n `Image transformation failed: ${transformerResponse.body}`\n )\n default:\n throw new Error(\n `Unexpected response from image transformer: ${statusCode} - ${transformerResponse.body}`\n )\n }\n}\n\nexport async function requestImageTransformation(path, searchParamsObject) {\n if (!path) {\n throw new Error('Image Path is required for image transformation')\n }\n\n console.debug(\n 'ImageTransformation: Invoking image transformer lambda for path:',\n { path, searchParamsObject }\n )\n\n const lambdaEvent = {\n queryStringParameters: searchParamsObject,\n requestContext: {\n http: {\n method: 'GET',\n path,\n },\n },\n }\n\n const params = {\n FunctionName: process.env.IMAGE_TRANSFORMER_ARN,\n InvocationType: 'RequestResponse',\n Payload: JSON.stringify(lambdaEvent),\n }\n\n try {\n const result = await lambda.invoke(params).promise()\n\n const response = JSON.parse(result.Payload)\n\n return response\n } catch (error) {\n const errorMessage = `Failed to invoke image transformer lambda: ${error.message}`\n console.error(errorMessage, error)\n throw new Error(errorMessage)\n }\n}\n\nexport async function fetchResourceFromS3({ bucketName, key }) {\n console.debug(\n `Fetching resource from S3 Bucket: '${bucketName}' at path: '${key}'`\n )\n if (!bucketName || !key) {\n throw new Error(\n 'bucketName and key are required for S3 resource fetch ' +\n JSON.stringify({ bucketName, key })\n )\n }\n\n const params = {\n Bucket: bucketName,\n Key: key,\n }\n\n try {\n const result = await s3.getObject(params).promise()\n\n return {\n body: result.Body,\n contentType: result.ContentType,\n contentLength: result.ContentLength,\n lastModified: result.LastModified,\n etag: result.ETag,\n }\n } catch (error) {\n if (error.code !== 'NoSuchKey') {\n console.error('Failed to fetch image:', error)\n throw new Error(`Failed to fetch image: ${bucketName}/${key}`)\n }\n\n console.debug('Image not found in transformed bucket, invoking transformer')\n }\n}\n\nexport function formatBase64Image({ base64String, key }) {\n if (!key) {\n throw new Error('Key is required for image formatting')\n }\n\n const imageType = key.toLowerCase().includes('.png') ? 'png' : 'jpeg'\n const base64Flag = `data:image/${imageType};base64,`\n const fullDataUrl = `${base64Flag}${base64String}`\n\n // Validate the formatted data URL\n const isValid = validateBase64Image(fullDataUrl)\n if (!isValid) {\n throw new Error('InvalidImageError')\n }\n\n return fullDataUrl\n}\n\n/**\n * Parses a URL-like string into path and query parameters\n * @param {string} urlString - String like \"https://example.cloudfront.net/<applicationId>/<path>/filename.jpeg?width=100&height=100\"\n * @returns {Object} - Object with { path: string, queryString: string, searchParamsObject: Object }\n * @example\n * parseUrlString(\"https://example.cloudfront.net/abc123/folder/image.jpeg?width=100&height=100\")\n * // Returns: { path: \"abc123/folder/image.jpeg\", queryString: \"width=100,t=456\", searchParamsObject: { width: \"100\", height: \"100\" } }\n */\nfunction parseUrlString(urlString) {\n if (!urlString || typeof urlString !== 'string') {\n throw new Error('URL string is required and must be a string')\n }\n\n // Extract the path after the domain\n const url = new URL(urlString)\n\n let searchParamsObject = {}\n url.searchParams.forEach((value, key) => {\n searchParamsObject[key] = value\n })\n\n let queryString = url.searchParams.toString()\n queryString = queryString ? queryString.replace(/&/g, ',') : ''\n\n return {\n path: url.pathname.substring(1), // Remove leading '/'\n queryString,\n searchParamsObject,\n }\n}\n"],"mappings":";;AAAA,SAASA,mBAAmB,QAAQ,qBAAqB;AACzD,OAAOC,GAAG,MAAM,SAAS;AACzB,IAAMC,MAAM,GAAGC,OAAO,CAACC,GAAG,CAACC,UAAU;AAErC,IAAMC,MAAM,GAAG,IAAIL,GAAG,CAACM,MAAM,CAAC;EAC5BC,MAAM,EAAEN;AACV,CAAC,CAAC;AACF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35,13 @@ import { getAuditEntryDetails } from '../../helpers';
|
|
|
35
35
|
export function buildAuditPdf(pdfOptions, data) {
|
|
36
36
|
var entity = data.entity,
|
|
37
37
|
timezone = data.timezone;
|
|
38
|
+
var _pdfOptions$flags = pdfOptions.flags,
|
|
39
|
+
flags = _pdfOptions$flags === void 0 ? {} : _pdfOptions$flags;
|
|
38
40
|
var sequenceId = entity.sequenceId;
|
|
39
41
|
var timestamp = entity.createdAt;
|
|
40
42
|
var title = entity.title || 'Unknown';
|
|
41
43
|
var fileTitle = "Audit Report - ".concat(title);
|
|
42
|
-
return generateContent(data).then(function (content) {
|
|
44
|
+
return generateContent(data, flags).then(function (content) {
|
|
43
45
|
return generateDefinition(_objectSpread({
|
|
44
46
|
content: content,
|
|
45
47
|
fileTitle: fileTitle,
|
|
@@ -54,9 +56,6 @@ export function buildAuditPdf(pdfOptions, data) {
|
|
|
54
56
|
}
|
|
55
57
|
function generateContent(data) {
|
|
56
58
|
var entity = data.entity;
|
|
57
|
-
console.log('GENERATE AUDIT CONTENT:', JSON.stringify({
|
|
58
|
-
data: data
|
|
59
|
-
}, null, 2));
|
|
60
59
|
var _entity$followUps = entity.followUps,
|
|
61
60
|
followUps = _entity$followUps === void 0 ? [] : _entity$followUps,
|
|
62
61
|
_entity$footerFields = entity.footerFields,
|
|
@@ -71,9 +70,6 @@ function generateContent(data) {
|
|
|
71
70
|
title = _entity$title === void 0 ? 'Unknown' : _entity$title;
|
|
72
71
|
var timezone = (entity === null || entity === void 0 ? void 0 : entity.timezone) || (data === null || data === void 0 ? void 0 : data.timezone) || 'UTC';
|
|
73
72
|
var entityDetails = getAuditEntryDetails(data);
|
|
74
|
-
console.log({
|
|
75
|
-
entryDetails: entityDetails
|
|
76
|
-
});
|
|
77
73
|
var gpsText = entityDetails.gpsText,
|
|
78
74
|
groupedData = entityDetails.groupedData,
|
|
79
75
|
locationText = entityDetails.locationText,
|
|
@@ -213,7 +209,7 @@ function generateContent(data) {
|
|
|
213
209
|
headerTemplate = _ref.headerTemplate;
|
|
214
210
|
return [titleTable, followUpItems].concat(auditItemsTitle, _toConsumableArray(headerTemplate), _toConsumableArray(entry), [hLineTop, totalScoreTable, hLineBottom], _toConsumableArray(footerTemplate));
|
|
215
211
|
}).catch(function (err) {
|
|
216
|
-
throw new Error("GenerateContentError: ".concat(err));
|
|
212
|
+
throw new Error("GenerateContentError: ".concat(err.message));
|
|
217
213
|
});
|
|
218
214
|
}
|
|
219
215
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Promise","isEmpty","round","moment","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","catch","err","Error","message","console","log","JSON","stringify","_entity$followUps","followUps","_entity$footerFields","footerFields","_entity$gps","gps","_entity$headerFields","headerFields","_entity$score","score","_entity$title","entityDetails","entryDetails","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","submittedAtInTimezone","submittedAt","tz","format","showSimplifiedDuration","push","startedAtInTimezone","startedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","settings","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props","_ref","_toConsumableArray"],"sources":["../../../src/pdf/audit/index.js"],"sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data)\n .then((content) =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch((err) => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data) {\n const { entity } = data\n console.log('GENERATE AUDIT CONTENT:', JSON.stringify({ data }, null, 2))\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n title = 'Unknown',\n } = entity\n\n const timezone = entity?.timezone || data?.timezone || 'UTC'\n const entityDetails = getAuditEntryDetails(data)\n\n console.log({ entryDetails: entityDetails })\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${\n locationText || gpsText\n } - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n headerAddress = text(address, { style: 'small' })\n\n const truncatedTargetPercent = round(target, 2)\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n if (entity.showSimplifiedDuration) {\n body.push([submittedAt, dummyColumn])\n } else {\n const startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt).tz(timezone).format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays()).toString().padStart(2, '0')\n const hours = Math.floor(momentDuration.hours()).toString().padStart(2, '0')\n const minutes = momentDuration.minutes().toString().padStart(2, '0')\n const seconds = momentDuration.seconds().toString().padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n colSpan: 2,\n style: 'small',\n }\n )\n\n body.push([startedAt, dummyColumn])\n body.push([submittedAt, dummyColumn])\n body.push([formDuration, dummyColumn])\n }\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n margin: [0, 0, 0, 30],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const followUpItems = buildAuditFollowUps(followUps, { timezone })\n\n const promises = {\n entry: buildAuditContent(groupedData.items, data.settings),\n\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n followUpItems,\n ...auditItemsTitle,\n ...headerTemplate,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch((err) => {\n throw new Error(`GenerateContentError: ${err}`)\n })\n}\n"],"mappings":";;;;AAAA,OAAOA,OAAO,MAAM,UAAU;AAC9B,SAASC,OAAO,EAAEC,KAAK,QAAQ,QAAQ;AACvC,OAAOC,MAAM,MAAM,iBAAiB;AAEpC,SACEC,iBAAiB,EACjBC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,cAAc,EACdC,IAAI,EACJC,cAAc,QACT,YAAY;AACnB,SAASC,oBAAoB,QAAQ,eAAe;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,UAAU,EAAEC,IAAI,EAAE;EAC9C,IAAQC,MAAM,GAAeD,IAAI,CAAzBC,MAAM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e,EAAAK,kBAAA,CACfN,cAAc,GAAAM,kBAAA,CACdX,KAAK,IACRJ,QAAQ,EACRD,eAAe,EACfE,WAAW,GAAAc,kBAAA,CACRR,cAAc;EAAA,CAClB,CAAC,CACD5F,KAAK,CAAC,UAACC,GAAG,EAAK;IACd,MAAM,IAAIC,KAAK,0BAAAR,MAAA,CAA0BO,GAAG,CAAE,CAAC;EACjD,CAAC,CAAC;AACN","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Promise","isEmpty","round","moment","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","_pdfOptions$flags","flags","sequenceId","timestamp","createdAt","title","fileTitle","concat","generateContent","then","content","_objectSpread","type","catch","err","Error","message","_entity$followUps","followUps","_entity$footerFields","footerFields","_entity$gps","gps","_entity$headerFields","headerFields","_entity$score","score","_entity$title","entityDetails","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","submittedAtInTimezone","submittedAt","tz","format","showSimplifiedDuration","push","startedAtInTimezone","startedAt","momentDuration","duration","Math","abs","formDuration","days","floor","asDays","toString","padStart","hours","minutes","seconds","formattedFormDuration","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","settings","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props","_ref","_toConsumableArray"],"sources":["../../../src/pdf/audit/index.js"],"sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\nimport moment from 'moment-timezone'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n const { flags = {} } = pdfOptions\n\n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data, flags)\n .then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch(err => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data) {\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n title = 'Unknown',\n } = entity\n\n const timezone = entity?.timezone || data?.timezone || 'UTC'\n const entityDetails = getAuditEntryDetails(data)\n\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n headerAddress = text(address, { style: 'small' })\n\n const truncatedTargetPercent = round(target, 2)\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n if (entity.showSimplifiedDuration) {\n body.push([submittedAt, dummyColumn])\n } else {\n const startedAtInTimezone = entity.startedAt\n ? moment(entity.startedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const startedAt = text(`Started: ${startedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const submittedAtInTimezone = entity.submittedAt\n ? moment(entity.submittedAt)\n .tz(timezone)\n .format('YYYY-MM-DD HH:mm:ss z')\n : 'Not recorded'\n const submittedAt = text(`Submitted: ${submittedAtInTimezone}`, {\n colSpan: 2,\n style: 'small',\n })\n\n const momentDuration = moment.duration(Math.abs(entity.formDuration))\n const days = Math.floor(momentDuration.asDays())\n .toString()\n .padStart(2, '0')\n const hours = Math.floor(momentDuration.hours())\n .toString()\n .padStart(2, '0')\n const minutes = momentDuration\n .minutes()\n .toString()\n .padStart(2, '0')\n const seconds = momentDuration\n .seconds()\n .toString()\n .padStart(2, '0')\n const formattedFormDuration = entity.formDuration\n ? `${\n entity.formDuration < 0 ? '-' : ''\n }${days}:${hours}:${minutes}:${seconds}`\n : 'Not recorded'\n const formDuration = text(\n `Form Duration (DD:HH:MM:SS): ${formattedFormDuration}`,\n {\n colSpan: 2,\n style: 'small',\n }\n )\n\n body.push([startedAt, dummyColumn])\n body.push([submittedAt, dummyColumn])\n body.push([formDuration, dummyColumn])\n }\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n margin: [0, 0, 0, 30],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const followUpItems = buildAuditFollowUps(followUps, { timezone })\n\n const promises = {\n entry: buildAuditContent(groupedData.items, data.settings),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n followUpItems,\n ...auditItemsTitle,\n ...headerTemplate,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"mappings":";;;;AAAA,OAAOA,OAAO,MAAM,UAAU;AAC9B,SAASC,OAAO,EAAEC,KAAK,QAAQ,QAAQ;AACvC,OAAOC,MAAM,MAAM,iBAAiB;AAEpC,SACEC,iBAAiB,EACjBC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,cAAc,EACdC,IAAI,EACJC,cAAc,QACT,YAAY;AACnB,SAASC,oBAAoB,QAAQ,eAAe;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAACC,UAAU,EAAEC,IAAI,EAAE;EAC9C,IAAQC,MAAM,GAAeD,IAAI,CAAzBC,MAAM;IAAEC,QAAQ,GAAKF,IAAI,CAAjBE,QAAQ;EACxB,IAAAC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A,CAClB,CAAC,CACDvF,KAAK,CAAC,UAAAC,GAAG,EAAI;IACZ,MAAM,IAAIC,KAAK,0BAAAR,MAAA,CAA0BO,GAAG,CAACE,OAAO,CAAE,CAAC;EACzD,CAAC,CAAC;AACN","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lighthouse/common",
|
|
3
|
-
"version": "6.3.0
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -22,13 +22,12 @@
|
|
|
22
22
|
"build-storybook:html": "sb build -c .storybook-html",
|
|
23
23
|
"build-storybook:react": "sb build -c .storybook-react",
|
|
24
24
|
"test": "TZ=UTC vitest run",
|
|
25
|
+
"test:watch": "TZ=UTC vitest watch",
|
|
25
26
|
"test:ci": "yarn lint && yarn type-check && yarn test --coverage",
|
|
26
27
|
"type-check": "tsc --noEmit",
|
|
27
28
|
"type-check:watch": "yarn type-check --watch",
|
|
28
29
|
"validate:circleci": "circleci config validate -c .circleci/config.yml",
|
|
29
|
-
"version": "yarn build"
|
|
30
|
-
"watch:es": "nodemon --watch src --ext js,ts --exec \"yarn build:es\"",
|
|
31
|
-
"watch:node": "nodemon --watch src --ext js,ts --exec \"yarn build:node\""
|
|
30
|
+
"version": "yarn build"
|
|
32
31
|
},
|
|
33
32
|
"repository": {
|
|
34
33
|
"type": "git",
|