@raytio/decrypt-helper 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/authedFetch.d.ts +1 -0
- package/dist/api/authedFetch.js +33 -0
- package/dist/api/fetchAA.d.ts +3 -0
- package/dist/api/fetchAA.js +22 -0
- package/dist/api/fetchEnvConfig.d.ts +6 -0
- package/dist/api/fetchEnvConfig.js +39 -0
- package/dist/api/fetchInstanceData.d.ts +3 -0
- package/dist/api/fetchInstanceData.js +21 -0
- package/dist/api/getFiles.d.ts +6 -0
- package/dist/api/getFiles.js +92 -0
- package/dist/api/getLookupOption.d.ts +2 -0
- package/dist/api/getLookupOption.js +32 -0
- package/dist/api/getSchema.d.ts +3 -0
- package/dist/api/getSchema.js +23 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.js +25 -0
- package/dist/api/resolveVerificationDetails.d.ts +11 -0
- package/dist/api/resolveVerificationDetails.js +36 -0
- package/dist/api/signIn.d.ts +7 -0
- package/dist/api/signIn.js +56 -0
- package/dist/api/updateInstanceData.d.ts +2 -0
- package/dist/api/updateInstanceData.js +19 -0
- package/dist/api/uploadToObjectStore.d.ts +5 -0
- package/dist/api/uploadToObjectStore.js +42 -0
- package/dist/api/videoToImage.d.ts +3 -0
- package/dist/api/videoToImage.js +30 -0
- package/dist/configureEnv.d.ts +1 -0
- package/dist/configureEnv.js +30 -0
- package/dist/constants.d.ts +23 -0
- package/dist/constants.js +45 -0
- package/dist/helpers/file.d.ts +13 -0
- package/dist/helpers/file.js +17 -0
- package/dist/helpers/formatOutput.d.ts +28 -0
- package/dist/helpers/formatOutput.js +93 -0
- package/dist/helpers/index.d.ts +6 -0
- package/dist/helpers/index.js +22 -0
- package/dist/helpers/json2csv.d.ts +2 -0
- package/dist/helpers/json2csv.js +24 -0
- package/dist/helpers/lookup.d.ts +2 -0
- package/dist/helpers/lookup.js +22 -0
- package/dist/helpers/setupMaxcryptor.d.ts +4 -0
- package/dist/helpers/setupMaxcryptor.js +28 -0
- package/dist/helpers/splitPOAndVers.d.ts +2 -0
- package/dist/helpers/splitPOAndVers.js +12 -0
- package/dist/helpers/types.d.ts +1 -0
- package/dist/helpers/types.js +9 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -0
- package/dist/locales/index.d.ts +44 -0
- package/dist/locales/index.js +22 -0
- package/dist/locales/translations/en.json +33 -0
- package/dist/pdf/components/FieldVerificationBadge.d.ts +6 -0
- package/dist/pdf/components/FieldVerificationBadge.js +19 -0
- package/dist/pdf/components/Images.d.ts +6 -0
- package/dist/pdf/components/Images.js +20 -0
- package/dist/pdf/components/InnerTableRows.d.ts +11 -0
- package/dist/pdf/components/InnerTableRows.js +37 -0
- package/dist/pdf/components/POVerificationBadge.d.ts +8 -0
- package/dist/pdf/components/POVerificationBadge.js +41 -0
- package/dist/pdf/components/Report.d.ts +13 -0
- package/dist/pdf/components/Report.js +98 -0
- package/dist/pdf/components/Subheader.d.ts +2 -0
- package/dist/pdf/components/Subheader.js +28 -0
- package/dist/pdf/components/Table.d.ts +9 -0
- package/dist/pdf/components/Table.js +47 -0
- package/dist/pdf/components/TableTitle.d.ts +5 -0
- package/dist/pdf/components/TableTitle.js +17 -0
- package/dist/pdf/components/ValidationDisplay.d.ts +5 -0
- package/dist/pdf/components/ValidationDisplay.js +29 -0
- package/dist/pdf/components/VerifyBox.d.ts +9 -0
- package/dist/pdf/components/VerifyBox.js +19 -0
- package/dist/pdf/components/pieChart.d.ts +6 -0
- package/dist/pdf/components/pieChart.js +27 -0
- package/dist/pdf/constants.d.ts +3 -0
- package/dist/pdf/constants.js +12 -0
- package/dist/pdf/helpers/general.d.ts +8 -0
- package/dist/pdf/helpers/general.js +37 -0
- package/dist/pdf/helpers/transform.d.ts +4 -0
- package/dist/pdf/helpers/transform.js +39 -0
- package/dist/pdf/style.d.ts +10 -0
- package/dist/pdf/style.js +24 -0
- package/dist/public-methods/generatePDF.d.ts +4 -0
- package/dist/public-methods/generatePDF.js +60 -0
- package/dist/public-methods/getAndValidateConfig.d.ts +8 -0
- package/dist/public-methods/getAndValidateConfig.js +20 -0
- package/dist/public-methods/processSubmission.d.ts +49 -0
- package/dist/public-methods/processSubmission.js +128 -0
- package/dist/public-methods/saveToS3Bucket.d.ts +2 -0
- package/dist/public-methods/saveToS3Bucket.js +60 -0
- package/dist/public-methods/version.d.ts +2 -0
- package/dist/public-methods/version.js +15 -0
- package/package.json +12 -12
|
@@ -0,0 +1,41 @@
|
|
|
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.POVerificationBadge = exports.FILE_MAP = 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 general_1 = require("../helpers/general");
|
|
11
|
+
const constants_1 = require("../../constants");
|
|
12
|
+
exports.FILE_MAP = {
|
|
13
|
+
[types_1.POVerification.FullyVerified]: "verified_user_big",
|
|
14
|
+
[types_1.POVerification.PartiallyVerified]: "verified_partial_big",
|
|
15
|
+
[types_1.POVerification.NotVerified]: "not_verified_big",
|
|
16
|
+
[types_1.POVerification.Expired]: "not_verified_big",
|
|
17
|
+
[types_1.POVerification.VerifiedFalse]: "false_verified_user_big",
|
|
18
|
+
// not possible but included here for completeness
|
|
19
|
+
[types_1.POVerification.Encrypted]: "not_verified_big",
|
|
20
|
+
[types_1.POVerification.Loading]: "not_verified_big",
|
|
21
|
+
};
|
|
22
|
+
const POVerificationBadge = ({ width, POs, }) => {
|
|
23
|
+
// TODO: this won't work if multiple POs of the same schema are shared
|
|
24
|
+
const { $badges, $verification_details, $shouldBeVerifiedFields } = POs[0];
|
|
25
|
+
const verifiedBy = $verification_details === null || $verification_details === void 0 ? void 0 : $verification_details.verifier_id;
|
|
26
|
+
return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
|
|
27
|
+
$shouldBeVerifiedFields && (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
|
|
28
|
+
jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$badges.verified.code]}.svg`), width: width }),
|
|
29
|
+
jsx_pdf_1.default.createElement("text", { alignment: "center" }, constants_1.PO_VER_TEXT_MAP[$badges.verified.code]),
|
|
30
|
+
verifiedBy && (jsx_pdf_1.default.createElement("text", { alignment: "center" }, (0, locales_1.$$)("POVerificationBadge.verified-by", { verifiedBy }))))),
|
|
31
|
+
$badges.safeHarbour && (jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
|
|
32
|
+
jsx_pdf_1.default.createElement("column", { width: width / 3 },
|
|
33
|
+
jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$badges.safeHarbour.code
|
|
34
|
+
? types_1.POVerification.FullyVerified
|
|
35
|
+
: types_1.POVerification.VerifiedFalse]}.svg`), width: width / 3 })),
|
|
36
|
+
jsx_pdf_1.default.createElement("column", { width: "auto" },
|
|
37
|
+
jsx_pdf_1.default.createElement("text", { alignment: "center" }, $badges.safeHarbour.code
|
|
38
|
+
? (0, locales_1.$$)("POVerificationBadge.safe-harbour-yes")
|
|
39
|
+
: (0, locales_1.$$)("POVerificationBadge.safe-harbour-no")))))));
|
|
40
|
+
};
|
|
41
|
+
exports.POVerificationBadge = POVerificationBadge;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="jsx-pdf" />
|
|
2
|
+
import type { AId } from "@raytio/types";
|
|
3
|
+
import { PdfConfig } from "../types";
|
|
4
|
+
import { EnvConfig } from "../../api";
|
|
5
|
+
import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
|
|
6
|
+
export declare const Report: ({ data, files, config, aId, clientUrl, envConfig, }: {
|
|
7
|
+
data: ProcessSubmissionOutput["json"];
|
|
8
|
+
files: ProcessSubmissionOutput["files"];
|
|
9
|
+
config: PdfConfig;
|
|
10
|
+
aId: AId;
|
|
11
|
+
clientUrl: string;
|
|
12
|
+
envConfig: EnvConfig;
|
|
13
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,98 @@
|
|
|
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 node_crypto_1 = require("node:crypto");
|
|
8
|
+
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
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, node_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;
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,47 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatDate = exports.verifyColour = exports.loadAsset = exports.asset = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const types_1 = require("@raytio/types");
|
|
7
|
+
const asset = (name) => {
|
|
8
|
+
if (/[^.A-Z_a-z-]/.test(name) || name.includes("..")) {
|
|
9
|
+
throw new Error("Invalid asset name");
|
|
10
|
+
}
|
|
11
|
+
return (0, node_path_1.join)(__dirname, "../../../assets/", name);
|
|
12
|
+
};
|
|
13
|
+
exports.asset = asset;
|
|
14
|
+
const loadAsset = (name) => (0, node_fs_1.readFileSync)((0, exports.asset)(name), { encoding: "utf8" });
|
|
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;
|
|
@@ -0,0 +1,4 @@
|
|
|
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;
|
|
@@ -0,0 +1,39 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
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>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 node_fs_1 = require("node:fs");
|
|
17
|
+
const node_path_1 = require("node:path");
|
|
18
|
+
const pdfmake_1 = __importDefault(require("pdfmake"));
|
|
19
|
+
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
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 = () =>
|
|
28
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping -- deliberately to future proof the SDK for options
|
|
29
|
+
(data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
console.log("Generating PDF Report...");
|
|
31
|
+
const { DATE_FORMAT = "en-nz", TIMEZONE = "Pacific/Auckland", PDF_LANGUAGE: customLang, } = process.env;
|
|
32
|
+
if (data.envConfig.logo_url) {
|
|
33
|
+
// there is a white labelling URL, so fetch it and write it to disk, overriding the default logo
|
|
34
|
+
const arrayBuf = yield fetch(data.envConfig.logo_url).then((r) => r.arrayBuffer());
|
|
35
|
+
yield node_fs_1.promises.writeFile((0, node_path_1.join)(__dirname, "../../assets/custom-logo.png"), Buffer.from(arrayBuf));
|
|
36
|
+
}
|
|
37
|
+
if (customLang) {
|
|
38
|
+
if ((0, locales_1.isValidLocale)(customLang)) {
|
|
39
|
+
global.lang = customLang;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.warn(`The specified PDF_LANGUAGE is language is invalid (${customLang})`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const printer = new pdfmake_1.default(style_1.fonts);
|
|
47
|
+
const pdfDocument = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE));
|
|
48
|
+
const chunks = [];
|
|
49
|
+
pdfDocument.on("data", (chunk) => chunks.push(chunk));
|
|
50
|
+
pdfDocument.on("end", () => {
|
|
51
|
+
const final = Buffer.concat(chunks);
|
|
52
|
+
const dataUrl = `data:application/pdf;base64,${final.toString("base64")}`;
|
|
53
|
+
resolve(Object.assign(Object.assign({}, data), { files: Object.assign(Object.assign({}, data.files), {
|
|
54
|
+
// do not change name, will be a breaking change
|
|
55
|
+
[data.json.i_id]: [dataUrl, "pdf"] }) }));
|
|
56
|
+
});
|
|
57
|
+
pdfDocument.end();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
exports.generatePDF = generatePDF;
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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((accumulator, name) => {
|
|
13
|
+
const value = process.env[name];
|
|
14
|
+
if (!value)
|
|
15
|
+
throw new Error(`${name} is not configured`);
|
|
16
|
+
return Object.assign(Object.assign({}, accumulator), { [name]: value });
|
|
17
|
+
}, {});
|
|
18
|
+
return CONFIG;
|
|
19
|
+
}
|
|
20
|
+
exports.getAndValidateConfig = getAndValidateConfig;
|