@raytio/decrypt-helper 6.0.0 → 6.1.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/package.json +12 -3
- package/dist/api/authedFetch.d.ts +0 -1
- package/dist/api/authedFetch.js +0 -32
- package/dist/api/fetchAA.d.ts +0 -3
- package/dist/api/fetchAA.js +0 -19
- package/dist/api/fetchEnvConfig.d.ts +0 -6
- package/dist/api/fetchEnvConfig.js +0 -39
- package/dist/api/fetchInstanceData.d.ts +0 -3
- package/dist/api/fetchInstanceData.js +0 -21
- package/dist/api/getFiles.d.ts +0 -4
- package/dist/api/getFiles.js +0 -78
- package/dist/api/getLookupOption.d.ts +0 -2
- package/dist/api/getLookupOption.js +0 -32
- package/dist/api/getSchema.d.ts +0 -3
- package/dist/api/getSchema.js +0 -23
- package/dist/api/index.d.ts +0 -9
- package/dist/api/index.js +0 -25
- package/dist/api/resolveVerificationDetails.d.ts +0 -11
- package/dist/api/resolveVerificationDetails.js +0 -36
- package/dist/api/signIn.d.ts +0 -7
- package/dist/api/signIn.js +0 -56
- package/dist/api/updateInstanceData.d.ts +0 -2
- package/dist/api/updateInstanceData.js +0 -19
- package/dist/configureEnv.d.ts +0 -1
- package/dist/configureEnv.js +0 -30
- package/dist/constants.d.ts +0 -23
- package/dist/constants.js +0 -45
- package/dist/helpers/file.d.ts +0 -13
- package/dist/helpers/file.js +0 -17
- package/dist/helpers/formatOutput.d.ts +0 -28
- package/dist/helpers/formatOutput.js +0 -92
- package/dist/helpers/index.d.ts +0 -6
- package/dist/helpers/index.js +0 -22
- package/dist/helpers/json2csv.d.ts +0 -2
- package/dist/helpers/json2csv.js +0 -24
- package/dist/helpers/lookup.d.ts +0 -2
- package/dist/helpers/lookup.js +0 -22
- package/dist/helpers/setupMaxcryptor.d.ts +0 -4
- package/dist/helpers/setupMaxcryptor.js +0 -28
- package/dist/helpers/splitPOAndVers.d.ts +0 -2
- package/dist/helpers/splitPOAndVers.js +0 -11
- package/dist/helpers/types.d.ts +0 -1
- package/dist/helpers/types.js +0 -9
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -18
- package/dist/locales/index.d.ts +0 -44
- package/dist/locales/index.js +0 -22
- package/dist/locales/translations/en.json +0 -33
- package/dist/pdf/components/FieldVerificationBadge.d.ts +0 -6
- package/dist/pdf/components/FieldVerificationBadge.js +0 -19
- package/dist/pdf/components/Images.d.ts +0 -6
- package/dist/pdf/components/Images.js +0 -19
- package/dist/pdf/components/InnerTableRows.d.ts +0 -11
- package/dist/pdf/components/InnerTableRows.js +0 -37
- package/dist/pdf/components/POVerificationBadge.d.ts +0 -8
- package/dist/pdf/components/POVerificationBadge.js +0 -41
- package/dist/pdf/components/Report.d.ts +0 -13
- package/dist/pdf/components/Report.js +0 -98
- package/dist/pdf/components/Subheader.d.ts +0 -2
- package/dist/pdf/components/Subheader.js +0 -28
- package/dist/pdf/components/Table.d.ts +0 -9
- package/dist/pdf/components/Table.js +0 -47
- package/dist/pdf/components/TableTitle.d.ts +0 -5
- package/dist/pdf/components/TableTitle.js +0 -17
- package/dist/pdf/components/ValidationDisplay.d.ts +0 -5
- package/dist/pdf/components/ValidationDisplay.js +0 -29
- package/dist/pdf/components/VerifyBox.d.ts +0 -9
- package/dist/pdf/components/VerifyBox.js +0 -19
- package/dist/pdf/components/pieChart.d.ts +0 -6
- package/dist/pdf/components/pieChart.js +0 -27
- package/dist/pdf/constants.d.ts +0 -3
- package/dist/pdf/constants.js +0 -12
- package/dist/pdf/helpers/general.d.ts +0 -8
- package/dist/pdf/helpers/general.js +0 -37
- package/dist/pdf/helpers/transform.d.ts +0 -4
- package/dist/pdf/helpers/transform.js +0 -39
- package/dist/pdf/style.d.ts +0 -10
- package/dist/pdf/style.js +0 -24
- package/dist/public-methods/generatePDF.d.ts +0 -4
- package/dist/public-methods/generatePDF.js +0 -59
- package/dist/public-methods/getAndValidateConfig.d.ts +0 -8
- package/dist/public-methods/getAndValidateConfig.js +0 -20
- package/dist/public-methods/processSubmission.d.ts +0 -49
- package/dist/public-methods/processSubmission.js +0 -128
- package/dist/public-methods/saveToS3Bucket.d.ts +0 -2
- package/dist/public-methods/saveToS3Bucket.js +0 -58
- package/dist/public-methods/version.d.ts +0 -2
- package/dist/public-methods/version.js +0 -15
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Report = void 0;
|
|
7
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
-
const crypto_1 = require("crypto");
|
|
9
|
-
const core_1 = require("@raytio/core");
|
|
10
|
-
const locales_1 = require("../../locales");
|
|
11
|
-
const POVerificationBadge_1 = require("./POVerificationBadge");
|
|
12
|
-
const Subheader_1 = require("./Subheader");
|
|
13
|
-
const TableTitle_1 = require("./TableTitle");
|
|
14
|
-
const Table_1 = require("./Table");
|
|
15
|
-
const style_1 = require("../style");
|
|
16
|
-
const general_1 = require("../helpers/general");
|
|
17
|
-
const VerifyBox_1 = require("./VerifyBox");
|
|
18
|
-
const constants_1 = require("../constants");
|
|
19
|
-
const transform_1 = require("../helpers/transform");
|
|
20
|
-
const constants_2 = require("../../constants");
|
|
21
|
-
const version_1 = require("../../public-methods/version");
|
|
22
|
-
const Report = ({ data, files, config, aId, clientUrl, envConfig, }) => {
|
|
23
|
-
// The PDF is read only; there's no reason why anyone would ever need to unlock it.
|
|
24
|
-
const randomToken = (0, crypto_1.randomBytes)(32).toString("base64");
|
|
25
|
-
const schemas = Object.values(data.profile_objects).sort(
|
|
26
|
-
// sort it so that the person schema comes first
|
|
27
|
-
(a, b) => {
|
|
28
|
-
var _a, _b;
|
|
29
|
-
return +(((_a = b[0]) === null || _a === void 0 ? void 0 : _a.$schemaName) === constants_2.SCHEMA.PERSON) -
|
|
30
|
-
+(((_b = a[0]) === null || _b === void 0 ? void 0 : _b.$schemaName) === constants_2.SCHEMA.PERSON);
|
|
31
|
-
});
|
|
32
|
-
const appName = envConfig.app_name;
|
|
33
|
-
const iId = data.i_id === constants_1.NULL_I_ID ? "" : data.i_id;
|
|
34
|
-
return (jsx_pdf_1.default.createElement("document", { defaultStyle: { font: "Lato", fontSize: 12 }, info: {
|
|
35
|
-
title: (0, locales_1.$$)("Report.meta.title", { appName, iId }),
|
|
36
|
-
creator: appName,
|
|
37
|
-
producer: "Raytio",
|
|
38
|
-
subject: version_1.version,
|
|
39
|
-
},
|
|
40
|
-
// @ts-expect-error -- waiting on bpampuch/pdfmake#2453
|
|
41
|
-
lang: global.lang, ownerPassword: randomToken, permissions: {
|
|
42
|
-
printing: "highResolution",
|
|
43
|
-
copying: true, // allow copy/paste
|
|
44
|
-
}, pageSize: "A4", styles: style_1.classes, images: {
|
|
45
|
-
raytioLogo: envConfig.logo_url
|
|
46
|
-
? (0, general_1.asset)("custom-logo.png")
|
|
47
|
-
: (0, general_1.asset)("logo.png"),
|
|
48
|
-
} },
|
|
49
|
-
jsx_pdf_1.default.createElement("header", null, (currentPage) => currentPage !== 1 && (jsx_pdf_1.default.createElement("stack", { color: "#333", fontSize: 10 },
|
|
50
|
-
jsx_pdf_1.default.createElement("text", { margin: 16 },
|
|
51
|
-
jsx_pdf_1.default.createElement("text", { bold: true },
|
|
52
|
-
(0, locales_1.$$)("Report.header", { appName }),
|
|
53
|
-
" - "),
|
|
54
|
-
jsx_pdf_1.default.createElement("text", null, iId))))),
|
|
55
|
-
jsx_pdf_1.default.createElement("content", null,
|
|
56
|
-
jsx_pdf_1.default.createElement("image", { src: "raytioLogo", width: 150, alignment: "center" }),
|
|
57
|
-
jsx_pdf_1.default.createElement("text", { style: ["header", "marginBottom"], alignment: "center" }, (0, locales_1.$$)("Report.header", { appName })),
|
|
58
|
-
jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
|
|
59
|
-
jsx_pdf_1.default.createElement("column", { width: "auto" },
|
|
60
|
-
jsx_pdf_1.default.createElement("text", { style: ["subheader", "marginBottom"] },
|
|
61
|
-
iId &&
|
|
62
|
-
Object.entries(constants_1.SUBMISSION_DATA)
|
|
63
|
-
.map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
|
|
64
|
-
.join("\n"),
|
|
65
|
-
(0, core_1.isScoreResultValid)(data.score)
|
|
66
|
-
? [
|
|
67
|
-
"",
|
|
68
|
-
`${(0, locales_1.$$)("constants.score")}: ${data.score.score}`,
|
|
69
|
-
`${(0, locales_1.$$)("constants.score-category")}: ${data.score.category}`,
|
|
70
|
-
].join("\n")
|
|
71
|
-
: ""),
|
|
72
|
-
jsx_pdf_1.default.createElement(Subheader_1.Subheader, { data: data, config: config })),
|
|
73
|
-
jsx_pdf_1.default.createElement("column", { width: "*" },
|
|
74
|
-
jsx_pdf_1.default.createElement("text", null, " ")),
|
|
75
|
-
jsx_pdf_1.default.createElement("column", { width: 150 },
|
|
76
|
-
jsx_pdf_1.default.createElement(VerifyBox_1.VerifyBox, { aId: aId, iId: data.i_id, clientUrl: clientUrl }))),
|
|
77
|
-
schemas.map((POs) => {
|
|
78
|
-
// for each schema
|
|
79
|
-
return (jsx_pdf_1.default.createElement("stack", {
|
|
80
|
-
// unbreakable is off because it crashes if its too big for one page
|
|
81
|
-
// This is a 7-year-old issue in pdfmake (https://github.com/bpampuch/pdfmake/issues/207)
|
|
82
|
-
unbreakable: false, style: "marginY" },
|
|
83
|
-
jsx_pdf_1.default.createElement(TableTitle_1.TableTitle, { POs: POs }),
|
|
84
|
-
jsx_pdf_1.default.createElement("columns", { columnGap: 15 },
|
|
85
|
-
jsx_pdf_1.default.createElement("column", { width: 80 },
|
|
86
|
-
jsx_pdf_1.default.createElement(POVerificationBadge_1.POVerificationBadge, { width: 80, POs: POs })),
|
|
87
|
-
jsx_pdf_1.default.createElement("column", { width: "auto" },
|
|
88
|
-
jsx_pdf_1.default.createElement(Table_1.Table, { POs: POs, files: files, config: config })))));
|
|
89
|
-
})),
|
|
90
|
-
jsx_pdf_1.default.createElement("footer", null, (currentPage, pageCount, pageSize) => (jsx_pdf_1.default.createElement("stack", { bold: true, color: "#333", fontSize: 10 },
|
|
91
|
-
jsx_pdf_1.default.createElement("text", { margin: 16 },
|
|
92
|
-
jsx_pdf_1.default.createElement("text", null,
|
|
93
|
-
(0, locales_1.$$)("Report.header", { appName }),
|
|
94
|
-
" - "),
|
|
95
|
-
jsx_pdf_1.default.createElement("text", { color: "#fb7171" }, (0, locales_1.$$)("Report.footer-private"))),
|
|
96
|
-
jsx_pdf_1.default.createElement("text", { absolutePosition: { x: pageSize.width - 50, y: 15 } }, (0, locales_1.$$)("Report.pagecount", { currentPage, pageCount })))))));
|
|
97
|
-
};
|
|
98
|
-
exports.Report = Report;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Subheader = void 0;
|
|
7
|
-
const types_1 = require("@raytio/types");
|
|
8
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
9
|
-
const locales_1 = require("../../locales");
|
|
10
|
-
const FieldVerificationBadge_1 = require("./FieldVerificationBadge");
|
|
11
|
-
const Subheader = () => {
|
|
12
|
-
return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
|
|
13
|
-
jsx_pdf_1.default.createElement("text", { bold: true, style: "marginBottom" }, "Key:"),
|
|
14
|
-
jsx_pdf_1.default.createElement("table", { layout: "noBorders" },
|
|
15
|
-
jsx_pdf_1.default.createElement("row", null,
|
|
16
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
17
|
-
jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: types_1.FieldVerification.Verified })),
|
|
18
|
-
jsx_pdf_1.default.createElement("cell", null, (0, locales_1.$$)("FieldVerification.Verified"))),
|
|
19
|
-
jsx_pdf_1.default.createElement("row", null,
|
|
20
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
21
|
-
jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: types_1.FieldVerification.NotVerified })),
|
|
22
|
-
jsx_pdf_1.default.createElement("cell", null, (0, locales_1.$$)("FieldVerification.NotVerified"))),
|
|
23
|
-
jsx_pdf_1.default.createElement("row", null,
|
|
24
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
25
|
-
jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: types_1.FieldVerification.VerifiedFalse })),
|
|
26
|
-
jsx_pdf_1.default.createElement("cell", null, (0, locales_1.$$)("FieldVerification.VerifiedFalse"))))));
|
|
27
|
-
};
|
|
28
|
-
exports.Subheader = Subheader;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/// <reference types="jsx-pdf" />
|
|
2
|
-
import { PdfConfig } from "../types";
|
|
3
|
-
import { FlatPO } from "../../helpers";
|
|
4
|
-
import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
|
|
5
|
-
export declare const Table: ({ POs, files, config, }: {
|
|
6
|
-
POs: FlatPO[];
|
|
7
|
-
files: ProcessSubmissionOutput["files"];
|
|
8
|
-
config: PdfConfig;
|
|
9
|
-
}) => JSX.Element;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Table = void 0;
|
|
7
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
-
const general_1 = require("../helpers/general");
|
|
9
|
-
const FieldVerificationBadge_1 = require("./FieldVerificationBadge");
|
|
10
|
-
const Images_1 = require("./Images");
|
|
11
|
-
const InnerTableRows_1 = require("./InnerTableRows");
|
|
12
|
-
const helpers_1 = require("../../helpers");
|
|
13
|
-
const Table = ({ POs, files, config, }) => {
|
|
14
|
-
/** every fieldName in these profile object */
|
|
15
|
-
const fieldNames = [
|
|
16
|
-
...new Set(POs.flatMap((PO) => Object.keys(PO.$properties))),
|
|
17
|
-
];
|
|
18
|
-
// some or all POs in this schema are files themselves. So render the file, assuming it's an image
|
|
19
|
-
const fileNIds = POs.filter(helpers_1.isPOFile).map((x) => x.$nId);
|
|
20
|
-
if (fileNIds.length)
|
|
21
|
-
return jsx_pdf_1.default.createElement(Images_1.Images, { nIds: fileNIds, files: files });
|
|
22
|
-
const imageFieldNames = fieldNames.filter((fieldName) => POs.map((PO) => { var _a; return (_a = PO.$properties[fieldName]) === null || _a === void 0 ? void 0 : _a.value; }).some(helpers_1.isFieldValueFile));
|
|
23
|
-
return (jsx_pdf_1.default.createElement("table", { layout: "noBorders" }, fieldNames.map((fieldName) => {
|
|
24
|
-
var _a;
|
|
25
|
-
return (jsx_pdf_1.default.createElement("row", null,
|
|
26
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
27
|
-
jsx_pdf_1.default.createElement("text", { color: "#12130e" }, ((_a = POs.find((PO) => PO.$properties[fieldName])) === null || _a === void 0 ? void 0 : _a.$properties[fieldName].title) || fieldName)),
|
|
28
|
-
POs.flatMap((PO) => {
|
|
29
|
-
(0, helpers_1.assertSafeProperty)(fieldName);
|
|
30
|
-
// if we're sharing multiple POs in this schema, and this field doesn't exist on this paticular PO,
|
|
31
|
-
// then just render some empty cells
|
|
32
|
-
if (!PO.$properties[fieldName]) {
|
|
33
|
-
return [jsx_pdf_1.default.createElement("cell", null, " "), jsx_pdf_1.default.createElement("cell", null, " ")];
|
|
34
|
-
}
|
|
35
|
-
const { value, formatted_value, verification } = PO.$properties[fieldName];
|
|
36
|
-
const color = (0, general_1.verifyColour)(verification);
|
|
37
|
-
// jsx-pdf currently doesn't support fragments, will make a PR at some point
|
|
38
|
-
return [
|
|
39
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
40
|
-
jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: verification })),
|
|
41
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
42
|
-
jsx_pdf_1.default.createElement(InnerTableRows_1.InnerTableRows, { key: fieldName, value: formatted_value || value, files: files, config: config, color: color, imageFieldNames: imageFieldNames })),
|
|
43
|
-
];
|
|
44
|
-
})));
|
|
45
|
-
})));
|
|
46
|
-
};
|
|
47
|
-
exports.Table = Table;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TableTitle = void 0;
|
|
7
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
-
const helpers_1 = require("../../helpers");
|
|
9
|
-
const TableTitle = ({ POs }) => {
|
|
10
|
-
var _a;
|
|
11
|
-
const schemaTitle = POs[0].$schemaTitle;
|
|
12
|
-
const maybeFileName = POs.some(helpers_1.isPOFile)
|
|
13
|
-
? (_a = POs[0].$properties.title) === null || _a === void 0 ? void 0 : _a.value
|
|
14
|
-
: undefined;
|
|
15
|
-
return (jsx_pdf_1.default.createElement("text", { bold: true, fontSize: 14, style: "marginBottom" }, maybeFileName || schemaTitle));
|
|
16
|
-
};
|
|
17
|
-
exports.TableTitle = TableTitle;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ValidationDisplay = void 0;
|
|
7
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
-
const locales_1 = require("../../locales");
|
|
9
|
-
const pieChart_1 = require("./pieChart");
|
|
10
|
-
const helpers_1 = require("../../helpers");
|
|
11
|
-
const SEVERITY_COLOURS = {
|
|
12
|
-
low: "#2e8bc0",
|
|
13
|
-
medium: "#ff9800",
|
|
14
|
-
high: "#fb7171",
|
|
15
|
-
};
|
|
16
|
-
const ValidationDisplay = ({ value, }) => {
|
|
17
|
-
const colour = value.score > 0.5 ? "#c2d887" : "#fb7171";
|
|
18
|
-
return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
|
|
19
|
-
jsx_pdf_1.default.createElement("svg", { content: (0, pieChart_1.pieChart)(colour, value.score * 100), width: 50 }),
|
|
20
|
-
(0, locales_1.$$)("ValidationDisplay.text", { n: value.score * 10 }),
|
|
21
|
-
Object.values(value.breakdown)
|
|
22
|
-
.filter((x) => x.severity && x.reason)
|
|
23
|
-
.map((x) => {
|
|
24
|
-
const key = x.severity;
|
|
25
|
-
(0, helpers_1.assertSafeProperty)(key);
|
|
26
|
-
return jsx_pdf_1.default.createElement("text", { color: SEVERITY_COLOURS[key] }, x.reason);
|
|
27
|
-
})));
|
|
28
|
-
};
|
|
29
|
-
exports.ValidationDisplay = ValidationDisplay;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.VerifyBox = void 0;
|
|
7
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
-
const locales_1 = require("../../locales");
|
|
9
|
-
const constants_1 = require("../constants");
|
|
10
|
-
const VerifyBox = ({ aId, iId, clientUrl }) => {
|
|
11
|
-
if (iId === constants_1.NULL_I_ID)
|
|
12
|
-
return null;
|
|
13
|
-
const url = `${clientUrl}/apps/s/${aId}/i/${iId}`;
|
|
14
|
-
return (jsx_pdf_1.default.createElement("stack", { alignment: "center" },
|
|
15
|
-
jsx_pdf_1.default.createElement("text", { link: url }, (0, locales_1.$$)("VerifyBox.text")),
|
|
16
|
-
jsx_pdf_1.default.createElement("qr", { content: url, fit: 150 }),
|
|
17
|
-
jsx_pdf_1.default.createElement("text", { color: "#1e90ff", fontSize: 9, link: url, alignment: "left" }, url)));
|
|
18
|
-
};
|
|
19
|
-
exports.VerifyBox = VerifyBox;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pieChart = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* A semi-cirle pie chart
|
|
6
|
-
* (!) generates a SVG string, not a JSX component.
|
|
7
|
-
* @param percentage a number from 0 to 100
|
|
8
|
-
*/
|
|
9
|
-
function pieChart(colour, percentage) {
|
|
10
|
-
return `
|
|
11
|
-
<svg height="70" width="140" viewBox="0 -5 20 15">
|
|
12
|
-
<circle r="10" cx="10" cy="10" fill="bisque" />
|
|
13
|
-
<circle
|
|
14
|
-
r="5"
|
|
15
|
-
cx="10"
|
|
16
|
-
cy="10"
|
|
17
|
-
fill="white"
|
|
18
|
-
stroke="${colour}"
|
|
19
|
-
stroke-width="10"
|
|
20
|
-
stroke-dasharray="${(((percentage / 2) * 31.42) / 100).toFixed(2 // NOTE: css calc() doesn't work in PDFs
|
|
21
|
-
)} 31.42"
|
|
22
|
-
transform="rotate(-180) translate(-20, -20)"
|
|
23
|
-
/>
|
|
24
|
-
</svg>
|
|
25
|
-
`;
|
|
26
|
-
}
|
|
27
|
-
exports.pieChart = pieChart;
|
package/dist/pdf/constants.d.ts
DELETED
package/dist/pdf/constants.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SUBMISSION_DATA = exports.NULL_I_ID = void 0;
|
|
4
|
-
const locales_1 = require("../locales");
|
|
5
|
-
exports.NULL_I_ID = "00000000-0000-0000-0000-000000000000";
|
|
6
|
-
exports.SUBMISSION_DATA = {
|
|
7
|
-
confirmation_code: (0, locales_1.$$)("constants.confirmation_code"),
|
|
8
|
-
i_id: (0, locales_1.$$)("constants.i_id"),
|
|
9
|
-
reference: (0, locales_1.$$)("constants.reference"),
|
|
10
|
-
start_date: (0, locales_1.$$)("constants.start_date"),
|
|
11
|
-
end_date: (0, locales_1.$$)("constants.end_date"),
|
|
12
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { FieldVerification, POVerification } from "@raytio/types";
|
|
2
|
-
export declare const asset: (name: string) => string;
|
|
3
|
-
export declare const loadAsset: (name: string) => string;
|
|
4
|
-
export declare const verifyColour: (x: FieldVerification | POVerification) => string;
|
|
5
|
-
/**
|
|
6
|
-
* Produces a date with a long month
|
|
7
|
-
*/
|
|
8
|
-
export declare const formatDate: (d: Date, locale: string, timeZone: string) => string;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatDate = exports.verifyColour = exports.loadAsset = exports.asset = void 0;
|
|
4
|
-
const types_1 = require("@raytio/types");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const asset = (name) => {
|
|
8
|
-
if (name.match(/[^A-Za-z\-_.]/) || name.includes("..")) {
|
|
9
|
-
throw new Error("Invalid asset name");
|
|
10
|
-
}
|
|
11
|
-
return (0, path_1.join)(__dirname, "../../../assets/", name);
|
|
12
|
-
};
|
|
13
|
-
exports.asset = asset;
|
|
14
|
-
const loadAsset = (name) => (0, fs_1.readFileSync)((0, exports.asset)(name), { encoding: "utf-8" });
|
|
15
|
-
exports.loadAsset = loadAsset;
|
|
16
|
-
const verifyColour = (x) => {
|
|
17
|
-
if (x === types_1.FieldVerification.Verified)
|
|
18
|
-
return "#12130e";
|
|
19
|
-
if (x === types_1.FieldVerification.VerifiedFalse ||
|
|
20
|
-
x === types_1.POVerification.VerifiedFalse) {
|
|
21
|
-
return "#fb7171";
|
|
22
|
-
}
|
|
23
|
-
return "#000";
|
|
24
|
-
};
|
|
25
|
-
exports.verifyColour = verifyColour;
|
|
26
|
-
/**
|
|
27
|
-
* Produces a date with a long month
|
|
28
|
-
*/
|
|
29
|
-
const formatDate = (d, locale, timeZone) => new Intl.DateTimeFormat(locale, {
|
|
30
|
-
day: "2-digit",
|
|
31
|
-
month: "long",
|
|
32
|
-
year: "numeric",
|
|
33
|
-
hour: "numeric",
|
|
34
|
-
minute: "numeric",
|
|
35
|
-
timeZone,
|
|
36
|
-
}).format(d);
|
|
37
|
-
exports.formatDate = formatDate;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { PdfConfig } from "../types";
|
|
2
|
-
export declare const IS_IMAGE: unique symbol;
|
|
3
|
-
export declare const IS_ARRAY_OF_OBJECTS: unique symbol;
|
|
4
|
-
export declare function transform(key: string, value: unknown, pdfConfig: PdfConfig, imageFieldNames?: string[]): string | typeof IS_IMAGE | typeof IS_ARRAY_OF_OBJECTS;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transform = exports.IS_ARRAY_OF_OBJECTS = exports.IS_IMAGE = void 0;
|
|
4
|
-
const core_1 = require("@raytio/core");
|
|
5
|
-
const locales_1 = require("../../locales");
|
|
6
|
-
const general_1 = require("./general");
|
|
7
|
-
exports.IS_IMAGE = Symbol.for("image");
|
|
8
|
-
exports.IS_ARRAY_OF_OBJECTS = Symbol.for("ArrayOfObjects");
|
|
9
|
-
function transform(key, value, pdfConfig, imageFieldNames) {
|
|
10
|
-
// value is possible to be false if type boolean
|
|
11
|
-
if (value === undefined) {
|
|
12
|
-
return (0, locales_1.$$)("field.undefined");
|
|
13
|
-
}
|
|
14
|
-
if (typeof value === "boolean") {
|
|
15
|
-
return value ? (0, locales_1.$$)("field.boolean.yes") : (0, locales_1.$$)("field.boolean.no");
|
|
16
|
-
}
|
|
17
|
-
if (imageFieldNames === null || imageFieldNames === void 0 ? void 0 : imageFieldNames.includes(key)) {
|
|
18
|
-
return exports.IS_IMAGE;
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(value)) {
|
|
21
|
-
if (value.every((v) => typeof v === "object")) {
|
|
22
|
-
return exports.IS_ARRAY_OF_OBJECTS;
|
|
23
|
-
}
|
|
24
|
-
return value.join(", ");
|
|
25
|
-
}
|
|
26
|
-
if (typeof value !== "string") {
|
|
27
|
-
return `${value}`;
|
|
28
|
-
}
|
|
29
|
-
switch (key) {
|
|
30
|
-
case "start_date":
|
|
31
|
-
case "end_date": {
|
|
32
|
-
return (0, general_1.formatDate)((0, core_1.repairDate)(value), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
|
|
33
|
-
}
|
|
34
|
-
default: {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.transform = transform;
|
package/dist/pdf/style.d.ts
DELETED
package/dist/pdf/style.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fonts = exports.classes = void 0;
|
|
4
|
-
const general_1 = require("./helpers/general");
|
|
5
|
-
exports.classes = {
|
|
6
|
-
header: {
|
|
7
|
-
fontSize: 18,
|
|
8
|
-
},
|
|
9
|
-
listing: {
|
|
10
|
-
fontSize: 10,
|
|
11
|
-
color: "#333",
|
|
12
|
-
},
|
|
13
|
-
// [l, t, r, b]
|
|
14
|
-
marginBottom: { margin: [0, 0, 0, 10] },
|
|
15
|
-
marginY: { margin: [0, 15, 0, 15] },
|
|
16
|
-
};
|
|
17
|
-
exports.fonts = {
|
|
18
|
-
Lato: {
|
|
19
|
-
normal: (0, general_1.asset)("Lato-Light.ttf"),
|
|
20
|
-
bold: (0, general_1.asset)("Lato-Bold.ttf"),
|
|
21
|
-
italics: (0, general_1.asset)("Lato-LightItalic.ttf"),
|
|
22
|
-
bolditalics: (0, general_1.asset)("Lato-BoldItalic.ttf"),
|
|
23
|
-
},
|
|
24
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { TDocumentDefinitions } from "pdfmake/interfaces";
|
|
2
|
-
import { ProcessSubmissionOutput } from "./processSubmission";
|
|
3
|
-
export declare function generatePdfJson(data: ProcessSubmissionOutput, DATE_FORMAT: string, TIMEZONE: string): TDocumentDefinitions;
|
|
4
|
-
export declare const generatePDF: () => (data: ProcessSubmissionOutput) => Promise<ProcessSubmissionOutput>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.generatePDF = exports.generatePdfJson = void 0;
|
|
16
|
-
const pdfmake_1 = __importDefault(require("pdfmake"));
|
|
17
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
18
|
-
const fs_1 = require("fs");
|
|
19
|
-
const path_1 = require("path");
|
|
20
|
-
const locales_1 = require("../locales");
|
|
21
|
-
const Report_1 = require("../pdf/components/Report");
|
|
22
|
-
const style_1 = require("../pdf/style");
|
|
23
|
-
function generatePdfJson(data, DATE_FORMAT, TIMEZONE) {
|
|
24
|
-
return jsx_pdf_1.default.renderPdf(jsx_pdf_1.default.createElement(Report_1.Report, { data: data.json, files: data.files, aId: data.a_id, clientUrl: data.client_url, envConfig: data.envConfig, config: { DATE_FORMAT, TIMEZONE } }));
|
|
25
|
-
}
|
|
26
|
-
exports.generatePdfJson = generatePdfJson;
|
|
27
|
-
const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
console.log("Generating PDF Report...");
|
|
29
|
-
const { DATE_FORMAT = "en-nz", TIMEZONE = "Pacific/Auckland" } = process.env;
|
|
30
|
-
if (data.envConfig.logo_url) {
|
|
31
|
-
// there is a white labelling URL, so fetch it and write it to disk, overriding the default logo
|
|
32
|
-
const arrayBuf = yield fetch(data.envConfig.logo_url).then((r) => r.arrayBuffer());
|
|
33
|
-
yield fs_1.promises.writeFile((0, path_1.join)(__dirname, "../../assets/custom-logo.png"), Buffer.from(arrayBuf));
|
|
34
|
-
}
|
|
35
|
-
const customLang = process.env.PDF_LANGUAGE;
|
|
36
|
-
if (customLang) {
|
|
37
|
-
if ((0, locales_1.isValidLocale)(customLang)) {
|
|
38
|
-
global.lang = customLang;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
console.warn(`The specified PDF_LANGUAGE is language is invalid (${customLang})`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return new Promise((resolve) => {
|
|
45
|
-
const printer = new pdfmake_1.default(style_1.fonts);
|
|
46
|
-
const pdfDoc = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE));
|
|
47
|
-
const chunks = [];
|
|
48
|
-
pdfDoc.on("data", (chunk) => chunks.push(chunk));
|
|
49
|
-
pdfDoc.on("end", () => {
|
|
50
|
-
const final = Buffer.concat(chunks);
|
|
51
|
-
const dataUrl = `data:application/pdf;base64,${final.toString("base64")}`;
|
|
52
|
-
resolve(Object.assign(Object.assign({}, data), { files: Object.assign(Object.assign({}, data.files), {
|
|
53
|
-
// do not change name, will be a breaking change
|
|
54
|
-
[data.json.i_id]: [dataUrl, "pdf"] }) }));
|
|
55
|
-
});
|
|
56
|
-
pdfDoc.end();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
exports.generatePDF = generatePDF;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Config } from "../constants";
|
|
2
|
-
/**
|
|
3
|
-
* This helper is designed for environments where the configuration
|
|
4
|
-
* options are in the environment variables, such as AWS lambda.
|
|
5
|
-
* It extracts the relevant ENV variables and throws an error if
|
|
6
|
-
* any are missing.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getAndValidateConfig(): Config;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAndValidateConfig = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
5
|
-
/**
|
|
6
|
-
* This helper is designed for environments where the configuration
|
|
7
|
-
* options are in the environment variables, such as AWS lambda.
|
|
8
|
-
* It extracts the relevant ENV variables and throws an error if
|
|
9
|
-
* any are missing.
|
|
10
|
-
*/
|
|
11
|
-
function getAndValidateConfig() {
|
|
12
|
-
const CONFIG = constants_1.ENV_VARIABLES.reduce((acc, name) => {
|
|
13
|
-
const value = process.env[name];
|
|
14
|
-
if (!value)
|
|
15
|
-
throw new Error(`${name} is not configured`);
|
|
16
|
-
return Object.assign(Object.assign({}, acc), { [name]: value });
|
|
17
|
-
}, {});
|
|
18
|
-
return CONFIG;
|
|
19
|
-
}
|
|
20
|
-
exports.getAndValidateConfig = getAndValidateConfig;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { AId, IId, Instance, RealVer } from "@raytio/types";
|
|
2
|
-
import { Config, InstanceDataToPassOn } from "../constants";
|
|
3
|
-
import { FlatPO } from "../helpers";
|
|
4
|
-
import { EnvConfig } from "../api";
|
|
5
|
-
import { ApplicationEncryptorLike } from "../types";
|
|
6
|
-
type DecryptData = {
|
|
7
|
-
apiToken: string;
|
|
8
|
-
instance: Instance;
|
|
9
|
-
encryptedInstance: Instance;
|
|
10
|
-
applicationDecryptor: ApplicationEncryptorLike;
|
|
11
|
-
realVers?: RealVer[];
|
|
12
|
-
};
|
|
13
|
-
export interface ProcessSubmissionInput {
|
|
14
|
-
/** The a_id of the application */
|
|
15
|
-
applicationId: AId;
|
|
16
|
-
/** The i_id of this submission */
|
|
17
|
-
instanceId: IId;
|
|
18
|
-
/** whether to enable extra logging. Default = false */
|
|
19
|
-
verbose?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* the configuration options. You can extract these from the environment
|
|
22
|
-
* variables by using @see getAndValidateConfig
|
|
23
|
-
*/
|
|
24
|
-
config: Config;
|
|
25
|
-
/** You can optionally supply Instance data and an API token - for Raytio internal use */
|
|
26
|
-
_supliedConfig?: DecryptData;
|
|
27
|
-
}
|
|
28
|
-
export interface ProcessSubmissionOutput {
|
|
29
|
-
/** details of the submission, included the decrypted profile objects */
|
|
30
|
-
json: InstanceDataToPassOn & {
|
|
31
|
-
profile_objects: {
|
|
32
|
-
[schemaName: string]: FlatPO[];
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
/** A string of a CSV file containing the same data as in `json` */
|
|
36
|
-
csv: string;
|
|
37
|
-
/** an object of files that were attached to the submission, such as images */
|
|
38
|
-
files: {
|
|
39
|
-
[nId: string]: [dataUrl: string, fileExtension: string];
|
|
40
|
-
};
|
|
41
|
-
/** the a_id is passed on */
|
|
42
|
-
a_id: AId;
|
|
43
|
-
/** passed down so that pdf generation has access to it */
|
|
44
|
-
client_url: string;
|
|
45
|
-
/** passed down so that pdf generation has access to it */
|
|
46
|
-
envConfig: EnvConfig;
|
|
47
|
-
}
|
|
48
|
-
export declare function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }: ProcessSubmissionInput): Promise<ProcessSubmissionOutput>;
|
|
49
|
-
export {};
|