@lighthouse/common 5.0.0-canary-11 → 5.0.0-canary-12
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-web/index.js +0 -9
- package/dist/scheduling/scheduling.types.js +9 -9
- package/dist/service-hours/schema.js +12 -12
- package/lib/errors/DomainError.js +7 -8
- package/lib/errors/DomainError.js.map +1 -1
- package/lib/errors/ValidationError.js +11 -9
- package/lib/errors/ValidationError.js.map +1 -1
- package/lib/helpers/build-fetch-url/index.js.map +1 -1
- package/lib/helpers/fetch-image/index.js.map +1 -1
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js +174 -180
- package/lib/helpers/fetch-image-for-pdf-generator-service/index.js.map +1 -1
- package/lib/helpers/fetch-image-for-web/index.js +63 -74
- package/lib/helpers/fetch-image-for-web/index.js.map +1 -1
- package/lib/helpers/fetch-lighthouse-logo/index.js +41 -43
- package/lib/helpers/fetch-lighthouse-logo/index.js.map +1 -1
- package/lib/helpers/get-audit-entry-details/index.js.map +1 -1
- package/lib/helpers/get-audit-items-data/index.js +8 -8
- package/lib/helpers/get-audit-items-data/index.js.map +1 -1
- package/lib/helpers/get-issue-details/index.js.map +1 -1
- package/lib/helpers/get-job-details/index.js.map +1 -1
- package/lib/helpers/get-location-reference/index.js +6 -4
- package/lib/helpers/get-location-reference/index.js.map +1 -1
- package/lib/helpers/get-reference-details/index.js.map +1 -1
- package/lib/helpers/get-task-entry-details/index.js.map +1 -1
- package/lib/helpers/get-timezone-datetime/index.js.map +1 -1
- package/lib/pdf/activity-report/index.js +299 -311
- package/lib/pdf/activity-report/index.js.map +1 -1
- package/lib/pdf/audit/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-content/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-follow-ups/index.js.map +1 -1
- package/lib/pdf/helpers/build-location-scans-content/index.js.map +1 -1
- package/lib/pdf/helpers/build-template-content/index.js.map +1 -1
- package/lib/pdf/helpers/fields/index.js.map +1 -1
- package/lib/pdf/helpers/generate-definition/index.js.map +1 -1
- package/lib/pdf/helpers/horizontal-line/index.js.map +1 -1
- package/lib/pdf/helpers/html-transformer/index.js +1 -2
- package/lib/pdf/helpers/html-transformer/index.js.map +1 -1
- package/lib/pdf/helpers/table/index.js +63 -65
- package/lib/pdf/helpers/table/index.js.map +1 -1
- package/lib/pdf/issue/index.js.map +1 -1
- package/lib/pdf/job/index.js.map +1 -1
- package/lib/pdf/shift-report/index.js +275 -291
- package/lib/pdf/shift-report/index.js.map +1 -1
- package/lib/pdf/task/index.js.map +1 -1
- package/lib/scheduling/generators/occurrenceIntervalsGenerator.js +27 -30
- package/lib/scheduling/generators/occurrenceIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/generators/scheduleIntervalsGenerator.js +19 -21
- package/lib/scheduling/generators/scheduleIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/generators/serviceIntervalsGenerator.js +134 -136
- package/lib/scheduling/generators/serviceIntervalsGenerator.js.map +1 -1
- package/lib/scheduling/helpers/generateNonRepeatingSchedule.js +81 -83
- package/lib/scheduling/helpers/generateNonRepeatingSchedule.js.map +1 -1
- package/lib/scheduling/helpers/generateRepeatingSchedule.js +104 -106
- package/lib/scheduling/helpers/generateRepeatingSchedule.js.map +1 -1
- package/lib/scheduling/helpers/generateScheduleEnd.js.map +1 -1
- package/lib/scheduling/scheduling.types.js +9 -9
- package/lib/scheduling/scheduling.types.js.map +1 -1
- package/lib/scheduling/strategies/getNext.js +21 -17
- package/lib/scheduling/strategies/getNext.js.map +1 -1
- package/lib/scheduling/strategies/getNextExactDateOfMonth.js +21 -18
- package/lib/scheduling/strategies/getNextExactDateOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextLastDayOfMonth.js +20 -17
- package/lib/scheduling/strategies/getNextLastDayOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextLastWeekdayOfMonth.js +20 -17
- package/lib/scheduling/strategies/getNextLastWeekdayOfMonth.js.map +1 -1
- package/lib/scheduling/strategies/getNextNoRepeat.js +15 -14
- package/lib/scheduling/strategies/getNextNoRepeat.js.map +1 -1
- package/lib/scheduling/strategies/getNextWeekday.js +36 -33
- package/lib/scheduling/strategies/getNextWeekday.js.map +1 -1
- package/lib/scheduling/strategies/getNextXDayOfXWeekOfMonth.js +20 -17
- package/lib/scheduling/strategies/getNextXDayOfXWeekOfMonth.js.map +1 -1
- package/lib/schema/schema.js +21 -23
- package/lib/schema/schema.js.map +1 -1
- package/lib/service-hours/schema.js +15 -13
- package/lib/service-hours/schema.js.map +1 -1
- package/package-lock.json +25484 -0
- package/package.json +1 -1
- package/yarn-error.log +0 -13549
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -9,18 +8,10 @@ var _images = require("../../images");
|
|
|
9
8
|
var _fetchLighthouseLogo = require("../fetch-lighthouse-logo");
|
|
10
9
|
var _arrayBufferToBase = require("../array-buffer-to-base-64");
|
|
11
10
|
var _imageValidators = require("../image-validators");
|
|
12
|
-
var _fetchPonyfill = _interopRequireDefault(require("fetch-ponyfill"));
|
|
13
11
|
const contentTypes = {
|
|
14
12
|
'image/png': 'png',
|
|
15
13
|
'image/jpeg': 'jpeg'
|
|
16
14
|
};
|
|
17
|
-
|
|
18
|
-
// NOTE use the native fetch if it's available in the browser, because the
|
|
19
|
-
// ponyfill (which actually uses the github polyfill) does not support all the
|
|
20
|
-
// same options as native fetch
|
|
21
|
-
const fetch = typeof self === 'object' && self.fetch || (0, _fetchPonyfill.default)({
|
|
22
|
-
Promise
|
|
23
|
-
}).fetch;
|
|
24
15
|
const fetchImageForWeb = async function (url, options) {
|
|
25
16
|
const {
|
|
26
17
|
isHeader = false,
|
|
@@ -4,13 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Unit = exports.StrategyTypes = exports.IntervalTypes = void 0;
|
|
7
|
-
let IntervalTypes = exports.IntervalTypes =
|
|
8
|
-
(function (IntervalTypes) {
|
|
7
|
+
let IntervalTypes = exports.IntervalTypes = /*#__PURE__*/function (IntervalTypes) {
|
|
9
8
|
IntervalTypes["Occurrence"] = "occurrence";
|
|
10
9
|
IntervalTypes["Service"] = "service";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
return IntervalTypes;
|
|
11
|
+
}({});
|
|
12
|
+
let Unit = exports.Unit = /*#__PURE__*/function (Unit) {
|
|
14
13
|
Unit["Millisecond"] = "millisecond";
|
|
15
14
|
Unit["Second"] = "second";
|
|
16
15
|
Unit["Minute"] = "minute";
|
|
@@ -19,9 +18,9 @@ let Unit = exports.Unit = void 0;
|
|
|
19
18
|
Unit["Week"] = "isoWeek";
|
|
20
19
|
Unit["Month"] = "month";
|
|
21
20
|
Unit["Year"] = "year";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
return Unit;
|
|
22
|
+
}({});
|
|
23
|
+
let StrategyTypes = exports.StrategyTypes = /*#__PURE__*/function (StrategyTypes) {
|
|
25
24
|
StrategyTypes["ExactDateOfMonth"] = "exactDateOfMonth";
|
|
26
25
|
StrategyTypes["LastDayOfMonth"] = "lastDayOfMonth";
|
|
27
26
|
StrategyTypes["LastWeekdayOfMonth"] = "lastWeekdayOfMonth";
|
|
@@ -30,4 +29,5 @@ let StrategyTypes = exports.StrategyTypes = void 0;
|
|
|
30
29
|
StrategyTypes["Weekdays"] = "weekdays";
|
|
31
30
|
StrategyTypes["Window"] = "window";
|
|
32
31
|
StrategyTypes["XDayOfXWeekOfMonth"] = "xDayOfxWeekOfMonth";
|
|
33
|
-
|
|
32
|
+
return StrategyTypes;
|
|
33
|
+
}({});
|
|
@@ -9,26 +9,25 @@ var _yup = require("yup");
|
|
|
9
9
|
var _fp = require("lodash/fp");
|
|
10
10
|
var _lodash = require("lodash");
|
|
11
11
|
const MAX_OFFSET_MS = 604800000;
|
|
12
|
-
let Behaviours = exports.Behaviours =
|
|
13
|
-
(function (Behaviours) {
|
|
12
|
+
let Behaviours = exports.Behaviours = /*#__PURE__*/function (Behaviours) {
|
|
14
13
|
Behaviours["Open"] = "OPEN";
|
|
15
14
|
Behaviours["Close"] = "CLOSE";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
return Behaviours;
|
|
16
|
+
}({});
|
|
17
|
+
let Durations = exports.Durations = /*#__PURE__*/function (Durations) {
|
|
19
18
|
Durations[Durations["Second"] = 1000] = "Second";
|
|
20
19
|
Durations[Durations["Minute"] = 60000] = "Minute";
|
|
21
20
|
Durations[Durations["Hour"] = 3600000] = "Hour";
|
|
22
21
|
Durations[Durations["Day"] = 86400000] = "Day";
|
|
23
22
|
Durations[Durations["Week"] = 604800000] = "Week";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
return Durations;
|
|
24
|
+
}({});
|
|
25
|
+
let Types = exports.Types = /*#__PURE__*/function (Types) {
|
|
27
26
|
Types["Default"] = "DEFAULT";
|
|
28
27
|
Types["Override"] = "OVERRIDE";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
return Types;
|
|
29
|
+
}({});
|
|
30
|
+
let Weekdays = exports.Weekdays = /*#__PURE__*/function (Weekdays) {
|
|
32
31
|
Weekdays["Monday"] = "MONDAY";
|
|
33
32
|
Weekdays["Tuesday"] = "TUESDAY";
|
|
34
33
|
Weekdays["Wednesday"] = "WEDNESDAY";
|
|
@@ -36,7 +35,8 @@ let Weekdays = exports.Weekdays = void 0;
|
|
|
36
35
|
Weekdays["Friday"] = "FRIDAY";
|
|
37
36
|
Weekdays["Saturday"] = "SATURDAY";
|
|
38
37
|
Weekdays["Sunday"] = "SUNDAY";
|
|
39
|
-
|
|
38
|
+
return Weekdays;
|
|
39
|
+
}({});
|
|
40
40
|
const hoursSchema = (0, _yup.object)({
|
|
41
41
|
type: (0, _yup.string)().oneOf([Types.Default, Types.Override]).required(),
|
|
42
42
|
start: (0, _yup.number)().min(0).required(),
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
3
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
4
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
6
|
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
7
|
-
function
|
|
7
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
8
8
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
9
9
|
// TODO is this universal?
|
|
10
10
|
var DomainError = /*#__PURE__*/function (_Error) {
|
|
11
|
-
_inherits(DomainError, _Error);
|
|
12
|
-
var _super = _createSuper(DomainError);
|
|
13
11
|
function DomainError(message) {
|
|
14
12
|
var _this;
|
|
15
13
|
_classCallCheck(this, DomainError);
|
|
16
|
-
_this =
|
|
14
|
+
_this = _callSuper(this, DomainError, [message]);
|
|
17
15
|
_this.name = _this.constructor.name;
|
|
18
16
|
|
|
19
17
|
// @ts-ignore support both node and browser environments
|
|
20
18
|
if (typeof Error.captureStackTrace === 'function') {
|
|
21
19
|
// @ts-ignore
|
|
22
|
-
Error.captureStackTrace(
|
|
20
|
+
Error.captureStackTrace(_this, _this.constructor);
|
|
23
21
|
} else {
|
|
24
22
|
_this.stack = new Error(message).stack;
|
|
25
23
|
}
|
|
26
24
|
return _this;
|
|
27
25
|
}
|
|
28
|
-
|
|
26
|
+
_inherits(DomainError, _Error);
|
|
27
|
+
return _createClass(DomainError);
|
|
29
28
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
30
29
|
export { DomainError as default };
|
|
31
30
|
//# sourceMappingURL=DomainError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomainError.js","names":["DomainError","_Error","
|
|
1
|
+
{"version":3,"file":"DomainError.js","names":["DomainError","_Error","message","_this","_classCallCheck","_callSuper","name","constructor","Error","captureStackTrace","stack","_inherits","_createClass","_wrapNativeSuper","default"],"sources":["../../src/errors/DomainError.ts"],"sourcesContent":["// TODO is this universal?\nexport default class DomainError extends Error {\n constructor(message: string) {\n super(message)\n this.name = this.constructor.name\n\n // @ts-ignore support both node and browser environments\n if (typeof Error.captureStackTrace === 'function') {\n // @ts-ignore\n Error.captureStackTrace(this, this.constructor)\n } else { \n this.stack = (new Error(message)).stack\n }\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAAA,IACqBA,WAAW,0BAAAC,MAAA;EAC9B,SAAAD,YAAYE,OAAe,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAJ,WAAA;IAC3BG,KAAA,GAAAE,UAAA,OAAAL,WAAA,GAAME,OAAO;IACbC,KAAA,CAAKG,IAAI,GAAGH,KAAA,CAAKI,WAAW,CAACD,IAAI;;IAEjC;IACA,IAAI,OAAOE,KAAK,CAACC,iBAAiB,KAAK,UAAU,EAAE;MACjD;MACAD,KAAK,CAACC,iBAAiB,CAAAN,KAAA,EAAOA,KAAA,CAAKI,WAAW,CAAC;IACjD,CAAC,MAAM;MACLJ,KAAA,CAAKO,KAAK,GAAI,IAAIF,KAAK,CAACN,OAAO,CAAC,CAAEQ,KAAK;IACzC;IAAC,OAAAP,KAAA;EACH;EAACQ,SAAA,CAAAX,WAAA,EAAAC,MAAA;EAAA,OAAAW,YAAA,CAAAZ,WAAA;AAAA,eAAAa,gBAAA,CAZsCL,KAAK;AAAA,SAAzBR,WAAW,IAAAc,OAAA","ignoreList":[]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import
|
|
4
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
5
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
6
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
8
|
+
var _excluded = ["message", "name"];
|
|
9
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
10
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
8
11
|
import { ValidationError as SchemaValidationError } from 'yup';
|
|
9
12
|
import DomainError from './DomainError';
|
|
10
13
|
var DEFAULT_MESSAGE = 'The data you submitted was invalid. Please try again with valid data.';
|
|
11
14
|
var ValidationError = /*#__PURE__*/function (_DomainError) {
|
|
12
|
-
_inherits(ValidationError, _DomainError);
|
|
13
|
-
var _super = _createSuper(ValidationError);
|
|
14
15
|
function ValidationError(_ref) {
|
|
15
16
|
var _this;
|
|
16
17
|
var data = _ref.data,
|
|
@@ -22,18 +23,19 @@ var ValidationError = /*#__PURE__*/function (_DomainError) {
|
|
|
22
23
|
if (data instanceof SchemaValidationError) {
|
|
23
24
|
var validationMessage = data.message,
|
|
24
25
|
name = data.name,
|
|
25
|
-
other = _objectWithoutProperties(data,
|
|
26
|
-
_this =
|
|
26
|
+
other = _objectWithoutProperties(data, _excluded);
|
|
27
|
+
_this = _callSuper(this, ValidationError, [validationMessage]);
|
|
27
28
|
_this.data = other;
|
|
28
29
|
_this.status = 400;
|
|
29
30
|
return _possibleConstructorReturn(_this);
|
|
30
31
|
}
|
|
31
|
-
_this =
|
|
32
|
+
_this = _callSuper(this, ValidationError, [message]);
|
|
32
33
|
_this.data = data;
|
|
33
34
|
_this.status = 400;
|
|
34
|
-
return
|
|
35
|
+
return _assertThisInitialized(_this);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
_inherits(ValidationError, _DomainError);
|
|
38
|
+
return _createClass(ValidationError);
|
|
37
39
|
}(DomainError);
|
|
38
40
|
export { ValidationError as default };
|
|
39
41
|
//# sourceMappingURL=ValidationError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationError.js","names":["ValidationError","SchemaValidationError","DomainError","DEFAULT_MESSAGE","_DomainError","
|
|
1
|
+
{"version":3,"file":"ValidationError.js","names":["ValidationError","SchemaValidationError","DomainError","DEFAULT_MESSAGE","_DomainError","_ref","_this","data","_ref$message","message","_classCallCheck","validationMessage","name","other","_objectWithoutProperties","_excluded","_callSuper","status","_possibleConstructorReturn","_assertThisInitialized","_inherits","_createClass","default"],"sources":["../../src/errors/ValidationError.ts"],"sourcesContent":["import { ValidationError as SchemaValidationError } from 'yup'\nimport DomainError from './DomainError'\n\ninterface Options {\n data?: any\n message?: string\n}\n\nconst DEFAULT_MESSAGE =\n 'The data you submitted was invalid. Please try again with valid data.'\n\nexport default class ValidationError extends DomainError {\n public data: object\n public message: string\n public status: number\n constructor({ data, message = DEFAULT_MESSAGE }: Options) {\n // When the data object is a schema validation error, take its data\n // attributes and apply to our wrapped error\n if (data instanceof SchemaValidationError) {\n const { message: validationMessage, name, ...other } = data\n\n super(validationMessage)\n this.data = other\n this.status = 400\n return\n }\n\n super(message)\n this.data = data\n this.status = 400\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAASA,eAAe,IAAIC,qBAAqB,QAAQ,KAAK;AAC9D,OAAOC,WAAW,MAAM,eAAe;AAOvC,IAAMC,eAAe,GACnB,uEAAuE;AAAA,IAEpDH,eAAe,0BAAAI,YAAA;EAIlC,SAAAJ,gBAAAK,IAAA,EAA0D;IAAA,IAAAC,KAAA;IAAA,IAA5CC,IAAI,GAAAF,IAAA,CAAJE,IAAI;MAAAC,YAAA,GAAAH,IAAA,CAAEI,OAAO;MAAPA,OAAO,GAAAD,YAAA,cAAGL,eAAe,GAAAK,YAAA;IAAAE,eAAA,OAAAV,eAAA;IAC3C;IACA;IACA,IAAIO,IAAI,YAAYN,qBAAqB,EAAE;MACzC,IAAiBU,iBAAiB,GAAqBJ,IAAI,CAAnDE,OAAO;QAAqBG,IAAI,GAAeL,IAAI,CAAvBK,IAAI;QAAKC,KAAK,GAAAC,wBAAA,CAAKP,IAAI,EAAAQ,SAAA;MAE3DT,KAAA,GAAAU,UAAA,OAAAhB,eAAA,GAAMW,iBAAiB;MACvBL,KAAA,CAAKC,IAAI,GAAGM,KAAK;MACjBP,KAAA,CAAKW,MAAM,GAAG,GAAG;MACjB,OAAAC,0BAAA,CAAAZ,KAAA;IACF;IAEAA,KAAA,GAAAU,UAAA,OAAAhB,eAAA,GAAMS,OAAO;IACbH,KAAA,CAAKC,IAAI,GAAGA,IAAI;IAChBD,KAAA,CAAKW,MAAM,GAAG,GAAG;IAAA,OAAAE,sBAAA,CAAAb,KAAA;EACnB;EAACc,SAAA,CAAApB,eAAA,EAAAI,YAAA;EAAA,OAAAiB,YAAA,CAAArB,eAAA;AAAA,EAnB0CE,WAAW;AAAA,SAAnCF,eAAe,IAAAsB,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["buildFetchUrl","url","options","awsS3BaseUrl","_options$cloudfrontBa","cloudfrontBaseUrl","cloudinaryBaseUrl","fit","height","width","quality","shouldUseCloudfront","includes","transformations","push","concat","toString","transformationsString","join","fetchUrl"],"sources":["../../../src/helpers/build-fetch-url/index.js"],"sourcesContent":["export function buildFetchUrl(url, options) {\n const {\n awsS3BaseUrl,\n cloudfrontBaseUrl = '',\n cloudinaryBaseUrl,\n fit,\n height,\n width,\n quality,\n } = options\n\n const shouldUseCloudfront =\n cloudfrontBaseUrl && cloudfrontBaseUrl.includes('.cloudfront.net')\n\n if (shouldUseCloudfront) {\n const transformations = []\n\n if (width) transformations.push(`width=${width.toString()}`)\n if (height) transformations.push(`height=${height.toString()}`)\n if (quality) transformations.push(`quality=${quality.toString()}`)\n transformations.push(`fit=contain`)\n\n const transformationsString = transformations.join('&')\n\n const fetchUrl = `${cloudfrontBaseUrl}/${url}?${transformationsString}`\n return fetchUrl\n }\n\n const transformations = []\n let transformationsString = ''\n\n if (width) transformations.push(`w_${width.toString()}`)\n if (height) transformations.push(`h_${height.toString()}`)\n if (quality) transformations.push(`q_${quality.toString()}`)\n if (fit) transformations.push('c_fit')\n\n transformationsString = `${transformations.join(',')}/`\n\n const fetchUrl = `${cloudinaryBaseUrl}/${transformationsString}${awsS3BaseUrl}/${url}`\n\n return fetchUrl\n}\n"],"mappings":"AAAA,OAAO,SAASA,aAAaA,CAACC,GAAG,EAAEC,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"index.js","names":["buildFetchUrl","url","options","awsS3BaseUrl","_options$cloudfrontBa","cloudfrontBaseUrl","cloudinaryBaseUrl","fit","height","width","quality","shouldUseCloudfront","includes","transformations","push","concat","toString","transformationsString","join","fetchUrl"],"sources":["../../../src/helpers/build-fetch-url/index.js"],"sourcesContent":["export function buildFetchUrl(url, options) {\n const {\n awsS3BaseUrl,\n cloudfrontBaseUrl = '',\n cloudinaryBaseUrl,\n fit,\n height,\n width,\n quality,\n } = options\n\n const shouldUseCloudfront =\n cloudfrontBaseUrl && cloudfrontBaseUrl.includes('.cloudfront.net')\n\n if (shouldUseCloudfront) {\n const transformations = []\n\n if (width) transformations.push(`width=${width.toString()}`)\n if (height) transformations.push(`height=${height.toString()}`)\n if (quality) transformations.push(`quality=${quality.toString()}`)\n transformations.push(`fit=contain`)\n\n const transformationsString = transformations.join('&')\n\n const fetchUrl = `${cloudfrontBaseUrl}/${url}?${transformationsString}`\n return fetchUrl\n }\n\n const transformations = []\n let transformationsString = ''\n\n if (width) transformations.push(`w_${width.toString()}`)\n if (height) transformations.push(`h_${height.toString()}`)\n if (quality) transformations.push(`q_${quality.toString()}`)\n if (fit) transformations.push('c_fit')\n\n transformationsString = `${transformations.join(',')}/`\n\n const fetchUrl = `${cloudinaryBaseUrl}/${transformationsString}${awsS3BaseUrl}/${url}`\n\n return fetchUrl\n}\n"],"mappings":"AAAA,OAAO,SAASA,aAAaA,CAACC,GAAG,EAAEC,OAAO,EAAE;EAC1C,IACEC,YAAY,GAOVD,OAAO,CAPTC,YAAY;IAAAC,qBAAA,GAOVF,OAAO,CANTG,iBAAiB;IAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,EAAE,GAAAA,qBAAA;IACtBE,iBAAiB,GAKfJ,OAAO,CALTI,iBAAiB;IACjBC,GAAG,GAIDL,OAAO,CAJTK,GAAG;IACHC,MAAM,GAGJN,OAAO,CAHTM,MAAM;IACNC,KAAK,GAEHP,OAAO,CAFTO,KAAK;IACLC,OAAO,GACLR,OAAO,CADTQ,OAAO;EAGT,IAAMC,mBAAmB,GACvBN,iBAAiB,IAAIA,iBAAiB,CAACO,QAAQ,CAAC,iBAAiB,CAAC;EAEpE,IAAID,mBAAmB,EAAE;IACvB,IAAME,gBAAe,GAAG,EAAE;IAE1B,IAAIJ,KAAK,EAAEI,gBAAe,CAACC,IAAI,UAAAC,MAAA,CAAUN,KAAK,CAACO,QAAQ,CAAC,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
-
{"version":3,"file":"index.js","names":["atob","btoa","fetchPonyfill","Promise","LIGHTHOUSE_LOGO_URL","imageNotFound","fetchImageForPdfGeneratorService","fetchImageForWeb","fetch","self","_typeof","contentTypes","defaultOptions","cache","fetchImage","url","options","arguments","length","undefined","shouldUseCloudfront","includes","isWebContext","window","encodedUrl","encodeURI","fetchOptions","_objectSpread","_options$isHeader","isHeader","then","response","contentHeader","headers","get","contentType","reject","Error","concat","ok","imageType","arrayBuffer","buffer","_ref","base64Flag","imageStr","arrayBufferToBase64","base64","isValid","validateBase64Image","catch","error","console","binary","bytes","slice","call","Uint8Array","forEach","b","String","fromCharCode","base64String","isJpeg","startsWith","validateJpegImage","isPng","validatePngImage","base64string","src","imageData","from","replace","c","charCodeAt","imageCorrupted","sequence","i"],"sources":["../../../src/helpers/fetch-image/index.js"],"sourcesContent":["import { atob, btoa } from '@lighthouse/abab'\nimport fetchPonyfill from 'fetch-ponyfill'\nimport Promise from 'bluebird'\nimport { LIGHTHOUSE_LOGO_URL } from '../../constants'\nimport { imageNotFound } from '../../images'\nimport { fetchImageForPdfGeneratorService } from '../fetch-image-for-pdf-generator-service'\nimport { fetchImageForWeb } from '../fetch-image-for-web'\n\n// NOTE use the native fetch if it's available in the browser, because the\n// ponyfill (which actually uses the github polyfill) does not support all the\n// same options as native fetch\nconst fetch =\n (typeof self === 'object' && self.fetch) || fetchPonyfill({ Promise }).fetch\n\nconst contentTypes = {\n 'image/png': 'png',\n 'image/jpeg': 'jpeg',\n}\n\nconst defaultOptions = {\n // NOTE The cache: no-cache option is important to avoid an issue with CORS\n // and caching on Chrome. Here's a good explanation of the issue:\n // https://stackoverflow.com/a/37455118\n // In our case, when loading the web version of a form, the signature image is\n // cached without the correct CORS headers. If the pdf is then generated,\n // there's a mismatch between the cached image headers and the CORS headers\n // sent from the fetch request, causing an error\n cache: 'no-cache',\n}\n\nexport function fetchImage(url, options = {}) {\n const shouldUseCloudfront = url && url.includes('.cloudfront.net')\n\n if (shouldUseCloudfront) {\n const isWebContext = typeof window === 'object'\n\n return isWebContext\n ? // Values used from options: isHeader, Signature, Policy, KeyPairId\n fetchImageForWeb(url, options)\n : fetchImageForPdfGeneratorService(url)\n }\n\n const encodedUrl = encodeURI(url)\n\n const fetchOptions = {\n ...defaultOptions,\n ...options,\n }\n const { isHeader = false } = options\n\n return fetch(encodedUrl, fetchOptions)\n .then(response => {\n const contentHeader = response.headers.get('content-length')\n const contentType = response.headers.get('content-type')\n\n // NOTE: the response will be ok but we won't be able to render any\n // image meaning pdfmake will error. Raise error here and return early.\n if (contentHeader === '0') {\n return Promise.reject(\n new Error(`Failed to fetch image as no content length: ${encodedUrl}`)\n )\n }\n\n if (!response.ok) {\n return Promise.reject(new Error(`Failed to fetch image: ${encodedUrl}`))\n }\n\n const imageType = contentTypes[contentType]\n\n return response.arrayBuffer().then(buffer => ({\n buffer,\n imageType,\n }))\n })\n .then(({ buffer, imageType }) => {\n const base64Flag = `data:image/${imageType};base64,`\n const imageStr = arrayBufferToBase64(buffer)\n\n const base64 = `${base64Flag}${imageStr}`\n const isValid = validateBase64Image(base64)\n\n if (!isValid) {\n return Promise.reject(new Error('InvalidImageError'))\n }\n\n return base64\n })\n .catch(error => {\n if (isHeader) {\n // NOTE: Replace failed headers with LH logo\n console.error('FetchImageHeaderError', error)\n return fetchImage(LIGHTHOUSE_LOGO_URL, defaultOptions)\n }\n\n console.error(error)\n return imageNotFound\n })\n}\n\nfunction arrayBufferToBase64(buffer) {\n let binary = ''\n const bytes = [].slice.call(new Uint8Array(buffer))\n\n bytes.forEach(b => (binary += String.fromCharCode(b)))\n\n return btoa(binary)\n}\n\nexport function validateBase64Image(base64String) {\n const isJpeg = base64String.startsWith('data:image/jpeg;base64,')\n\n if (isJpeg) return validateJpegImage(base64String)\n\n const isPng = base64String.startsWith('data:image/png;base64,')\n\n if (isPng) return validatePngImage(base64String)\n\n return false\n}\n\n// See SO for more info: https://stackoverflow.com/a/41635312\n// Fiddle: https://jsfiddle.net/Lnyxuchw/\nexport function validateJpegImage(base64string) {\n const src = base64string\n const imageData = Uint8Array.from(\n atob(src.replace('data:image/jpeg;base64,', '')),\n c => c.charCodeAt(0)\n )\n const imageCorrupted =\n imageData[imageData.length - 1] === 217 &&\n imageData[imageData.length - 2] === 255\n\n return imageCorrupted\n}\n\n// See SO for more info: https://stackoverflow.com/a/41635312\n// Fiddle: https://jsfiddle.net/Lnyxuchw/\nexport function validatePngImage(base64string) {\n const src = base64string\n const imageData = Uint8Array.from(\n atob(src.replace('data:image/png;base64,', '')),\n c => c.charCodeAt(0)\n )\n const sequence = [0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]\n\n //check last 12 elements of array so they contains needed values\n for (let i = 12; i > 0; i--) {\n if (imageData[imageData.length - i] !== sequence[12 - i]) {\n return false\n }\n }\n\n return true\n}\n"],"mappings":";;;;AAAA,SAASA,IAAI,EAAEC,IAAI,QAAQ,kBAAkB;AAC7C,OAAOC,aAAa,MAAM,gBAAgB;AAC1C,OAAOC,OAAO,MAAM,UAAU;AAC9B,SAASC,mBAAmB,QAAQ,iBAAiB;AACrD,SAASC,aAAa,QAAQ,cAAc;AAC5C,SAASC,gCAAgC,QAAQ,0CAA0C;AAC3F,SAASC,gBAAgB,QAAQ,wBAAwB;;AAEzD;AACA;AACA;AACA,IAAMC,KAAK,GACR,QAAOC,IAAI,iCAAAC,OAAA,CAAJD,IAAI,OAAK,QAAQ,IAAIA,IAAI,CAACD,KAAK,IAAKN,aAAa,CAAC;EAAEC,OAAO,EAAPA;AAAQ,CAAC,CAAC,CAACK,KAAK;AAE9E,IAAMG,YAAY,GAAG;EACnB,WAAW,EAAE,KAAK;EAClB,YAAY,EAAE;AAChB,CAAC;AAED,IAAMC,cAAc,GAAG;EACrB;EACA;EACA;EACA;EACA;EACA;EACA;EACAC,KAAK,EAAE;AACT,CAAC;AAED,OAAO,SAASC,UAAUA,CAACC,GAAG,EAAgB;EAAA,IAAdC,OAAO,GAAAC,SAAA,CAAAC,MAAA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AAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC;;EAE/D;EACA,KAAK,IAAIC,CAAC,GAAG,EAAE,EAAEA,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IAC3B,IAAIP,SAAS,CAACA,SAAS,CAACpD,MAAM,GAAG2D,CAAC,CAAC,KAAKD,QAAQ,CAAC,EAAE,GAAGC,CAAC,CAAC,EAAE;MACxD,OAAO,KAAK;IACd;EACF;EAEA,OAAO,IAAI;AACb","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["atob","btoa","fetchPonyfill","Promise","LIGHTHOUSE_LOGO_URL","imageNotFound","fetchImageForPdfGeneratorService","fetchImageForWeb","fetch","self","_typeof","contentTypes","defaultOptions","cache","fetchImage","url","options","arguments","length","undefined","shouldUseCloudfront","includes","isWebContext","window","encodedUrl","encodeURI","fetchOptions","_objectSpread","_options$isHeader","isHeader","then","response","contentHeader","headers","get","contentType","reject","Error","concat","ok","imageType","arrayBuffer","buffer","_ref","base64Flag","imageStr","arrayBufferToBase64","base64","isValid","validateBase64Image","catch","error","console","binary","bytes","slice","call","Uint8Array","forEach","b","String","fromCharCode","base64String","isJpeg","startsWith","validateJpegImage","isPng","validatePngImage","base64string","src","imageData","from","replace","c","charCodeAt","imageCorrupted","sequence","i"],"sources":["../../../src/helpers/fetch-image/index.js"],"sourcesContent":["import { atob, btoa } from '@lighthouse/abab'\nimport fetchPonyfill from 'fetch-ponyfill'\nimport Promise from 'bluebird'\nimport { LIGHTHOUSE_LOGO_URL } from '../../constants'\nimport { imageNotFound } from '../../images'\nimport { fetchImageForPdfGeneratorService } from '../fetch-image-for-pdf-generator-service'\nimport { fetchImageForWeb } from '../fetch-image-for-web'\n\n// NOTE use the native fetch if it's available in the browser, because the\n// ponyfill (which actually uses the github polyfill) does not support all the\n// same options as native fetch\nconst fetch =\n (typeof self === 'object' && self.fetch) || fetchPonyfill({ Promise }).fetch\n\nconst contentTypes = {\n 'image/png': 'png',\n 'image/jpeg': 'jpeg',\n}\n\nconst defaultOptions = {\n // NOTE The cache: no-cache option is important to avoid an issue with CORS\n // and caching on Chrome. Here's a good explanation of the issue:\n // https://stackoverflow.com/a/37455118\n // In our case, when loading the web version of a form, the signature image is\n // cached without the correct CORS headers. If the pdf is then generated,\n // there's a mismatch between the cached image headers and the CORS headers\n // sent from the fetch request, causing an error\n cache: 'no-cache',\n}\n\nexport function fetchImage(url, options = {}) {\n const shouldUseCloudfront = url && url.includes('.cloudfront.net')\n\n if (shouldUseCloudfront) {\n const isWebContext = typeof window === 'object'\n\n return isWebContext\n ? // Values used from options: isHeader, Signature, Policy, KeyPairId\n fetchImageForWeb(url, options)\n : fetchImageForPdfGeneratorService(url)\n }\n\n const encodedUrl = encodeURI(url)\n\n const fetchOptions = {\n ...defaultOptions,\n ...options,\n }\n const { isHeader = false } = options\n\n return fetch(encodedUrl, fetchOptions)\n .then(response => {\n const contentHeader = response.headers.get('content-length')\n const contentType = response.headers.get('content-type')\n\n // NOTE: the response will be ok but we won't be able to render any\n // image meaning pdfmake will error. Raise error here and return early.\n if (contentHeader === '0') {\n return Promise.reject(\n new Error(`Failed to fetch image as no content length: ${encodedUrl}`)\n )\n }\n\n if (!response.ok) {\n return Promise.reject(new Error(`Failed to fetch image: ${encodedUrl}`))\n }\n\n const imageType = contentTypes[contentType]\n\n return response.arrayBuffer().then(buffer => ({\n buffer,\n imageType,\n }))\n })\n .then(({ buffer, imageType }) => {\n const base64Flag = `data:image/${imageType};base64,`\n const imageStr = arrayBufferToBase64(buffer)\n\n const base64 = `${base64Flag}${imageStr}`\n const isValid = validateBase64Image(base64)\n\n if (!isValid) {\n return Promise.reject(new Error('InvalidImageError'))\n }\n\n return base64\n })\n .catch(error => {\n if (isHeader) {\n // NOTE: Replace failed headers with LH logo\n console.error('FetchImageHeaderError', error)\n return fetchImage(LIGHTHOUSE_LOGO_URL, defaultOptions)\n }\n\n console.error(error)\n return imageNotFound\n })\n}\n\nfunction arrayBufferToBase64(buffer) {\n let binary = ''\n const bytes = [].slice.call(new Uint8Array(buffer))\n\n bytes.forEach(b => (binary += String.fromCharCode(b)))\n\n return btoa(binary)\n}\n\nexport function validateBase64Image(base64String) {\n const isJpeg = base64String.startsWith('data:image/jpeg;base64,')\n\n if (isJpeg) return validateJpegImage(base64String)\n\n const isPng = base64String.startsWith('data:image/png;base64,')\n\n if (isPng) return validatePngImage(base64String)\n\n return false\n}\n\n// See SO for more info: https://stackoverflow.com/a/41635312\n// Fiddle: https://jsfiddle.net/Lnyxuchw/\nexport function validateJpegImage(base64string) {\n const src = base64string\n const imageData = Uint8Array.from(\n atob(src.replace('data:image/jpeg;base64,', '')),\n c => c.charCodeAt(0)\n )\n const imageCorrupted =\n imageData[imageData.length - 1] === 217 &&\n imageData[imageData.length - 2] === 255\n\n return imageCorrupted\n}\n\n// See SO for more info: https://stackoverflow.com/a/41635312\n// Fiddle: https://jsfiddle.net/Lnyxuchw/\nexport function validatePngImage(base64string) {\n const src = base64string\n const imageData = Uint8Array.from(\n atob(src.replace('data:image/png;base64,', '')),\n c => c.charCodeAt(0)\n )\n const sequence = [0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]\n\n //check last 12 elements of array so they contains needed values\n for (let i = 12; i > 0; i--) {\n if (imageData[imageData.length - i] !== sequence[12 - i]) {\n return false\n }\n }\n\n return true\n}\n"],"mappings":";;;;AAAA,SAASA,IAAI,EAAEC,IAAI,QAAQ,kBAAkB;AAC7C,OAAOC,aAAa,MAAM,gBAAgB;AAC1C,OAAOC,OAAO,MAAM,UAAU;AAC9B,SAASC,mBAAmB,QAAQ,iBAAiB;AACrD,SAASC,aAAa,QAAQ,cAAc;AAC5C,SAASC,gCAAgC,QAAQ,0CAA0C;AAC3F,SAASC,gBAAgB,QAAQ,wBAAwB;;AAEzD;AACA;AACA;AACA,IAAMC,KAAK,GACR,QAAOC,IAAI,iC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