@lighthouse/common 6.5.0 → 6.6.0-canary.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/constants.js +7 -13
- package/dist/errors/DomainError.js +2 -4
- package/dist/errors/ValidationError.js +0 -8
- package/dist/errors/index.js +1 -5
- package/dist/helpers/build-fetch-url/index.js +0 -5
- package/dist/helpers/fetch-image/index.js +16 -32
- package/dist/helpers/fetch-image-for-pdf-generator-service/index.js +7 -40
- package/dist/helpers/fetch-image-for-web/index.js +0 -9
- package/dist/helpers/fetch-lighthouse-logo/index.js +2 -13
- package/dist/helpers/floatify/index.js +0 -1
- package/dist/helpers/get-assignees-full-names/index.js +0 -4
- package/dist/helpers/get-audit-entry-details/index.js +0 -3
- package/dist/helpers/get-audit-items-data/index.js +2 -6
- package/dist/helpers/get-geometry-geocoded-string/index.js +0 -3
- package/dist/helpers/get-issue-details/index.js +0 -7
- package/dist/helpers/get-job-details/index.js +0 -7
- package/dist/helpers/get-location-reference/index.js +18 -21
- package/dist/helpers/get-pretty-duration/index.js +0 -5
- package/dist/helpers/get-reference-details/index.js +0 -4
- package/dist/helpers/get-status-details/index.js +2 -9
- package/dist/helpers/get-task-entry-details/index.js +0 -3
- package/dist/helpers/get-timezone-abbr/index.js +0 -4
- package/dist/helpers/get-timezone-datetime/index.js +0 -5
- package/dist/helpers/get-user-full-name/index.js +0 -1
- package/dist/helpers/get-value-as-percentage/index.js +0 -1
- package/dist/helpers/image-validators/index.js +8 -9
- package/dist/helpers/index.js +16 -33
- package/dist/images/index.js +5 -9
- package/dist/index.js +4 -20
- package/dist/pdf/activity-report/index.js +41 -62
- package/dist/pdf/audit/index.js +0 -14
- package/dist/pdf/helpers/build-audit-content/index.js +4 -15
- package/dist/pdf/helpers/build-audit-follow-ups/index.js +4 -14
- package/dist/pdf/helpers/build-location-scans-content/index.js +4 -17
- package/dist/pdf/helpers/build-template-content/index.js +5 -14
- package/dist/pdf/helpers/default-footer/index.js +2 -3
- package/dist/pdf/helpers/default-header/index.js +0 -2
- package/dist/pdf/helpers/default-styles/index.js +2 -3
- package/dist/pdf/helpers/fields/index.js +21 -51
- package/dist/pdf/helpers/format-location-address/index.js +0 -3
- package/dist/pdf/helpers/generate-definition/index.js +0 -12
- package/dist/pdf/helpers/horizontal-line/index.js +0 -1
- package/dist/pdf/helpers/html-transformer/index.js +11 -23
- package/dist/pdf/helpers/index.js +40 -55
- package/dist/pdf/helpers/parse-value/index.js +2 -6
- package/dist/pdf/helpers/table/index.js +13 -31
- package/dist/pdf/helpers/text/index.js +0 -1
- package/dist/pdf/icons/index.js +3 -5
- package/dist/pdf/index.js +4 -10
- package/dist/pdf/issue/index.js +17 -16
- package/dist/pdf/job/index.js +1 -13
- package/dist/pdf/shift-report/emptyFixtures.js +4 -6
- package/dist/pdf/shift-report/index.js +2 -25
- package/dist/pdf/task/index.js +0 -13
- package/dist/scheduling/generators/index.js +0 -6
- package/dist/scheduling/generators/occurrenceIntervalsGenerator.js +1 -6
- package/dist/scheduling/generators/scheduleIntervalsGenerator.js +0 -5
- package/dist/scheduling/generators/serviceIntervalsGenerator.js +13 -27
- package/dist/scheduling/helpers/convertToTimezone.js +1 -6
- package/dist/scheduling/helpers/generateNonRepeatingSchedule.js +3 -9
- package/dist/scheduling/helpers/generateRepeatingSchedule.js +11 -18
- package/dist/scheduling/helpers/generateScheduleEnd.js +2 -8
- package/dist/scheduling/helpers/hasValidStartAndEnd.js +0 -6
- package/dist/scheduling/helpers/index.js +0 -28
- package/dist/scheduling/helpers/intervalCovers.js +0 -1
- package/dist/scheduling/helpers/intervalIntersectsEnd.js +0 -1
- package/dist/scheduling/helpers/intervalIntersectsStart.js +0 -1
- package/dist/scheduling/helpers/intervalOnlyIntersectsEnd.js +1 -3
- package/dist/scheduling/helpers/intervalOnlyIntersectsStart.js +0 -3
- package/dist/scheduling/helpers/intervalOutside.js +0 -1
- package/dist/scheduling/helpers/intervalWithin.js +0 -1
- package/dist/scheduling/helpers/mergeIntervals.js +0 -4
- package/dist/scheduling/helpers/splitIntervals.js +0 -3
- package/dist/scheduling/index.js +0 -6
- package/dist/scheduling/scheduling.types.js +10 -18
- package/dist/scheduling/strategies/getNext.js +2 -13
- package/dist/scheduling/strategies/getNextExactDateOfMonth.js +0 -12
- package/dist/scheduling/strategies/getNextLastDayOfMonth.js +0 -10
- package/dist/scheduling/strategies/getNextLastWeekdayOfMonth.js +0 -11
- package/dist/scheduling/strategies/getNextNoRepeat.js +0 -7
- package/dist/scheduling/strategies/getNextWeekday.js +0 -10
- package/dist/scheduling/strategies/getNextXDayOfXWeekOfMonth.js +0 -12
- package/dist/scheduling/strategies/index.js +0 -14
- package/dist/schema/index.js +0 -2
- package/dist/schema/schema.js +2 -7
- package/dist/service-hours/__helpers__/calculate-hours.js +4 -13
- package/dist/service-hours/__helpers__/isOpen.js +0 -9
- package/dist/service-hours/index.js +0 -4
- package/dist/service-hours/schema.js +20 -43
- package/lib/constants.js.map +1 -1
- package/lib/errors/DomainError.js +11 -47
- package/lib/errors/DomainError.js.map +1 -1
- package/lib/errors/ValidationError.js +15 -52
- package/lib/errors/ValidationError.js.map +1 -1
- package/lib/errors/index.js.map +1 -1
- package/lib/helpers/build-fetch-url/index.js +14 -20
- package/lib/helpers/build-fetch-url/index.js.map +1 -1
- package/lib/helpers/fetch-image/index.js +20 -27
- package/lib/helpers/fetch-image/index.js.map +1 -1
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js +187 -239
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js.map +1 -1
- package/lib/helpers/fetch-image-for-web/index.js +50 -66
- package/lib/helpers/fetch-image-for-web/index.js.map +1 -1
- package/lib/helpers/fetch-lighthouse-logo/index.js +47 -59
- package/lib/helpers/fetch-lighthouse-logo/index.js.map +1 -1
- package/lib/helpers/floatify/index.js.map +1 -1
- package/lib/helpers/get-assignees-full-names/index.js +0 -1
- package/lib/helpers/get-assignees-full-names/index.js.map +1 -1
- package/lib/helpers/get-audit-entry-details/index.js +8 -8
- package/lib/helpers/get-audit-entry-details/index.js.map +1 -1
- package/lib/helpers/get-audit-items-data/index.js +16 -19
- package/lib/helpers/get-audit-items-data/index.js.map +1 -1
- package/lib/helpers/get-geometry-geocoded-string/index.js.map +1 -1
- package/lib/helpers/get-issue-details/index.js +11 -11
- package/lib/helpers/get-issue-details/index.js.map +1 -1
- package/lib/helpers/get-job-details/index.js +12 -12
- package/lib/helpers/get-job-details/index.js.map +1 -1
- package/lib/helpers/get-location-reference/index.js +32 -36
- package/lib/helpers/get-location-reference/index.js.map +1 -1
- package/lib/helpers/get-pretty-duration/index.js +0 -4
- package/lib/helpers/get-pretty-duration/index.js.map +1 -1
- package/lib/helpers/get-reference-details/index.js +1 -3
- package/lib/helpers/get-reference-details/index.js.map +1 -1
- package/lib/helpers/get-status-details/index.js +0 -4
- package/lib/helpers/get-status-details/index.js.map +1 -1
- package/lib/helpers/get-task-entry-details/index.js +5 -5
- package/lib/helpers/get-task-entry-details/index.js.map +1 -1
- package/lib/helpers/get-timezone-abbr/index.js.map +1 -1
- package/lib/helpers/get-timezone-datetime/index.js +6 -6
- package/lib/helpers/get-timezone-datetime/index.js.map +1 -1
- package/lib/helpers/get-user-full-name/index.js.map +1 -1
- package/lib/helpers/get-value-as-percentage/index.js.map +1 -1
- package/lib/helpers/image-validators/index.js +8 -7
- package/lib/helpers/image-validators/index.js.map +1 -1
- package/lib/helpers/index.js.map +1 -1
- package/lib/images/index.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/pdf/activity-report/index.js +360 -416
- package/lib/pdf/activity-report/index.js.map +1 -1
- package/lib/pdf/audit/index.js +25 -36
- package/lib/pdf/audit/index.js.map +1 -1
- package/lib/pdf/fonts/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-content/index.js +3 -5
- package/lib/pdf/helpers/build-audit-content/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-follow-ups/index.js +5 -12
- package/lib/pdf/helpers/build-audit-follow-ups/index.js.map +1 -1
- package/lib/pdf/helpers/build-location-scans-content/index.js +4 -9
- package/lib/pdf/helpers/build-location-scans-content/index.js.map +1 -1
- package/lib/pdf/helpers/build-template-content/index.js +7 -9
- package/lib/pdf/helpers/build-template-content/index.js.map +1 -1
- package/lib/pdf/helpers/default-footer/index.js +9 -8
- package/lib/pdf/helpers/default-footer/index.js.map +1 -1
- package/lib/pdf/helpers/default-header/index.js +5 -5
- package/lib/pdf/helpers/default-header/index.js.map +1 -1
- package/lib/pdf/helpers/default-styles/index.js.map +1 -1
- package/lib/pdf/helpers/fields/index.js +48 -81
- package/lib/pdf/helpers/fields/index.js.map +1 -1
- package/lib/pdf/helpers/format-location-address/index.js.map +1 -1
- package/lib/pdf/helpers/generate-definition/index.js +22 -29
- package/lib/pdf/helpers/generate-definition/index.js.map +1 -1
- package/lib/pdf/helpers/horizontal-line/index.js +1 -1
- package/lib/pdf/helpers/horizontal-line/index.js.map +1 -1
- package/lib/pdf/helpers/html-transformer/index.js +19 -30
- package/lib/pdf/helpers/html-transformer/index.js.map +1 -1
- package/lib/pdf/helpers/index.js.map +1 -1
- package/lib/pdf/helpers/parse-value/index.js +2 -4
- package/lib/pdf/helpers/parse-value/index.js.map +1 -1
- package/lib/pdf/helpers/table/index.js +78 -84
- package/lib/pdf/helpers/table/index.js.map +1 -1
- package/lib/pdf/helpers/text/index.js +2 -5
- package/lib/pdf/helpers/text/index.js.map +1 -1
- package/lib/pdf/icons/index.js.map +1 -1
- package/lib/pdf/index.js.map +1 -1
- package/lib/pdf/issue/index.js +36 -30
- package/lib/pdf/issue/index.js.map +1 -1
- package/lib/pdf/job/index.js +12 -19
- package/lib/pdf/job/index.js.map +1 -1
- package/lib/pdf/shift-report/emptyFixtures.js.map +1 -1
- package/lib/pdf/shift-report/index.js +308 -374
- package/lib/pdf/shift-report/index.js.map +1 -1
- package/lib/pdf/task/index.js +11 -19
- package/lib/pdf/task/index.js.map +1 -1
- package/lib/scheduling/generators/index.js.map +1 -1
- package/lib/scheduling/generators/occurrenceIntervalsGenerator.js +27 -38
- package/lib/scheduling/generators/occurrenceIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/generators/scheduleIntervalsGenerator.js +19 -30
- package/lib/scheduling/generators/scheduleIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/generators/serviceIntervalsGenerator.js +139 -181
- package/lib/scheduling/generators/serviceIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/helpers/convertToTimezone.js +1 -1
- package/lib/scheduling/helpers/convertToTimezone.js.map +1 -1
- package/lib/scheduling/helpers/generateNonRepeatingSchedule.js +84 -124
- package/lib/scheduling/helpers/generateNonRepeatingSchedule.js.map +1 -1
- package/lib/scheduling/helpers/generateRepeatingSchedule.js +107 -175
- package/lib/scheduling/helpers/generateRepeatingSchedule.js.map +1 -1
- package/lib/scheduling/helpers/generateScheduleEnd.js +6 -6
- package/lib/scheduling/helpers/generateScheduleEnd.js.map +1 -1
- package/lib/scheduling/helpers/hasValidStartAndEnd.js +1 -2
- package/lib/scheduling/helpers/hasValidStartAndEnd.js.map +1 -1
- package/lib/scheduling/helpers/index.js.map +1 -1
- package/lib/scheduling/helpers/intervalCovers.js.map +1 -1
- package/lib/scheduling/helpers/intervalIntersectsEnd.js.map +1 -1
- package/lib/scheduling/helpers/intervalIntersectsStart.js.map +1 -1
- package/lib/scheduling/helpers/intervalOnlyIntersectsEnd.js +1 -0
- package/lib/scheduling/helpers/intervalOnlyIntersectsEnd.js.map +1 -1
- package/lib/scheduling/helpers/intervalOnlyIntersectsStart.js +1 -1
- package/lib/scheduling/helpers/intervalOnlyIntersectsStart.js.map +1 -1
- package/lib/scheduling/helpers/intervalOutside.js.map +1 -1
- package/lib/scheduling/helpers/intervalWithin.js.map +1 -1
- package/lib/scheduling/helpers/mergeIntervals.js +0 -3
- package/lib/scheduling/helpers/mergeIntervals.js.map +1 -1
- package/lib/scheduling/helpers/splitIntervals.js +1 -1
- package/lib/scheduling/helpers/splitIntervals.js.map +1 -1
- package/lib/scheduling/index.js.map +1 -1
- package/lib/scheduling/scheduling.types.js +9 -14
- package/lib/scheduling/scheduling.types.js.map +1 -1
- package/lib/scheduling/strategies/getNext.js +22 -30
- package/lib/scheduling/strategies/getNext.js.map +1 -1
- package/lib/scheduling/strategies/getNextExactDateOfMonth.js +22 -31
- package/lib/scheduling/strategies/getNextExactDateOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextLastDayOfMonth.js +21 -28
- package/lib/scheduling/strategies/getNextLastDayOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextLastWeekdayOfMonth.js +21 -28
- package/lib/scheduling/strategies/getNextLastWeekdayOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextNoRepeat.js +15 -23
- package/lib/scheduling/strategies/getNextNoRepeat.js.map +1 -1
- package/lib/scheduling/strategies/getNextWeekday.js +43 -78
- package/lib/scheduling/strategies/getNextWeekday.js.map +1 -1
- package/lib/scheduling/strategies/getNextXDayOfXWeekOfMonth.js +21 -28
- package/lib/scheduling/strategies/getNextXDayOfXWeekOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/index.js.map +1 -1
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/schema.js +22 -30
- package/lib/schema/schema.js.map +1 -1
- package/lib/service-hours/__helpers__/calculate-hours.js +4 -13
- package/lib/service-hours/__helpers__/calculate-hours.js.map +1 -1
- package/lib/service-hours/__helpers__/isOpen.js +3 -7
- package/lib/service-hours/__helpers__/isOpen.js.map +1 -1
- package/lib/service-hours/index.js.map +1 -1
- package/lib/service-hours/schema.js +21 -36
- package/lib/service-hours/schema.js.map +1 -1
- package/package.json +1 -1
package/dist/constants.js
CHANGED
|
@@ -3,17 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.LIGHTHOUSE_LOGO_URL = exports.
|
|
6
|
+
exports.LIGHTHOUSE_LOGO_URL = exports.DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH = exports.DEFAULT_PAGE_SIZE = exports.DEFAULT_PAGE_ORIENTATION = exports.DEFAULT_PAGE_MARGINS = exports.DEFAULT_IMAGE_COLUMN_LENGTH = void 0;
|
|
7
7
|
// pdf
|
|
8
|
-
const DEFAULT_IMAGE_COLUMN_LENGTH = 2;
|
|
9
|
-
exports.
|
|
10
|
-
const
|
|
11
|
-
exports.
|
|
12
|
-
const
|
|
13
|
-
exports.
|
|
14
|
-
const DEFAULT_PAGE_ORIENTATION = 'portrait';
|
|
15
|
-
exports.DEFAULT_PAGE_ORIENTATION = DEFAULT_PAGE_ORIENTATION;
|
|
16
|
-
const DEFAULT_PAGE_SIZE = 'A4';
|
|
17
|
-
exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
|
|
18
|
-
const LIGHTHOUSE_LOGO_URL = 'https://assets-lighthouse-io.s3.amazonaws.com/img/lighthouse-color-logo-2023.png';
|
|
19
|
-
exports.LIGHTHOUSE_LOGO_URL = LIGHTHOUSE_LOGO_URL;
|
|
8
|
+
const DEFAULT_IMAGE_COLUMN_LENGTH = exports.DEFAULT_IMAGE_COLUMN_LENGTH = 2;
|
|
9
|
+
const DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH = exports.DEFAULT_SUMMARY_FIELDS_COLUMN_LENGTH = 3;
|
|
10
|
+
const DEFAULT_PAGE_MARGINS = exports.DEFAULT_PAGE_MARGINS = [60, 130, 60, 80];
|
|
11
|
+
const DEFAULT_PAGE_ORIENTATION = exports.DEFAULT_PAGE_ORIENTATION = 'portrait';
|
|
12
|
+
const DEFAULT_PAGE_SIZE = exports.DEFAULT_PAGE_SIZE = 'A4';
|
|
13
|
+
const LIGHTHOUSE_LOGO_URL = exports.LIGHTHOUSE_LOGO_URL = 'https://assets-lighthouse-io.s3.amazonaws.com/img/lighthouse-color-logo-2023.png';
|
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
// TODO is this universal?
|
|
9
8
|
class DomainError extends Error {
|
|
10
9
|
constructor(message) {
|
|
11
10
|
super(message);
|
|
12
|
-
this.name = this.constructor.name;
|
|
11
|
+
this.name = this.constructor.name;
|
|
13
12
|
|
|
13
|
+
// @ts-ignore support both node and browser environments
|
|
14
14
|
if (typeof Error.captureStackTrace === 'function') {
|
|
15
15
|
// @ts-ignore
|
|
16
16
|
Error.captureStackTrace(this, this.constructor);
|
|
@@ -18,7 +18,5 @@ class DomainError extends Error {
|
|
|
18
18
|
this.stack = new Error(message).stack;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
exports.default = DomainError;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _yup = require("yup");
|
|
11
|
-
|
|
12
9
|
var _DomainError = _interopRequireDefault(require("./DomainError"));
|
|
13
|
-
|
|
14
10
|
const DEFAULT_MESSAGE = 'The data you submitted was invalid. Please try again with valid data.';
|
|
15
|
-
|
|
16
11
|
class ValidationError extends _DomainError.default {
|
|
17
12
|
constructor({
|
|
18
13
|
data,
|
|
@@ -31,12 +26,9 @@ class ValidationError extends _DomainError.default {
|
|
|
31
26
|
this.status = 400;
|
|
32
27
|
return;
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
super(message);
|
|
36
30
|
this.data = data;
|
|
37
31
|
this.status = 400;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
exports.default = ValidationError;
|
package/dist/errors/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.isKnownError = isKnownError;
|
|
9
7
|
Object.defineProperty(exports, "DomainError", {
|
|
10
8
|
enumerable: true,
|
|
11
9
|
get: function () {
|
|
@@ -18,11 +16,9 @@ Object.defineProperty(exports, "ValidationError", {
|
|
|
18
16
|
return _ValidationError.default;
|
|
19
17
|
}
|
|
20
18
|
});
|
|
21
|
-
|
|
19
|
+
exports.isKnownError = isKnownError;
|
|
22
20
|
var _DomainError = _interopRequireDefault(require("./DomainError"));
|
|
23
|
-
|
|
24
21
|
var _ValidationError = _interopRequireDefault(require("./ValidationError"));
|
|
25
|
-
|
|
26
22
|
function isKnownError(err) {
|
|
27
23
|
return err instanceof _DomainError.default;
|
|
28
24
|
}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.buildFetchUrl = buildFetchUrl;
|
|
7
|
-
|
|
8
7
|
function buildFetchUrl(url, options) {
|
|
9
8
|
const {
|
|
10
9
|
awsS3BaseUrl,
|
|
@@ -19,7 +18,6 @@ function buildFetchUrl(url, options) {
|
|
|
19
18
|
KeyPairId,
|
|
20
19
|
Signature
|
|
21
20
|
} = options;
|
|
22
|
-
|
|
23
21
|
if (shouldUseCloudfront) {
|
|
24
22
|
const isWebContext = shouldUseCloudfront && typeof window === 'object';
|
|
25
23
|
const paramMap = {
|
|
@@ -28,18 +26,15 @@ function buildFetchUrl(url, options) {
|
|
|
28
26
|
quality,
|
|
29
27
|
fit: 'contain'
|
|
30
28
|
};
|
|
31
|
-
|
|
32
29
|
if (isWebContext) {
|
|
33
30
|
paramMap.Policy = Policy;
|
|
34
31
|
paramMap['Key-Pair-Id'] = KeyPairId;
|
|
35
32
|
paramMap.Signature = Signature;
|
|
36
33
|
}
|
|
37
|
-
|
|
38
34
|
const params = Object.entries(paramMap).filter(([, value]) => value != null).map(([key, value]) => `${key}=${String(value)}`);
|
|
39
35
|
const paramsString = params.join('&');
|
|
40
36
|
return `${cloudfrontBaseUrl}/${url}?${paramsString}`;
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
const transformations = [];
|
|
44
39
|
let transformationsString = '';
|
|
45
40
|
if (width) transformations.push(`w_${width.toString()}`);
|
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.fetchImage = fetchImage;
|
|
9
7
|
exports.arrayBufferToBase64 = arrayBufferToBase64;
|
|
8
|
+
exports.fetchImage = fetchImage;
|
|
10
9
|
exports.validateBase64Image = validateBase64Image;
|
|
11
10
|
exports.validateJpegImage = validateJpegImage;
|
|
12
11
|
exports.validatePngImage = validatePngImage;
|
|
13
|
-
|
|
14
12
|
var _abab = require("@lighthouse/abab");
|
|
15
|
-
|
|
16
13
|
var _fetchPonyfill = _interopRequireDefault(require("fetch-ponyfill"));
|
|
17
|
-
|
|
18
14
|
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
19
|
-
|
|
20
15
|
var _constants = require("../../constants");
|
|
21
|
-
|
|
22
16
|
var _images = require("../../images");
|
|
23
|
-
|
|
24
17
|
var _fetchImageForPdfGeneratorService = require("../fetch-image-for-pdf-generator-service");
|
|
25
|
-
|
|
26
18
|
var _fetchImageForWeb = require("../fetch-image-for-web");
|
|
27
|
-
|
|
28
19
|
// NOTE use the native fetch if it's available in the browser, because the
|
|
29
20
|
// ponyfill (which actually uses the github polyfill) does not support all the
|
|
30
21
|
// same options as native fetch
|
|
@@ -45,20 +36,19 @@ const defaultOptions = {
|
|
|
45
36
|
// sent from the fetch request, causing an error
|
|
46
37
|
cache: 'no-cache'
|
|
47
38
|
};
|
|
48
|
-
|
|
49
39
|
function fetchImage(url, options = {}) {
|
|
50
40
|
const {
|
|
51
41
|
shouldUseCloudfront
|
|
52
42
|
} = options;
|
|
53
|
-
|
|
54
43
|
if (shouldUseCloudfront) {
|
|
55
44
|
const isWebContext = typeof window === 'object';
|
|
56
|
-
return isWebContext ?
|
|
45
|
+
return isWebContext ?
|
|
46
|
+
// Values used from options: isHeader, Signature, Policy, KeyPairId
|
|
57
47
|
(0, _fetchImageForWeb.fetchImageForWeb)(url, options) : (0, _fetchImageForPdfGeneratorService.fetchImageForPdfGeneratorService)(url);
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
const encodedUrl = encodeURI(url);
|
|
61
|
-
const fetchOptions = {
|
|
50
|
+
const fetchOptions = {
|
|
51
|
+
...defaultOptions,
|
|
62
52
|
...options
|
|
63
53
|
};
|
|
64
54
|
const {
|
|
@@ -66,17 +56,16 @@ function fetchImage(url, options = {}) {
|
|
|
66
56
|
} = options;
|
|
67
57
|
return fetch(encodedUrl, fetchOptions).then(response => {
|
|
68
58
|
const contentHeader = response.headers.get('content-length');
|
|
69
|
-
const contentType = response.headers.get('content-type');
|
|
70
|
-
// image meaning pdfmake will error. Raise error here and return early.
|
|
59
|
+
const contentType = response.headers.get('content-type');
|
|
71
60
|
|
|
61
|
+
// NOTE: the response will be ok but we won't be able to render any
|
|
62
|
+
// image meaning pdfmake will error. Raise error here and return early.
|
|
72
63
|
if (contentHeader === '0') {
|
|
73
64
|
return _bluebird.default.reject(new Error(`Failed to fetch image as no content length: ${encodedUrl}`));
|
|
74
65
|
}
|
|
75
|
-
|
|
76
66
|
if (!response.ok) {
|
|
77
67
|
return _bluebird.default.reject(new Error(`Failed to fetch image: ${encodedUrl}`));
|
|
78
68
|
}
|
|
79
|
-
|
|
80
69
|
const imageType = contentTypes[contentType];
|
|
81
70
|
return response.arrayBuffer().then(buffer => ({
|
|
82
71
|
buffer,
|
|
@@ -90,11 +79,9 @@ function fetchImage(url, options = {}) {
|
|
|
90
79
|
const imageStr = arrayBufferToBase64(buffer);
|
|
91
80
|
const base64 = `${base64Flag}${imageStr}`;
|
|
92
81
|
const isValid = validateBase64Image(base64);
|
|
93
|
-
|
|
94
82
|
if (!isValid) {
|
|
95
83
|
return _bluebird.default.reject(new Error('InvalidImageError'));
|
|
96
84
|
}
|
|
97
|
-
|
|
98
85
|
return base64;
|
|
99
86
|
}).catch(error => {
|
|
100
87
|
if (isHeader) {
|
|
@@ -102,48 +89,45 @@ function fetchImage(url, options = {}) {
|
|
|
102
89
|
console.error('FetchImageHeaderError', error);
|
|
103
90
|
return fetchImage(_constants.LIGHTHOUSE_LOGO_URL, defaultOptions);
|
|
104
91
|
}
|
|
105
|
-
|
|
106
92
|
console.error(error);
|
|
107
93
|
return _images.imageNotFound;
|
|
108
94
|
});
|
|
109
95
|
}
|
|
110
|
-
|
|
111
96
|
function arrayBufferToBase64(buffer) {
|
|
112
97
|
let binary = '';
|
|
113
98
|
const bytes = [].slice.call(new Uint8Array(buffer));
|
|
114
99
|
bytes.forEach(b => binary += String.fromCharCode(b));
|
|
115
100
|
return (0, _abab.btoa)(binary);
|
|
116
101
|
}
|
|
117
|
-
|
|
118
102
|
function validateBase64Image(base64String) {
|
|
119
103
|
const isJpeg = base64String.startsWith('data:image/jpeg;base64,');
|
|
120
104
|
if (isJpeg) return validateJpegImage(base64String);
|
|
121
105
|
const isPng = base64String.startsWith('data:image/png;base64,');
|
|
122
106
|
if (isPng) return validatePngImage(base64String);
|
|
123
107
|
return false;
|
|
124
|
-
}
|
|
125
|
-
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
126
|
-
|
|
108
|
+
}
|
|
127
109
|
|
|
110
|
+
// See SO for more info: https://stackoverflow.com/a/41635312
|
|
111
|
+
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
128
112
|
function validateJpegImage(base64string) {
|
|
129
113
|
const src = base64string;
|
|
130
114
|
const imageData = Uint8Array.from((0, _abab.atob)(src.replace('data:image/jpeg;base64,', '')), c => c.charCodeAt(0));
|
|
131
115
|
const imageCorrupted = imageData[imageData.length - 1] === 217 && imageData[imageData.length - 2] === 255;
|
|
132
116
|
return imageCorrupted;
|
|
133
|
-
}
|
|
134
|
-
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
135
|
-
|
|
117
|
+
}
|
|
136
118
|
|
|
119
|
+
// See SO for more info: https://stackoverflow.com/a/41635312
|
|
120
|
+
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
137
121
|
function validatePngImage(base64string) {
|
|
138
122
|
const src = base64string;
|
|
139
123
|
const imageData = Uint8Array.from((0, _abab.atob)(src.replace('data:image/png;base64,', '')), c => c.charCodeAt(0));
|
|
140
|
-
const sequence = [0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130];
|
|
124
|
+
const sequence = [0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130];
|
|
141
125
|
|
|
126
|
+
//check last 12 elements of array so they contains needed values
|
|
142
127
|
for (let i = 12; i > 0; i--) {
|
|
143
128
|
if (imageData[imageData.length - i] !== sequence[12 - i]) {
|
|
144
129
|
return false;
|
|
145
130
|
}
|
|
146
131
|
}
|
|
147
|
-
|
|
148
132
|
return true;
|
|
149
133
|
}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
7
|
+
exports.fetchImageForPdfGeneratorService = void 0;
|
|
9
8
|
exports.fetchResourceFromS3 = fetchResourceFromS3;
|
|
10
9
|
exports.formatBase64Image = formatBase64Image;
|
|
11
|
-
exports.
|
|
12
|
-
|
|
10
|
+
exports.requestImageTransformation = requestImageTransformation;
|
|
13
11
|
var _imageValidators = require("../image-validators");
|
|
14
|
-
|
|
15
12
|
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
16
|
-
|
|
17
13
|
const REGION = process.env.AWS_REGION;
|
|
18
14
|
const lambda = new _awsSdk.default.Lambda({
|
|
19
15
|
region: REGION
|
|
@@ -21,21 +17,16 @@ const lambda = new _awsSdk.default.Lambda({
|
|
|
21
17
|
const s3 = new _awsSdk.default.S3({
|
|
22
18
|
region: REGION
|
|
23
19
|
});
|
|
24
|
-
|
|
25
20
|
const fetchImageForPdfGeneratorService = async function (url) {
|
|
26
21
|
console.debug('Fetching image via CloudFront For Serverless Pdf Generator Service');
|
|
27
|
-
|
|
28
22
|
if (!url) {
|
|
29
23
|
throw new Error('URL is required to fetch image for PDF generator service');
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
const urlMatch = url && url.match(/([a-f0-9]{24})\//);
|
|
33
26
|
const applicationId = urlMatch && urlMatch[1];
|
|
34
|
-
|
|
35
27
|
if (!applicationId) {
|
|
36
28
|
throw new Error('Requestor has insufficient permissions');
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
const {
|
|
40
31
|
path,
|
|
41
32
|
queryString,
|
|
@@ -46,7 +37,6 @@ const fetchImageForPdfGeneratorService = async function (url) {
|
|
|
46
37
|
bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,
|
|
47
38
|
key: transformedBucketImagePath
|
|
48
39
|
});
|
|
49
|
-
|
|
50
40
|
if (alreadyTransformedImage?.body) {
|
|
51
41
|
const fullDataUrl = formatBase64Image({
|
|
52
42
|
base64String: alreadyTransformedImage.body.toString('base64'),
|
|
@@ -54,10 +44,8 @@ const fetchImageForPdfGeneratorService = async function (url) {
|
|
|
54
44
|
});
|
|
55
45
|
return fullDataUrl;
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
const transformerResponse = await requestImageTransformation(`/${path}`, searchParamsObject);
|
|
59
48
|
const statusCode = transformerResponse.statusCode;
|
|
60
|
-
|
|
61
49
|
switch (statusCode) {
|
|
62
50
|
case 200:
|
|
63
51
|
{
|
|
@@ -68,16 +56,13 @@ const fetchImageForPdfGeneratorService = async function (url) {
|
|
|
68
56
|
});
|
|
69
57
|
return fullDataUrl;
|
|
70
58
|
}
|
|
71
|
-
|
|
72
59
|
case 302:
|
|
73
60
|
{
|
|
74
61
|
console.debug('Image transformation successful but image is too big for lambda delivery, fetching directly from S3');
|
|
75
62
|
const redirectLocation = transformerResponse.headers.Location;
|
|
76
|
-
|
|
77
63
|
if (!redirectLocation) {
|
|
78
64
|
throw new Error('Redirect response received but no location provided');
|
|
79
65
|
}
|
|
80
|
-
|
|
81
66
|
const newlyTransformedImage = await fetchResourceFromS3({
|
|
82
67
|
bucketName: process.env.S3_BUCKET_IMAGE_TRANSFORMER_CACHE,
|
|
83
68
|
key: transformedBucketImagePath
|
|
@@ -89,31 +74,23 @@ const fetchImageForPdfGeneratorService = async function (url) {
|
|
|
89
74
|
});
|
|
90
75
|
return fullDataUrl;
|
|
91
76
|
}
|
|
92
|
-
|
|
93
77
|
case 400:
|
|
94
78
|
throw new Error(`Bad request to image transformer: ${transformerResponse.body}`);
|
|
95
|
-
|
|
96
79
|
case 403:
|
|
97
80
|
throw new Error('Requested transformed image is too big');
|
|
98
|
-
|
|
99
81
|
case 404:
|
|
100
82
|
throw new Error('The requested image does not exist');
|
|
101
|
-
|
|
102
83
|
case 500:
|
|
103
84
|
throw new Error(`Image transformation failed: ${transformerResponse.body}`);
|
|
104
|
-
|
|
105
85
|
default:
|
|
106
86
|
throw new Error(`Unexpected response from image transformer: ${statusCode} - ${transformerResponse.body}`);
|
|
107
87
|
}
|
|
108
88
|
};
|
|
109
|
-
|
|
110
89
|
exports.fetchImageForPdfGeneratorService = fetchImageForPdfGeneratorService;
|
|
111
|
-
|
|
112
90
|
async function requestImageTransformation(path, searchParamsObject) {
|
|
113
91
|
if (!path) {
|
|
114
92
|
throw new Error('Image Path is required for image transformation');
|
|
115
93
|
}
|
|
116
|
-
|
|
117
94
|
console.debug('ImageTransformation: Invoking image transformer lambda for path:', {
|
|
118
95
|
path,
|
|
119
96
|
searchParamsObject
|
|
@@ -132,7 +109,6 @@ async function requestImageTransformation(path, searchParamsObject) {
|
|
|
132
109
|
InvocationType: 'RequestResponse',
|
|
133
110
|
Payload: JSON.stringify(lambdaEvent)
|
|
134
111
|
};
|
|
135
|
-
|
|
136
112
|
try {
|
|
137
113
|
const result = await lambda.invoke(params).promise();
|
|
138
114
|
const response = JSON.parse(result.Payload);
|
|
@@ -143,25 +119,21 @@ async function requestImageTransformation(path, searchParamsObject) {
|
|
|
143
119
|
throw new Error(errorMessage);
|
|
144
120
|
}
|
|
145
121
|
}
|
|
146
|
-
|
|
147
122
|
async function fetchResourceFromS3({
|
|
148
123
|
bucketName,
|
|
149
124
|
key
|
|
150
125
|
}) {
|
|
151
126
|
console.debug(`Fetching resource from S3 Bucket: '${bucketName}' at path: '${key}'`);
|
|
152
|
-
|
|
153
127
|
if (!bucketName || !key) {
|
|
154
128
|
throw new Error('bucketName and key are required for S3 resource fetch ' + JSON.stringify({
|
|
155
129
|
bucketName,
|
|
156
130
|
key
|
|
157
131
|
}));
|
|
158
132
|
}
|
|
159
|
-
|
|
160
133
|
const params = {
|
|
161
134
|
Bucket: bucketName,
|
|
162
135
|
Key: key
|
|
163
136
|
};
|
|
164
|
-
|
|
165
137
|
try {
|
|
166
138
|
const result = await s3.getObject(params).promise();
|
|
167
139
|
return {
|
|
@@ -176,11 +148,9 @@ async function fetchResourceFromS3({
|
|
|
176
148
|
console.error('Failed to fetch image:', error);
|
|
177
149
|
throw new Error(`Failed to fetch image: ${bucketName}/${key}`);
|
|
178
150
|
}
|
|
179
|
-
|
|
180
151
|
console.debug('Image not found in transformed bucket, invoking transformer');
|
|
181
152
|
}
|
|
182
153
|
}
|
|
183
|
-
|
|
184
154
|
function formatBase64Image({
|
|
185
155
|
base64String,
|
|
186
156
|
key
|
|
@@ -188,19 +158,18 @@ function formatBase64Image({
|
|
|
188
158
|
if (!key) {
|
|
189
159
|
throw new Error('Key is required for image formatting');
|
|
190
160
|
}
|
|
191
|
-
|
|
192
161
|
const imageType = key.toLowerCase().includes('.png') ? 'png' : 'jpeg';
|
|
193
162
|
const base64Flag = `data:image/${imageType};base64,`;
|
|
194
|
-
const fullDataUrl = `${base64Flag}${base64String}`;
|
|
163
|
+
const fullDataUrl = `${base64Flag}${base64String}`;
|
|
195
164
|
|
|
165
|
+
// Validate the formatted data URL
|
|
196
166
|
const isValid = (0, _imageValidators.validateBase64Image)(fullDataUrl);
|
|
197
|
-
|
|
198
167
|
if (!isValid) {
|
|
199
168
|
throw new Error('InvalidImageError');
|
|
200
169
|
}
|
|
201
|
-
|
|
202
170
|
return fullDataUrl;
|
|
203
171
|
}
|
|
172
|
+
|
|
204
173
|
/**
|
|
205
174
|
* Parses a URL-like string into path and query parameters
|
|
206
175
|
* @param {string} urlString - String like "https://example.cloudfront.net/<applicationId>/<path>/filename.jpeg?width=100&height=100"
|
|
@@ -209,14 +178,12 @@ function formatBase64Image({
|
|
|
209
178
|
* parseUrlString("https://example.cloudfront.net/abc123/folder/image.jpeg?width=100&height=100")
|
|
210
179
|
* // Returns: { path: "abc123/folder/image.jpeg", queryString: "width=100,t=456", searchParamsObject: { width: "100", height: "100" } }
|
|
211
180
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
181
|
function parseUrlString(urlString) {
|
|
215
182
|
if (!urlString || typeof urlString !== 'string') {
|
|
216
183
|
throw new Error('URL string is required and must be a string');
|
|
217
|
-
}
|
|
218
|
-
|
|
184
|
+
}
|
|
219
185
|
|
|
186
|
+
// Extract the path after the domain
|
|
220
187
|
const url = new URL(urlString);
|
|
221
188
|
let searchParamsObject = {};
|
|
222
189
|
url.searchParams.forEach((value, key) => {
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.fetchImageForWeb = void 0;
|
|
7
|
-
|
|
8
7
|
var _images = require("../../images");
|
|
9
|
-
|
|
10
8
|
var _fetchLighthouseLogo = require("../fetch-lighthouse-logo");
|
|
11
|
-
|
|
12
9
|
const fetchImageForWeb = async function (url, options) {
|
|
13
10
|
const {
|
|
14
11
|
isHeader = false,
|
|
@@ -16,7 +13,6 @@ const fetchImageForWeb = async function (url, options) {
|
|
|
16
13
|
Policy,
|
|
17
14
|
KeyPairId
|
|
18
15
|
} = options;
|
|
19
|
-
|
|
20
16
|
try {
|
|
21
17
|
const firstParamConnector = url.indexOf('?') > -1 ? '&' : '?';
|
|
22
18
|
const hasSignatureParams = url.includes('Signature=') && url.includes('Policy=') && url.includes('Key-Pair-Id=');
|
|
@@ -24,15 +20,12 @@ const fetchImageForWeb = async function (url, options) {
|
|
|
24
20
|
console.debug('Fetching image via CloudFront For Web');
|
|
25
21
|
const imageResponse = await fetch(constructedUrl);
|
|
26
22
|
const contentLengthHeader = imageResponse.headers.get('content-length');
|
|
27
|
-
|
|
28
23
|
if (contentLengthHeader === '0') {
|
|
29
24
|
return Promise.reject(new Error(`Failed to fetch image as no content length: ${encodedUrl}`));
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
if (!imageResponse.ok) {
|
|
33
27
|
return Promise.reject(new Error(`Failed to fetch image: ${encodedUrl}`));
|
|
34
28
|
}
|
|
35
|
-
|
|
36
29
|
return await imageResponse.arrayBuffer();
|
|
37
30
|
} catch (error) {
|
|
38
31
|
if (isHeader) {
|
|
@@ -40,10 +33,8 @@ const fetchImageForWeb = async function (url, options) {
|
|
|
40
33
|
console.error('FetchImageHeaderError', error);
|
|
41
34
|
return (0, _fetchLighthouseLogo.fetchLighthouseLogo)();
|
|
42
35
|
}
|
|
43
|
-
|
|
44
36
|
console.error(error);
|
|
45
37
|
return _images.imageNotFound;
|
|
46
38
|
}
|
|
47
39
|
};
|
|
48
|
-
|
|
49
40
|
exports.fetchImageForWeb = fetchImageForWeb;
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.fetchLighthouseLogo = void 0;
|
|
9
|
-
|
|
10
8
|
var _constants = require("../../constants");
|
|
11
|
-
|
|
12
9
|
var _fetchImage = require("../fetch-image");
|
|
13
|
-
|
|
14
10
|
var _imageValidators = require("../image-validators");
|
|
15
|
-
|
|
16
11
|
var _fetchPonyfill = _interopRequireDefault(require("fetch-ponyfill"));
|
|
17
|
-
|
|
18
12
|
// NOTE use the native fetch if it's available in the browser, because the
|
|
19
13
|
// ponyfill (which actually uses the github polyfill) does not support all the
|
|
20
14
|
// same options as native fetch
|
|
@@ -24,34 +18,29 @@ const fetch = typeof self === 'object' && self.fetch || (0, _fetchPonyfill.defau
|
|
|
24
18
|
const contentTypes = {
|
|
25
19
|
'image/png': 'png',
|
|
26
20
|
'image/jpeg': 'jpeg'
|
|
27
|
-
};
|
|
21
|
+
};
|
|
28
22
|
|
|
23
|
+
// NOTE: This is not stored where other images are - so it cannot go through CloudFront
|
|
29
24
|
const fetchLighthouseLogo = async function () {
|
|
30
25
|
const encodedLogoUrl = encodeURI(_constants.LIGHTHOUSE_LOGO_URL);
|
|
31
26
|
const logoResponse = await fetch(encodedLogoUrl);
|
|
32
27
|
const contentLengthHeader = logoResponse.headers.get('content-length');
|
|
33
28
|
const contentType = logoResponse.headers.get('content-type');
|
|
34
|
-
|
|
35
29
|
if (contentLengthHeader === '0') {
|
|
36
30
|
return Promise.reject(new Error(`Failed to fetch image as no content length: ${encodedLogoUrl}`));
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
if (!logoResponse.ok) {
|
|
40
33
|
return Promise.reject(new Error(`Failed to fetch image: ${encodedLogoUrl}`));
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
const imageType = contentTypes[contentType];
|
|
44
36
|
const logoArrayBuffer = await logoResponse.arrayBuffer();
|
|
45
37
|
const base64Flag = `data:image/${imageType};base64,`;
|
|
46
38
|
const imageStr = (0, _fetchImage.arrayBufferToBase64)(logoArrayBuffer);
|
|
47
39
|
const base64 = `${base64Flag}${imageStr}`;
|
|
48
40
|
const isValid = (0, _imageValidators.validateBase64Image)(base64);
|
|
49
|
-
|
|
50
41
|
if (isValid) {
|
|
51
42
|
return base64;
|
|
52
43
|
}
|
|
53
|
-
|
|
54
44
|
return Promise.reject(new Error('InvalidImageError'));
|
|
55
45
|
};
|
|
56
|
-
|
|
57
46
|
exports.fetchLighthouseLogo = fetchLighthouseLogo;
|
|
@@ -4,16 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getAssigneesFullNames = getAssigneesFullNames;
|
|
7
|
-
|
|
8
7
|
var _lodash = require("lodash");
|
|
9
|
-
|
|
10
8
|
var _ = require("../");
|
|
11
|
-
|
|
12
9
|
function getAssigneesFullNames(users, assignees) {
|
|
13
10
|
if ((0, _lodash.isEmpty)(assignees)) {
|
|
14
11
|
return 'No users assigned';
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
const fullNames = (0, _lodash.chain)(assignees).map(userId => (0, _.getUserFullName)(users, userId)).compact().join(', ').value();
|
|
18
14
|
return fullNames;
|
|
19
15
|
}
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getAuditItemsData = getAuditItemsData;
|
|
7
|
-
|
|
8
7
|
var _lodash = require("lodash");
|
|
9
|
-
|
|
10
8
|
var _ = require("../");
|
|
11
|
-
|
|
12
9
|
function getAuditItemsData(items, data) {
|
|
13
10
|
const {
|
|
14
11
|
settings: {
|
|
@@ -43,14 +40,12 @@ function getAuditItemsData(items, data) {
|
|
|
43
40
|
title
|
|
44
41
|
};
|
|
45
42
|
const currentGroupScores = (0, _lodash.get)(groupScores, key);
|
|
46
|
-
|
|
47
43
|
if (currentGroupScores) {
|
|
48
44
|
groupData.groupMaximumScore = (0, _lodash.round)(currentGroupScores.max, 2);
|
|
49
45
|
groupData.groupActualScore = (0, _lodash.round)(currentGroupScores.actual, 2);
|
|
50
46
|
groupData.groupResultScore = currentGroupScores.result;
|
|
51
47
|
groupData.groupPercentageResultScore = currentGroupScores.percentageResult;
|
|
52
48
|
}
|
|
53
|
-
|
|
54
49
|
groupData.items = items.map((item, itemIndex) => {
|
|
55
50
|
// NOTE: we handle scores of -1, 0 and 1
|
|
56
51
|
// -1 scores are skipped from group max and actual score
|
|
@@ -100,8 +95,9 @@ function getAuditItemsData(items, data) {
|
|
|
100
95
|
const key = `${groupIndex}-item-${itemIndex}`;
|
|
101
96
|
const matchingScore = (0, _lodash.find)(item.scores, {
|
|
102
97
|
value: score
|
|
103
|
-
});
|
|
98
|
+
});
|
|
104
99
|
|
|
100
|
+
// NOTE: ensure we have a score otherwise fallback to - value
|
|
105
101
|
const scoreLabel = hasScore && matchingScore && !skipped ? matchingScore.label : '-';
|
|
106
102
|
const scoreWeight = hasScore && !skipped ? item.scoreWeight : '-';
|
|
107
103
|
const weight = hasScore ? item.weight : '-';
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getGeometryGeocodedString = getGeometryGeocodedString;
|
|
7
|
-
|
|
8
7
|
var _lodash = require("lodash");
|
|
9
|
-
|
|
10
8
|
const DEFAULT_PROPERTIES = ['label', 'postalcode', 'postcode'];
|
|
11
|
-
|
|
12
9
|
function getGeometryGeocodedString(geometryReverseGeocoded, properties = DEFAULT_PROPERTIES) {
|
|
13
10
|
if (!geometryReverseGeocoded) return 'Unknown Location';
|
|
14
11
|
return (0, _lodash.chain)(geometryReverseGeocoded).pick(properties).values().compact().join(', ').value();
|