@lighthouse/common 5.0.0-canary-6 → 5.0.0-canary-8
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/array-buffer-to-base-64/index.js +0 -1
- package/dist/helpers/build-fetch-url/index.js +0 -3
- package/dist/helpers/fetch-image/index.js +14 -31
- package/dist/helpers/fetch-image-for-pdf-generator-service/index.js +38 -36
- package/dist/helpers/fetch-image-for-web/index.js +3 -18
- 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 +7 -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 -12
- 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 +15 -45
- 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 +0 -12
- 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 -11
- 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 +4 -12
- 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 +12 -35
- package/lib/constants.js.map +1 -1
- package/lib/errors/DomainError.js +5 -40
- package/lib/errors/DomainError.js.map +1 -1
- package/lib/errors/ValidationError.js +6 -45
- package/lib/errors/ValidationError.js.map +1 -1
- package/lib/errors/index.js.map +1 -1
- package/lib/helpers/array-buffer-to-base-64/index.js.map +1 -1
- package/lib/helpers/build-fetch-url/index.js +7 -13
- package/lib/helpers/build-fetch-url/index.js.map +1 -1
- package/lib/helpers/fetch-image/index.js +19 -30
- package/lib/helpers/fetch-image/index.js.map +1 -1
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js +78 -68
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js.map +1 -1
- package/lib/helpers/fetch-image-for-web/index.js +4 -21
- package/lib/helpers/fetch-image-for-web/index.js.map +1 -1
- package/lib/helpers/fetch-lighthouse-logo/index.js +6 -16
- 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 +7 -7
- package/lib/helpers/get-audit-entry-details/index.js.map +1 -1
- package/lib/helpers/get-audit-items-data/index.js +5 -6
- 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 +8 -8
- 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 +27 -33
- 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 +4 -4
- 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 +7 -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 +66 -110
- package/lib/pdf/activity-report/index.js.map +1 -1
- package/lib/pdf/audit/index.js +25 -31
- 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 +44 -79
- 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 +18 -28
- 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 +15 -19
- 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 +19 -26
- 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 +35 -85
- package/lib/pdf/shift-report/index.js.map +1 -1
- package/lib/pdf/task/index.js +11 -17
- package/lib/pdf/task/index.js.map +1 -1
- package/lib/scheduling/generators/index.js.map +1 -1
- package/lib/scheduling/generators/occurrenceIntervalsGenerator.js +0 -8
- package/lib/scheduling/generators/occurrenceIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/generators/scheduleIntervalsGenerator.js +0 -9
- package/lib/scheduling/generators/scheduleIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/generators/serviceIntervalsGenerator.js +31 -71
- 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 +26 -64
- package/lib/scheduling/helpers/generateNonRepeatingSchedule.js.map +1 -1
- package/lib/scheduling/helpers/generateRepeatingSchedule.js +47 -113
- 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 +0 -5
- package/lib/scheduling/scheduling.types.js.map +1 -1
- package/lib/scheduling/strategies/getNext.js +1 -13
- package/lib/scheduling/strategies/getNext.js.map +1 -1
- package/lib/scheduling/strategies/getNextExactDateOfMonth.js +1 -13
- package/lib/scheduling/strategies/getNextExactDateOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextLastDayOfMonth.js +1 -11
- package/lib/scheduling/strategies/getNextLastDayOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextLastWeekdayOfMonth.js +1 -11
- package/lib/scheduling/strategies/getNextLastWeekdayOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextNoRepeat.js +0 -9
- package/lib/scheduling/strategies/getNextNoRepeat.js.map +1 -1
- package/lib/scheduling/strategies/getNextWeekday.js +30 -68
- package/lib/scheduling/strategies/getNextWeekday.js.map +1 -1
- package/lib/scheduling/strategies/getNextXDayOfXWeekOfMonth.js +1 -11
- 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 +1 -7
- 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 +7 -24
- 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,
|
|
@@ -16,7 +15,6 @@ function buildFetchUrl(url, options) {
|
|
|
16
15
|
quality
|
|
17
16
|
} = options;
|
|
18
17
|
const shouldUseCloudfront = cloudfrontBaseUrl && cloudfrontBaseUrl.includes('.cloudfront.net');
|
|
19
|
-
|
|
20
18
|
if (shouldUseCloudfront) {
|
|
21
19
|
const transformations = [];
|
|
22
20
|
if (width) transformations.push(`width=${width.toString()}`);
|
|
@@ -27,7 +25,6 @@ function buildFetchUrl(url, options) {
|
|
|
27
25
|
const fetchUrl = `${cloudfrontBaseUrl}/${url}?${transformationsString}`;
|
|
28
26
|
return fetchUrl;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
const transformations = [];
|
|
32
29
|
let transformationsString = '';
|
|
33
30
|
if (width) transformations.push(`w_${width.toString()}`);
|
|
@@ -1,7 +1,6 @@
|
|
|
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
|
});
|
|
@@ -9,21 +8,13 @@ exports.fetchImage = fetchImage;
|
|
|
9
8
|
exports.validateBase64Image = validateBase64Image;
|
|
10
9
|
exports.validateJpegImage = validateJpegImage;
|
|
11
10
|
exports.validatePngImage = validatePngImage;
|
|
12
|
-
|
|
13
11
|
var _abab = require("@lighthouse/abab");
|
|
14
|
-
|
|
15
12
|
var _fetchPonyfill = _interopRequireDefault(require("fetch-ponyfill"));
|
|
16
|
-
|
|
17
13
|
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
18
|
-
|
|
19
14
|
var _constants = require("../../constants");
|
|
20
|
-
|
|
21
15
|
var _images = require("../../images");
|
|
22
|
-
|
|
23
16
|
var _fetchImageForPdfGeneratorService = require("../fetch-image-for-pdf-generator-service");
|
|
24
|
-
|
|
25
17
|
var _fetchImageForWeb = require("../fetch-image-for-web");
|
|
26
|
-
|
|
27
18
|
// NOTE use the native fetch if it's available in the browser, because the
|
|
28
19
|
// ponyfill (which actually uses the github polyfill) does not support all the
|
|
29
20
|
// same options as native fetch
|
|
@@ -44,14 +35,12 @@ const defaultOptions = {
|
|
|
44
35
|
// sent from the fetch request, causing an error
|
|
45
36
|
cache: 'no-cache'
|
|
46
37
|
};
|
|
47
|
-
|
|
48
38
|
function fetchImage(url, options = {}) {
|
|
49
39
|
const isWebContext = typeof window === 'object';
|
|
50
40
|
const {
|
|
51
41
|
isHeader = false
|
|
52
42
|
} = options;
|
|
53
43
|
const shouldUseCloudfront = url && url.includes('.cloudfront.net');
|
|
54
|
-
|
|
55
44
|
if (shouldUseCloudfront && isWebContext) {
|
|
56
45
|
// NOTE: Instead of passing in options directly
|
|
57
46
|
// we expose the used variables for readability
|
|
@@ -69,26 +58,26 @@ function fetchImage(url, options = {}) {
|
|
|
69
58
|
} else if (shouldUseCloudfront && !isWebContext) {
|
|
70
59
|
return (0, _fetchImageForPdfGeneratorService.fetchImageForPdfGeneratorService)(url);
|
|
71
60
|
}
|
|
72
|
-
|
|
73
61
|
const encodedUrl = encodeURI(url);
|
|
74
|
-
const fetchOptions = {
|
|
62
|
+
const fetchOptions = {
|
|
63
|
+
...defaultOptions,
|
|
75
64
|
...options,
|
|
76
|
-
headers: {
|
|
65
|
+
headers: {
|
|
66
|
+
...(options.headers || {})
|
|
77
67
|
}
|
|
78
68
|
};
|
|
79
69
|
return fetch(encodedUrl, fetchOptions).then(response => {
|
|
80
70
|
const contentHeader = response.headers.get('content-length');
|
|
81
|
-
const contentType = response.headers.get('content-type');
|
|
82
|
-
// image meaning pdfmake will error. Raise error here and return early.
|
|
71
|
+
const contentType = response.headers.get('content-type');
|
|
83
72
|
|
|
73
|
+
// NOTE: the response will be ok but we won't be able to render any
|
|
74
|
+
// image meaning pdfmake will error. Raise error here and return early.
|
|
84
75
|
if (contentHeader === '0') {
|
|
85
76
|
return _bluebird.default.reject(new Error(`Failed to fetch image as no content length: ${encodedUrl}`));
|
|
86
77
|
}
|
|
87
|
-
|
|
88
78
|
if (!response.ok) {
|
|
89
79
|
return _bluebird.default.reject(new Error(`Failed to fetch image: ${encodedUrl}`));
|
|
90
80
|
}
|
|
91
|
-
|
|
92
81
|
const imageType = contentTypes[contentType];
|
|
93
82
|
return response.arrayBuffer().then(buffer => ({
|
|
94
83
|
buffer,
|
|
@@ -102,11 +91,9 @@ function fetchImage(url, options = {}) {
|
|
|
102
91
|
const imageStr = arrayBufferToBase64(buffer);
|
|
103
92
|
const base64 = `${base64Flag}${imageStr}`;
|
|
104
93
|
const isValid = validateBase64Image(base64);
|
|
105
|
-
|
|
106
94
|
if (!isValid) {
|
|
107
95
|
return _bluebird.default.reject(new Error('InvalidImageError'));
|
|
108
96
|
}
|
|
109
|
-
|
|
110
97
|
return base64;
|
|
111
98
|
}).catch(error => {
|
|
112
99
|
if (isHeader) {
|
|
@@ -114,49 +101,45 @@ function fetchImage(url, options = {}) {
|
|
|
114
101
|
console.error('FetchImageHeaderError', error);
|
|
115
102
|
return fetchImage(_constants.LIGHTHOUSE_LOGO_URL, defaultOptions);
|
|
116
103
|
}
|
|
117
|
-
|
|
118
104
|
console.error(error);
|
|
119
105
|
return _images.imageNotFound;
|
|
120
106
|
});
|
|
121
107
|
}
|
|
122
|
-
|
|
123
108
|
function arrayBufferToBase64(buffer) {
|
|
124
109
|
let binary = '';
|
|
125
110
|
const bytes = [].slice.call(new Uint8Array(buffer));
|
|
126
111
|
bytes.forEach(b => binary += String.fromCharCode(b));
|
|
127
112
|
return (0, _abab.btoa)(binary);
|
|
128
113
|
}
|
|
129
|
-
|
|
130
114
|
function validateBase64Image(base64String) {
|
|
131
115
|
const isJpeg = base64String.startsWith('data:image/jpeg;base64,');
|
|
132
116
|
if (isJpeg) return validateJpegImage(base64String);
|
|
133
117
|
const isPng = base64String.startsWith('data:image/png;base64,');
|
|
134
118
|
if (isPng) return validatePngImage(base64String);
|
|
135
119
|
return false;
|
|
136
|
-
}
|
|
137
|
-
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
138
|
-
|
|
120
|
+
}
|
|
139
121
|
|
|
122
|
+
// See SO for more info: https://stackoverflow.com/a/41635312
|
|
123
|
+
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
140
124
|
function validateJpegImage(base64string) {
|
|
141
125
|
const src = base64string;
|
|
142
126
|
const imageData = Uint8Array.from((0, _abab.atob)(src.replace('data:image/jpeg;base64,', '')), c => c.charCodeAt(0));
|
|
143
127
|
const imageCorrupted = imageData[imageData.length - 1] === 217 && imageData[imageData.length - 2] === 255;
|
|
144
128
|
return imageCorrupted;
|
|
145
|
-
}
|
|
146
|
-
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
147
|
-
|
|
129
|
+
}
|
|
148
130
|
|
|
131
|
+
// See SO for more info: https://stackoverflow.com/a/41635312
|
|
132
|
+
// Fiddle: https://jsfiddle.net/Lnyxuchw/
|
|
149
133
|
function validatePngImage(base64string) {
|
|
150
134
|
const src = base64string;
|
|
151
135
|
const imageData = Uint8Array.from((0, _abab.atob)(src.replace('data:image/png;base64,', '')), c => c.charCodeAt(0));
|
|
152
136
|
const sequence = [0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]; // in hex:
|
|
153
|
-
//check last 12 elements of array so they contains needed values
|
|
154
137
|
|
|
138
|
+
//check last 12 elements of array so they contains needed values
|
|
155
139
|
for (let i = 12; i > 0; i--) {
|
|
156
140
|
if (imageData[imageData.length - i] !== sequence[12 - i]) {
|
|
157
141
|
return false;
|
|
158
142
|
}
|
|
159
143
|
}
|
|
160
|
-
|
|
161
144
|
return true;
|
|
162
145
|
}
|
|
@@ -1,16 +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.requestImageTransformation = requestImageTransformation;
|
|
9
|
-
exports.fetchResourceFromS3 = fetchResourceFromS3;
|
|
10
7
|
exports.fetchImageForPdfGeneratorService = void 0;
|
|
11
|
-
|
|
8
|
+
exports.fetchResourceFromS3 = fetchResourceFromS3;
|
|
9
|
+
exports.formatBase64Image = formatBase64Image;
|
|
10
|
+
exports.requestImageTransformation = requestImageTransformation;
|
|
11
|
+
var _imageValidators = require("../image-validators");
|
|
12
12
|
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
13
|
-
|
|
14
13
|
const REGION = process.env.AWS_REGION;
|
|
15
14
|
const lambda = new _awsSdk.default.Lambda({
|
|
16
15
|
region: REGION
|
|
@@ -18,81 +17,76 @@ const lambda = new _awsSdk.default.Lambda({
|
|
|
18
17
|
const s3 = new _awsSdk.default.S3({
|
|
19
18
|
region: REGION
|
|
20
19
|
});
|
|
21
|
-
|
|
22
20
|
const fetchImageForPdfGeneratorService = async function (url) {
|
|
23
21
|
console.info('Fetching image via CloudFront For Serverless Pdf Generator Service');
|
|
24
|
-
|
|
25
22
|
if (!url) {
|
|
26
23
|
throw new Error('URL is required to fetch image for PDF generator service');
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
const urlMatch = url && url.match(/([a-f0-9]{24})\//);
|
|
30
26
|
const applicationId = urlMatch && urlMatch[1];
|
|
31
|
-
|
|
32
27
|
if (!applicationId) {
|
|
33
28
|
throw new Error('Requestor has insufficient permissions');
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
const keyWithTransformations = url.substring(url.indexOf(applicationId));
|
|
37
31
|
const alreadyTransformedImage = await fetchResourceFromS3({
|
|
38
32
|
bucketName: `${process.env.S3_BUCKET_UPLOADS}-transformed`,
|
|
39
33
|
key: keyWithTransformations
|
|
40
34
|
});
|
|
41
|
-
|
|
42
35
|
if (alreadyTransformedImage && alreadyTransformedImage.body) {
|
|
43
|
-
|
|
36
|
+
const fullDataUrl = await formatBase64Image({
|
|
37
|
+
base64String: alreadyTransformedImage.body.toString('base64'),
|
|
38
|
+
key: keyWithTransformations
|
|
39
|
+
});
|
|
40
|
+
return fullDataUrl;
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
const keyWithoutTransformations = `/${keyWithTransformations.split('?')[0]}`;
|
|
47
43
|
const transformerResponse = await requestImageTransformation(keyWithoutTransformations);
|
|
48
44
|
const statusCode = transformerResponse.statusCode;
|
|
49
|
-
|
|
50
45
|
switch (statusCode) {
|
|
51
46
|
case 200:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
{
|
|
48
|
+
console.log('Image transformation successful');
|
|
49
|
+
const fullDataUrl = await formatBase64Image({
|
|
50
|
+
base64String: transformerResponse.body.toString('base64'),
|
|
51
|
+
key: keyWithTransformations
|
|
52
|
+
});
|
|
53
|
+
return fullDataUrl;
|
|
54
|
+
}
|
|
55
55
|
case 302:
|
|
56
56
|
{
|
|
57
57
|
console.log('Image transformation successful but image is too big for lambda delivery, fetching directly from S3');
|
|
58
58
|
const redirectLocation = transformerResponse.headers?.Location;
|
|
59
|
-
|
|
60
59
|
if (redirectLocation) {
|
|
61
60
|
const newlyTransformedImage = await fetchResourceFromS3({
|
|
62
61
|
bucketName: `${process.env.S3_BUCKET_UPLOADS}-transformed`,
|
|
63
62
|
key: keyWithTransformations
|
|
64
63
|
});
|
|
65
64
|
console.log('Image successfully fetched from S3 at:', redirectLocation);
|
|
66
|
-
|
|
65
|
+
const fullDataUrl = await formatBase64Image({
|
|
66
|
+
base64String: newlyTransformedImage.body.toString('base64'),
|
|
67
|
+
key: keyWithTransformations
|
|
68
|
+
});
|
|
69
|
+
return fullDataUrl;
|
|
67
70
|
}
|
|
68
|
-
|
|
69
71
|
throw new Error('Redirect response received but no location provided');
|
|
70
72
|
}
|
|
71
|
-
|
|
72
73
|
case 400:
|
|
73
74
|
throw new Error(`Bad request to image transformer: ${transformerResponse.body}`);
|
|
74
|
-
|
|
75
75
|
case 403:
|
|
76
76
|
throw new Error('Requested transformed image is too big');
|
|
77
|
-
|
|
78
77
|
case 404:
|
|
79
78
|
throw new Error('The requested image does not exist');
|
|
80
|
-
|
|
81
79
|
case 500:
|
|
82
80
|
throw new Error(`Image transformation failed: ${transformerResponse.body}`);
|
|
83
|
-
|
|
84
81
|
default:
|
|
85
82
|
throw new Error(`Unexpected response from image transformer: ${statusCode} - ${transformerResponse.body}`);
|
|
86
83
|
}
|
|
87
84
|
};
|
|
88
|
-
|
|
89
85
|
exports.fetchImageForPdfGeneratorService = fetchImageForPdfGeneratorService;
|
|
90
|
-
|
|
91
86
|
async function requestImageTransformation(key) {
|
|
92
87
|
if (!key) {
|
|
93
88
|
throw new Error('Image Path is required for image transformation');
|
|
94
89
|
}
|
|
95
|
-
|
|
96
90
|
console.log('ImageTransformation: Invoking image transformer lambda for path:', key);
|
|
97
91
|
const lambdaEvent = {
|
|
98
92
|
requestContext: {
|
|
@@ -107,7 +101,6 @@ async function requestImageTransformation(key) {
|
|
|
107
101
|
InvocationType: 'RequestResponse',
|
|
108
102
|
Payload: JSON.stringify(lambdaEvent)
|
|
109
103
|
};
|
|
110
|
-
|
|
111
104
|
try {
|
|
112
105
|
const result = await lambda.invoke(params).promise();
|
|
113
106
|
const response = JSON.parse(result.Payload);
|
|
@@ -118,25 +111,21 @@ async function requestImageTransformation(key) {
|
|
|
118
111
|
throw new Error(errorMessage);
|
|
119
112
|
}
|
|
120
113
|
}
|
|
121
|
-
|
|
122
114
|
async function fetchResourceFromS3({
|
|
123
115
|
bucketName,
|
|
124
116
|
key
|
|
125
117
|
}) {
|
|
126
118
|
console.info(`Fetching resource from S3 Bucket: '${bucketName}' at path: '${key}'`);
|
|
127
|
-
|
|
128
119
|
if (!bucketName || !key) {
|
|
129
120
|
throw new Error('bucketName and key are required for S3 resource fetch ' + JSON.stringify({
|
|
130
121
|
bucketName,
|
|
131
122
|
key
|
|
132
123
|
}));
|
|
133
124
|
}
|
|
134
|
-
|
|
135
125
|
const params = {
|
|
136
126
|
Bucket: bucketName,
|
|
137
127
|
Key: key
|
|
138
128
|
};
|
|
139
|
-
|
|
140
129
|
try {
|
|
141
130
|
const result = await s3.getObject(params).promise();
|
|
142
131
|
return {
|
|
@@ -148,11 +137,24 @@ async function fetchResourceFromS3({
|
|
|
148
137
|
};
|
|
149
138
|
} catch (error) {
|
|
150
139
|
if (error.code !== 'NoSuchKey') {
|
|
151
|
-
console.info('
|
|
152
|
-
|
|
140
|
+
console.info('Failed to fetch image:', error);
|
|
153
141
|
throw new Error(`Failed to fetch image: ${bucketName}/${key}`);
|
|
154
142
|
}
|
|
155
|
-
|
|
156
143
|
console.info('Image not found in transformed bucket, invoking transformer');
|
|
157
144
|
}
|
|
145
|
+
}
|
|
146
|
+
async function formatBase64Image({
|
|
147
|
+
base64String,
|
|
148
|
+
key
|
|
149
|
+
}) {
|
|
150
|
+
const imageType = key.toLowerCase().includes('.png') ? 'png' : 'jpeg';
|
|
151
|
+
const base64Flag = `data:image/${imageType};base64,`;
|
|
152
|
+
const fullDataUrl = `${base64Flag}${base64String}`;
|
|
153
|
+
|
|
154
|
+
// Validate the formatted data URL
|
|
155
|
+
const isValid = (0, _imageValidators.validateBase64Image)(fullDataUrl);
|
|
156
|
+
if (!isValid) {
|
|
157
|
+
return Promise.reject(new Error('InvalidImageError'));
|
|
158
|
+
}
|
|
159
|
+
return fullDataUrl;
|
|
158
160
|
}
|
|
@@ -1,33 +1,26 @@
|
|
|
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.fetchImageForWeb = void 0;
|
|
9
|
-
|
|
10
8
|
var _images = require("../../images");
|
|
11
|
-
|
|
12
9
|
var _fetchLighthouseLogo = require("../fetch-lighthouse-logo");
|
|
13
|
-
|
|
14
10
|
var _arrayBufferToBase = require("../array-buffer-to-base-64");
|
|
15
|
-
|
|
16
11
|
var _imageValidators = require("../image-validators");
|
|
17
|
-
|
|
18
12
|
var _fetchPonyfill = _interopRequireDefault(require("fetch-ponyfill"));
|
|
19
|
-
|
|
20
13
|
const contentTypes = {
|
|
21
14
|
'image/png': 'png',
|
|
22
15
|
'image/jpeg': 'jpeg'
|
|
23
|
-
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// NOTE use the native fetch if it's available in the browser, because the
|
|
24
19
|
// ponyfill (which actually uses the github polyfill) does not support all the
|
|
25
20
|
// same options as native fetch
|
|
26
|
-
|
|
27
21
|
const fetch = typeof self === 'object' && self.fetch || (0, _fetchPonyfill.default)({
|
|
28
22
|
Promise
|
|
29
23
|
}).fetch;
|
|
30
|
-
|
|
31
24
|
const fetchImageForWeb = async function (url, options) {
|
|
32
25
|
const {
|
|
33
26
|
isHeader = false,
|
|
@@ -35,7 +28,6 @@ const fetchImageForWeb = async function (url, options) {
|
|
|
35
28
|
Policy,
|
|
36
29
|
KeyPairId
|
|
37
30
|
} = options;
|
|
38
|
-
|
|
39
31
|
try {
|
|
40
32
|
const firstParamConnector = new URL(url).searchParams.size > 0 ? '&' : '?';
|
|
41
33
|
const urlToEncode = `${url}${firstParamConnector}Signature=${Signature}&Policy=${Policy}&Key-Pair-Id=${KeyPairId}`;
|
|
@@ -44,22 +36,18 @@ const fetchImageForWeb = async function (url, options) {
|
|
|
44
36
|
const imageResponse = await fetch(encodedUrl);
|
|
45
37
|
const contentLengthHeader = imageResponse.headers.get('content-length');
|
|
46
38
|
const contentType = imageResponse.headers.get('content-type');
|
|
47
|
-
|
|
48
39
|
if (contentLengthHeader === '0') {
|
|
49
40
|
return Promise.reject(new Error(`Failed to fetch image as no content length: ${encodedUrl}`));
|
|
50
41
|
}
|
|
51
|
-
|
|
52
42
|
if (!imageResponse.ok) {
|
|
53
43
|
return Promise.reject(new Error(`Failed to fetch image: ${encodedUrl}`));
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
const imageType = contentTypes[contentType];
|
|
57
46
|
const logoArrayBuffer = await imageResponse.arrayBuffer();
|
|
58
47
|
const base64Flag = `data:image/${imageType};base64,`;
|
|
59
48
|
const imageStr = (0, _arrayBufferToBase.arrayBufferToBase64)(logoArrayBuffer);
|
|
60
49
|
const base64 = `${base64Flag}${imageStr}`;
|
|
61
50
|
const isValid = (0, _imageValidators.validateBase64Image)(base64);
|
|
62
|
-
|
|
63
51
|
if (isValid) {
|
|
64
52
|
return base64;
|
|
65
53
|
}
|
|
@@ -69,12 +57,9 @@ const fetchImageForWeb = async function (url, options) {
|
|
|
69
57
|
console.error('FetchImageHeaderError', error);
|
|
70
58
|
return (0, _fetchLighthouseLogo.fetchLighthouseLogo)();
|
|
71
59
|
}
|
|
72
|
-
|
|
73
60
|
console.error(error);
|
|
74
61
|
return _images.imageNotFound;
|
|
75
62
|
}
|
|
76
|
-
|
|
77
63
|
return Promise.reject(new Error('InvalidImageError'));
|
|
78
64
|
};
|
|
79
|
-
|
|
80
65
|
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 _arrayBufferToBase = require("../array-buffer-to-base-64");
|
|
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, _arrayBufferToBase.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
|
}
|