@raytio/decrypt-helper 3.0.0 → 3.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/CHANGELOG.md +18 -0
- package/README.md +1 -0
- package/dist/api/fetchEnvConfig.d.ts +1 -1
- package/dist/api/fetchEnvConfig.js +8 -2
- package/dist/api/index.js +5 -1
- package/dist/constants.d.ts +4 -1
- package/dist/constants.js +17 -13
- package/dist/helpers/formatOutput.d.ts +1 -1
- package/dist/helpers/formatOutput.js +15 -14
- package/dist/helpers/index.js +5 -1
- package/dist/helpers/splitPOAndVers.js +1 -1
- package/dist/locales/index.d.ts +44 -0
- package/dist/locales/index.js +21 -0
- package/dist/locales/translations/en.json +33 -0
- package/dist/pdf/components/Images.js +2 -1
- package/dist/pdf/components/POVerificationBadge.js +5 -6
- package/dist/pdf/components/Report.d.ts +3 -1
- package/dist/pdf/components/Report.js +31 -14
- package/dist/pdf/components/Subheader.js +4 -3
- package/dist/pdf/components/Table.js +6 -1
- package/dist/pdf/components/ValidationDisplay.js +2 -3
- package/dist/pdf/components/VerifyBox.js +2 -1
- package/dist/pdf/constants.js +6 -5
- package/dist/pdf/helpers/transform.js +3 -2
- package/dist/public-methods/generatePDF.js +17 -1
- package/dist/public-methods/processSubmission.d.ts +4 -7
- package/dist/public-methods/processSubmission.js +1 -5
- package/package.json +29 -13
- package/dist/api/__tests__/fetchEnvConfig.test.d.ts +0 -1
- package/dist/api/__tests__/fetchEnvConfig.test.js +0 -29
- package/dist/api/__tests__/getFiles.test.d.ts +0 -1
- package/dist/api/__tests__/getFiles.test.js +0 -45
- package/dist/helpers/__tests__/formatOutput.test.d.ts +0 -1
- package/dist/helpers/__tests__/formatOutput.test.js +0 -129
- package/dist/helpers/__tests__/lookup.test.d.ts +0 -1
- package/dist/helpers/__tests__/lookup.test.js +0 -79
- package/dist/test/pdf.d.ts +0 -4
- package/dist/test/pdf.js +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## 3.1.0 (2022-03-14)
|
|
11
|
+
|
|
12
|
+
- !168 Support internationalizing the pdf
|
|
13
|
+
- !167 Support while labelling the pdf
|
|
14
|
+
- !166 List the person schema first in the PDF
|
|
15
|
+
- !163, !165, !169, !171, !172 automated dependency updates
|
|
16
|
+
|
|
17
|
+
## 3.0.2 (2022-02-16)
|
|
18
|
+
|
|
19
|
+
- !164 fix PDF bug for multiple POs from the same schema
|
|
20
|
+
- !164 remove legacy internal property called `$source`
|
|
21
|
+
- !164 fix field verification status being `undefined` instead of `NotVerified`/`60002`
|
|
22
|
+
- 💥 BREAKING CHANGE: we no longer use `schema_group` to group schema in the json, csv, and pdf
|
|
23
|
+
|
|
24
|
+
## 3.0.1 (2022-02-15)
|
|
25
|
+
|
|
26
|
+
- !162 fix bug with PDF generation
|
|
27
|
+
|
|
10
28
|
## 3.0.0 (2022-02-04)
|
|
11
29
|
|
|
12
30
|
- 💥 BREAKING CHANGE: renamed the `USERNAME` & `PASSWORD` environment variables to `RAYTIO_USERNAME` & `RAYTIO_PASSWORD`
|
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ raytio
|
|
|
42
42
|
// for available timezone options, see the map on https://momentjs.com/timezone
|
|
43
43
|
DATE_FORMAT: "en-nz",
|
|
44
44
|
TIMEZONE: "Pacific/Auckland",
|
|
45
|
+
PDF_LANGUAGE: "en", // the value must be one of the languages listed here: https://gitlab.com/raytio/tools/decrypt-helper/-/tree/main/src/locales/translations
|
|
45
46
|
},
|
|
46
47
|
verbose: true,
|
|
47
48
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const PARAMS: readonly ["cognito_region", "cognito_user_pool_id", "cognito_web_client_id", "api_url"];
|
|
1
|
+
declare const PARAMS: readonly ["cognito_region", "cognito_user_pool_id", "cognito_web_client_id", "api_url", "app_name", "logo_url"];
|
|
2
2
|
export declare type EnvConfig = Record<typeof PARAMS[number], string>;
|
|
3
3
|
export declare function fetchEnvConfig(clientUrl: string): Promise<EnvConfig>;
|
|
4
4
|
export {};
|
|
@@ -15,12 +15,18 @@ const PARAMS = [
|
|
|
15
15
|
"cognito_user_pool_id",
|
|
16
16
|
"cognito_web_client_id",
|
|
17
17
|
"api_url",
|
|
18
|
+
"app_name",
|
|
19
|
+
"logo_url", // must be a URL to a png file
|
|
18
20
|
];
|
|
21
|
+
const DEFAULTS = {
|
|
22
|
+
app_name: "Raytio",
|
|
23
|
+
logo_url: undefined,
|
|
24
|
+
};
|
|
19
25
|
function fetchEnvConfig(clientUrl) {
|
|
20
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
27
|
try {
|
|
22
|
-
const envConfig = yield fetch(`${clientUrl}/client_config.json`).then((r) => r.json());
|
|
23
|
-
const missing = PARAMS.filter((p) => !envConfig
|
|
28
|
+
const envConfig = Object.assign(Object.assign({}, DEFAULTS), (yield fetch(`${clientUrl}/client_config.json`).then((r) => r.json())));
|
|
29
|
+
const missing = PARAMS.filter((p) => !(p in envConfig));
|
|
24
30
|
if (missing.length)
|
|
25
31
|
throw new Error(`Missing: ${missing.join(", ")}`);
|
|
26
32
|
return envConfig;
|
package/dist/api/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/constants.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export declare const ATTRIBUTE_MAP: {
|
|
|
8
8
|
"custom:ask_public": string[];
|
|
9
9
|
"custom:ask_private": string[];
|
|
10
10
|
};
|
|
11
|
-
export declare const VERIFICATION_SCHEMA = "ss_Verification";
|
|
12
11
|
export declare const INSTANCE_FIELDS_TO_REMOVE: readonly ["profile_objects", "relationships", "keys"];
|
|
13
12
|
export declare const FIELDS_TO_REMOVE: readonly ["n_id", "document"];
|
|
14
13
|
export declare const ENV_VARIABLES: readonly ["CLIENT_URL", "RAYTIO_USERNAME", "RAYTIO_PASSWORD"];
|
|
@@ -18,3 +17,7 @@ export declare type InstanceDataToPassOn = Omit<Instance, typeof INSTANCE_FIELDS
|
|
|
18
17
|
};
|
|
19
18
|
export declare const PO_VER_TEXT_MAP: Record<POVerification, string>;
|
|
20
19
|
export declare const FIELD_VER_TEXT_MAP: Record<FieldVerification, string>;
|
|
20
|
+
export declare const SCHEMA: {
|
|
21
|
+
readonly VERIFICATION: "ss_Verification";
|
|
22
|
+
readonly PERSON: "ss_Person_Name";
|
|
23
|
+
};
|
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIELD_VER_TEXT_MAP = exports.PO_VER_TEXT_MAP = exports.ENV_VARIABLES = exports.FIELDS_TO_REMOVE = exports.INSTANCE_FIELDS_TO_REMOVE = exports.
|
|
3
|
+
exports.SCHEMA = exports.FIELD_VER_TEXT_MAP = exports.PO_VER_TEXT_MAP = exports.ENV_VARIABLES = exports.FIELDS_TO_REMOVE = exports.INSTANCE_FIELDS_TO_REMOVE = exports.ATTRIBUTE_MAP = void 0;
|
|
4
4
|
const types_1 = require("@raytio/types");
|
|
5
|
+
const locales_1 = require("locales");
|
|
5
6
|
exports.ATTRIBUTE_MAP = {
|
|
6
7
|
"custom:kek_derivation": ["kek_derivation_config"],
|
|
7
8
|
"custom:dek_encryption": ["private_key_encryption_config"],
|
|
@@ -10,7 +11,6 @@ exports.ATTRIBUTE_MAP = {
|
|
|
10
11
|
"custom:ask_public": ["signing_key_pair", "public_key"],
|
|
11
12
|
"custom:ask_private": ["signing_key_pair", "private_key"],
|
|
12
13
|
};
|
|
13
|
-
exports.VERIFICATION_SCHEMA = "ss_Verification";
|
|
14
14
|
exports.INSTANCE_FIELDS_TO_REMOVE = [
|
|
15
15
|
"profile_objects",
|
|
16
16
|
"relationships",
|
|
@@ -23,18 +23,22 @@ exports.ENV_VARIABLES = [
|
|
|
23
23
|
"RAYTIO_PASSWORD",
|
|
24
24
|
];
|
|
25
25
|
exports.PO_VER_TEXT_MAP = {
|
|
26
|
-
[types_1.POVerification.FullyVerified]:
|
|
27
|
-
[types_1.POVerification.PartiallyVerified]:
|
|
28
|
-
[types_1.POVerification.NotVerified]:
|
|
29
|
-
[types_1.POVerification.Expired]: "Expired",
|
|
30
|
-
[types_1.POVerification.VerifiedFalse]:
|
|
26
|
+
[types_1.POVerification.FullyVerified]: (0, locales_1.$$)("POVerification.FullyVerified"),
|
|
27
|
+
[types_1.POVerification.PartiallyVerified]: (0, locales_1.$$)("POVerification.PartiallyVerified"),
|
|
28
|
+
[types_1.POVerification.NotVerified]: (0, locales_1.$$)("POVerification.NotVerified"),
|
|
29
|
+
[types_1.POVerification.Expired]: (0, locales_1.$$)("POVerification.Expired"),
|
|
30
|
+
[types_1.POVerification.VerifiedFalse]: (0, locales_1.$$)("POVerification.VerifiedFalse"),
|
|
31
31
|
// not possible but included here for completeness
|
|
32
|
-
[types_1.POVerification.Encrypted]: "Encrypted",
|
|
33
|
-
[types_1.POVerification.Loading]: "Loading
|
|
32
|
+
[types_1.POVerification.Encrypted]: (0, locales_1.$$)("POVerification.Encrypted"),
|
|
33
|
+
[types_1.POVerification.Loading]: (0, locales_1.$$)("POVerification.Loading"),
|
|
34
34
|
};
|
|
35
35
|
exports.FIELD_VER_TEXT_MAP = {
|
|
36
|
-
[types_1.FieldVerification.Verified]: "Verified",
|
|
37
|
-
[types_1.FieldVerification.NotVerified]:
|
|
38
|
-
[types_1.FieldVerification.Expired]: "Expired",
|
|
39
|
-
[types_1.FieldVerification.VerifiedFalse]:
|
|
36
|
+
[types_1.FieldVerification.Verified]: (0, locales_1.$$)("FieldVerification.Verified"),
|
|
37
|
+
[types_1.FieldVerification.NotVerified]: (0, locales_1.$$)("FieldVerification.NotVerified"),
|
|
38
|
+
[types_1.FieldVerification.Expired]: (0, locales_1.$$)("FieldVerification.Expired"),
|
|
39
|
+
[types_1.FieldVerification.VerifiedFalse]: (0, locales_1.$$)("FieldVerification.VerifiedFalse"),
|
|
40
|
+
};
|
|
41
|
+
exports.SCHEMA = {
|
|
42
|
+
VERIFICATION: "ss_Verification",
|
|
43
|
+
PERSON: "ss_Person_Name",
|
|
40
44
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FieldVerification, NId, POVerification, ProfileObject, RealVer, Schema } from "@raytio/types";
|
|
2
2
|
import { ResolvedVerificationProvider, EnvConfig } from "../api";
|
|
3
3
|
export declare type FlatPO = {
|
|
4
4
|
$verified: POVerification;
|
|
@@ -12,14 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.formatOutput = void 0;
|
|
13
13
|
const core_1 = require("@raytio/core");
|
|
14
14
|
const ramda_1 = require("ramda");
|
|
15
|
+
const types_1 = require("@raytio/types");
|
|
15
16
|
const api_1 = require("../api");
|
|
16
17
|
const constants_1 = require("../constants");
|
|
17
18
|
const lookup_1 = require("./lookup");
|
|
18
|
-
const
|
|
19
|
+
const types_2 = require("./types");
|
|
19
20
|
const byPriority = (schema) => ([a], [b]) => {
|
|
20
21
|
var _a, _b, _c, _d, _e, _f;
|
|
21
|
-
(0,
|
|
22
|
-
(0,
|
|
22
|
+
(0, types_2.assertSafeProperty)(a);
|
|
23
|
+
(0, types_2.assertSafeProperty)(b);
|
|
23
24
|
// if no priority, it becomes the last
|
|
24
25
|
const aPriority = (_c = (_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[a]) === null || _b === void 0 ? void 0 : _b.priority) !== null && _c !== void 0 ? _c : Infinity;
|
|
25
26
|
const bPriority = (_f = (_e = (_d = schema.properties) === null || _d === void 0 ? void 0 : _d[b]) === null || _e === void 0 ? void 0 : _e.priority) !== null && _f !== void 0 ? _f : Infinity;
|
|
@@ -28,7 +29,7 @@ const byPriority = (schema) => ([a], [b]) => {
|
|
|
28
29
|
function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig) {
|
|
29
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
31
|
const PODetails = profileObjects.reduce((acPromise, PO) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
var _a
|
|
32
|
+
var _a;
|
|
32
33
|
const ac = yield acPromise;
|
|
33
34
|
const schemaName = (0, core_1.findSchemaLabel)(PO.labels);
|
|
34
35
|
const schema = allSchemas.find((x) => x.name === schemaName);
|
|
@@ -36,31 +37,31 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig)
|
|
|
36
37
|
throw new Error(`${schema} is missing!`);
|
|
37
38
|
const verDetails = (0, core_1.getPOVerification)({ PO, schema, realVers });
|
|
38
39
|
const realProps = (0, ramda_1.omit)(constants_1.FIELDS_TO_REMOVE, PO.properties);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const existing = ac[schemaNameOrGroup] || [];
|
|
40
|
+
(0, types_2.assertSafeProperty)(schemaName);
|
|
41
|
+
const existing = ac[schemaName] || [];
|
|
42
42
|
const poProperties = Object.entries(realProps).sort(byPriority(schema));
|
|
43
43
|
const reducedProperties = yield poProperties.reduce((acc, [key, value]) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
var
|
|
44
|
+
var _b, _c;
|
|
45
45
|
const accP = yield acc;
|
|
46
|
-
(0,
|
|
46
|
+
(0, types_2.assertSafeProperty)(key);
|
|
47
47
|
return Object.assign(Object.assign({}, accP), { [key]: {
|
|
48
|
-
title: ((
|
|
48
|
+
title: ((_c = (_b = schema.properties) === null || _b === void 0 ? void 0 : _b[key]) === null || _c === void 0 ? void 0 : _c.title) || key,
|
|
49
49
|
value: typeof value === "string"
|
|
50
50
|
? yield (0, lookup_1.maybeAddLookupValue)(schema, key, value, apiToken)
|
|
51
51
|
: value,
|
|
52
|
-
verification: verDetails.fieldVerifications[key]
|
|
52
|
+
verification: verDetails.fieldVerifications[key] ||
|
|
53
|
+
types_1.FieldVerification.NotVerified,
|
|
53
54
|
} });
|
|
54
55
|
}), Promise.resolve({}));
|
|
55
56
|
const thisPO = {
|
|
56
57
|
$verified: verDetails.status,
|
|
57
58
|
$verification_details: yield (0, api_1.resolveVerificationDetails)(verDetails.details.verifiers, apiToken, envConfig),
|
|
58
|
-
$shouldBeVerifiedFields: (
|
|
59
|
+
$shouldBeVerifiedFields: (_a = schema.verified_fields) === null || _a === void 0 ? void 0 : _a.map((x) => typeof x === "string" ? x : x.field),
|
|
59
60
|
$nId: PO.n_id,
|
|
60
61
|
$schemaName: schemaName,
|
|
61
62
|
$schemaTitle: schema.title,
|
|
62
63
|
$properties: reducedProperties,
|
|
63
|
-
$safeHarbour: schemaName ===
|
|
64
|
+
$safeHarbour: schemaName === constants_1.SCHEMA.PERSON
|
|
64
65
|
? (yield (0, core_1.calcSafeHarbourScore)({
|
|
65
66
|
person: PO,
|
|
66
67
|
getSchema: (name) => (0, api_1.getSchema)(envConfig, name),
|
|
@@ -69,7 +70,7 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig)
|
|
|
69
70
|
})).isSafe
|
|
70
71
|
: "NOT_APPLICABLE",
|
|
71
72
|
};
|
|
72
|
-
return Object.assign(Object.assign({}, ac), { [
|
|
73
|
+
return Object.assign(Object.assign({}, ac), { [schemaName]: [...existing, thisPO] });
|
|
73
74
|
}), Promise.resolve({}));
|
|
74
75
|
return PODetails;
|
|
75
76
|
});
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -4,7 +4,7 @@ exports.splitPOAndVers = void 0;
|
|
|
4
4
|
const core_1 = require("@raytio/core");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const splitPOAndVers = (list) => list.reduce((ac, PO) => {
|
|
7
|
-
const isVer = (0, core_1.findSchemaLabel)(PO.labels) === constants_1.
|
|
7
|
+
const isVer = (0, core_1.findSchemaLabel)(PO.labels) === constants_1.SCHEMA.VERIFICATION;
|
|
8
8
|
ac[+isVer].push(PO);
|
|
9
9
|
return ac;
|
|
10
10
|
}, [[], []]);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import en from "./translations/en.json";
|
|
2
|
+
declare const locales: {
|
|
3
|
+
readonly en: {
|
|
4
|
+
"FieldVerification.Expired": string;
|
|
5
|
+
"FieldVerification.NotVerified": string;
|
|
6
|
+
"FieldVerification.Verified": string;
|
|
7
|
+
"FieldVerification.VerifiedFalse": string;
|
|
8
|
+
"Images.file-not-found": string;
|
|
9
|
+
"POVerification.Encrypted": string;
|
|
10
|
+
"POVerification.Expired": string;
|
|
11
|
+
"POVerification.FullyVerified": string;
|
|
12
|
+
"POVerification.Loading": string;
|
|
13
|
+
"POVerification.NotVerified": string;
|
|
14
|
+
"POVerification.PartiallyVerified": string;
|
|
15
|
+
"POVerification.VerifiedFalse": string;
|
|
16
|
+
"POVerificationBadge.safe-harbour-no": string;
|
|
17
|
+
"POVerificationBadge.safe-harbour-yes": string;
|
|
18
|
+
"POVerificationBadge.verified-by": string;
|
|
19
|
+
"Report.footer-private": string;
|
|
20
|
+
"Report.header": string;
|
|
21
|
+
"Report.meta.title": string;
|
|
22
|
+
"Report.pagecount": string;
|
|
23
|
+
"ValidationDisplay.text": string;
|
|
24
|
+
"VerifyBox.text": string;
|
|
25
|
+
"constants.confirmation_code": string;
|
|
26
|
+
"constants.end_date": string;
|
|
27
|
+
"constants.i_id": string;
|
|
28
|
+
"constants.reference": string;
|
|
29
|
+
"constants.score": string;
|
|
30
|
+
"constants.score-category": string;
|
|
31
|
+
"constants.start_date": string;
|
|
32
|
+
"field.boolean.no": string;
|
|
33
|
+
"field.boolean.yes": string;
|
|
34
|
+
"field.undefined": string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare type I18nKey = keyof typeof en;
|
|
38
|
+
export declare type I18nLang = keyof typeof locales;
|
|
39
|
+
declare global {
|
|
40
|
+
var lang: I18nLang;
|
|
41
|
+
}
|
|
42
|
+
export declare const isValidLocale: (lang: string) => lang is "en";
|
|
43
|
+
export declare const $$: (key: I18nKey, variables?: Record<string, string | number> | undefined) => string;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
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.$$ = exports.isValidLocale = void 0;
|
|
7
|
+
const en_json_1 = __importDefault(require("./translations/en.json"));
|
|
8
|
+
const locales = { en: en_json_1.default };
|
|
9
|
+
const isValidLocale = (lang) => lang in locales;
|
|
10
|
+
exports.isValidLocale = isValidLocale;
|
|
11
|
+
const $$ = (key, variables) => {
|
|
12
|
+
const strings = locales[global.lang || "en"];
|
|
13
|
+
const replaceWithVariable = (_, varName) => {
|
|
14
|
+
const value = variables === null || variables === void 0 ? void 0 : variables[varName];
|
|
15
|
+
if (!value)
|
|
16
|
+
throw new Error(`[i18n] variable '${varName}' not defined`);
|
|
17
|
+
return `${value}`;
|
|
18
|
+
};
|
|
19
|
+
return strings[key].replace(/{([^}]+)}/g, replaceWithVariable);
|
|
20
|
+
};
|
|
21
|
+
exports.$$ = $$;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"FieldVerification.Expired": "Expired",
|
|
3
|
+
"FieldVerification.NotVerified": "Not Verified",
|
|
4
|
+
"FieldVerification.Verified": "Verified",
|
|
5
|
+
"FieldVerification.VerifiedFalse": "Verified False",
|
|
6
|
+
"Images.file-not-found": "File not found",
|
|
7
|
+
"POVerification.Encrypted": "Encrypted",
|
|
8
|
+
"POVerification.Expired": "Expired",
|
|
9
|
+
"POVerification.FullyVerified": "Fully Verified",
|
|
10
|
+
"POVerification.Loading": "Loading...",
|
|
11
|
+
"POVerification.NotVerified": "Not Verified",
|
|
12
|
+
"POVerification.PartiallyVerified": "Partially Verified",
|
|
13
|
+
"POVerification.VerifiedFalse": "Verified False",
|
|
14
|
+
"POVerificationBadge.safe-harbour-no": "Not Safe Harbour Compliant",
|
|
15
|
+
"POVerificationBadge.safe-harbour-yes": "Safe Harbour Compliant",
|
|
16
|
+
"POVerificationBadge.verified-by": "by {verifiedBy}",
|
|
17
|
+
"Report.footer-private": "Private and Confidential",
|
|
18
|
+
"Report.header": "{appName} Verification Report",
|
|
19
|
+
"Report.meta.title": "{appName} Verification Report - {iId}",
|
|
20
|
+
"Report.pagecount": "{currentPage} of {pageCount}",
|
|
21
|
+
"ValidationDisplay.text": "Score: {n}/10",
|
|
22
|
+
"VerifyBox.text": "To verify this submission, scan the QR Code or click here",
|
|
23
|
+
"constants.confirmation_code": "Code",
|
|
24
|
+
"constants.end_date": "Expiry Date",
|
|
25
|
+
"constants.i_id": "Submission ID",
|
|
26
|
+
"constants.reference": "Reference",
|
|
27
|
+
"constants.score": "Score",
|
|
28
|
+
"constants.score-category": "Score Category",
|
|
29
|
+
"constants.start_date": "Date Shared",
|
|
30
|
+
"field.boolean.no": "No",
|
|
31
|
+
"field.boolean.yes": "Yes",
|
|
32
|
+
"field.undefined": "N/A"
|
|
33
|
+
}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Images = void 0;
|
|
7
7
|
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
+
const locales_1 = require("locales");
|
|
8
9
|
const helpers_1 = require("../../helpers");
|
|
9
10
|
const Images = ({ nIds, files, }) => {
|
|
10
11
|
return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null, nIds.map((nId) => {
|
|
@@ -12,7 +13,7 @@ const Images = ({ nIds, files, }) => {
|
|
|
12
13
|
const file = (_a = files[nId]) === null || _a === void 0 ? void 0 : _a[0];
|
|
13
14
|
if (file)
|
|
14
15
|
(0, helpers_1.assertSafeProperty)(file);
|
|
15
|
-
return file ? (jsx_pdf_1.default.createElement("image", { src: file, width: 300 })) : (jsx_pdf_1.default.createElement("text", null, "
|
|
16
|
+
return file ? (jsx_pdf_1.default.createElement("image", { src: file, width: 300 })) : (jsx_pdf_1.default.createElement("text", null, (0, locales_1.$$)("Images.file-not-found")));
|
|
16
17
|
})));
|
|
17
18
|
};
|
|
18
19
|
exports.Images = Images;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.POVerificationBadge = exports.FILE_MAP = void 0;
|
|
7
7
|
const types_1 = require("@raytio/types");
|
|
8
8
|
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
9
|
+
const locales_1 = require("locales");
|
|
9
10
|
const general_1 = require("../helpers/general");
|
|
10
11
|
const constants_1 = require("../../constants");
|
|
11
12
|
exports.FILE_MAP = {
|
|
@@ -26,17 +27,15 @@ const POVerificationBadge = ({ width, POs, }) => {
|
|
|
26
27
|
$shouldBeVerifiedFields && (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
|
|
27
28
|
jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$verified]}.svg`), width: width }),
|
|
28
29
|
jsx_pdf_1.default.createElement("text", { alignment: "center" }, constants_1.PO_VER_TEXT_MAP[$verified]),
|
|
29
|
-
verifiedBy && jsx_pdf_1.default.createElement("text", { alignment: "center" },
|
|
30
|
-
"by ",
|
|
31
|
-
verifiedBy))),
|
|
30
|
+
verifiedBy && (jsx_pdf_1.default.createElement("text", { alignment: "center" }, (0, locales_1.$$)("POVerificationBadge.verified-by", { verifiedBy }))))),
|
|
32
31
|
typeof $safeHarbour === "boolean" && (jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
|
|
33
32
|
jsx_pdf_1.default.createElement("column", { width: width / 3 },
|
|
34
33
|
jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$safeHarbour
|
|
35
34
|
? types_1.POVerification.FullyVerified
|
|
36
35
|
: types_1.POVerification.VerifiedFalse]}.svg`), width: width / 3 })),
|
|
37
36
|
jsx_pdf_1.default.createElement("column", { width: "auto" },
|
|
38
|
-
jsx_pdf_1.default.createElement("text", { alignment: "center" },
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
jsx_pdf_1.default.createElement("text", { alignment: "center" }, $safeHarbour
|
|
38
|
+
? (0, locales_1.$$)("POVerificationBadge.safe-harbour-yes")
|
|
39
|
+
: (0, locales_1.$$)("POVerificationBadge.safe-harbour-no")))))));
|
|
41
40
|
};
|
|
42
41
|
exports.POVerificationBadge = POVerificationBadge;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/// <reference types="jsx-pdf" />
|
|
2
2
|
import type { AId } from "@raytio/types";
|
|
3
3
|
import { PdfConfig } from "../types";
|
|
4
|
+
import { EnvConfig } from "../../api";
|
|
4
5
|
import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
|
|
5
|
-
export declare const Report: ({ data, files, config, aId, clientUrl, version, }: {
|
|
6
|
+
export declare const Report: ({ data, files, config, aId, clientUrl, envConfig, version, }: {
|
|
6
7
|
data: ProcessSubmissionOutput["json"];
|
|
7
8
|
files: ProcessSubmissionOutput["files"];
|
|
8
9
|
config: PdfConfig;
|
|
9
10
|
aId: AId;
|
|
10
11
|
clientUrl: string;
|
|
12
|
+
envConfig: EnvConfig;
|
|
11
13
|
version: string;
|
|
12
14
|
}) => JSX.Element;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Report = void 0;
|
|
7
7
|
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
|
+
const locales_1 = require("locales");
|
|
9
10
|
const POVerificationBadge_1 = require("./POVerificationBadge");
|
|
10
11
|
const Subheader_1 = require("./Subheader");
|
|
11
12
|
const TableTitle_1 = require("./TableTitle");
|
|
@@ -15,27 +16,40 @@ const general_1 = require("../helpers/general");
|
|
|
15
16
|
const VerifyBox_1 = require("./VerifyBox");
|
|
16
17
|
const constants_1 = require("../constants");
|
|
17
18
|
const transform_1 = require("../helpers/transform");
|
|
18
|
-
const
|
|
19
|
+
const constants_2 = require("../../constants");
|
|
20
|
+
const Report = ({ data, files, config, aId, clientUrl, envConfig, version, }) => {
|
|
19
21
|
// The PDF is read only; there's no reason why anyone would ever need to unlock it.
|
|
20
22
|
const randomToken = (0, crypto_1.randomBytes)(32).toString("base64");
|
|
23
|
+
const schemas = Object.values(data.profile_objects).sort(
|
|
24
|
+
// sort it so that the person schema comes first
|
|
25
|
+
(a, b) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
return +(((_a = b[0]) === null || _a === void 0 ? void 0 : _a.$schemaName) === constants_2.SCHEMA.PERSON) -
|
|
28
|
+
+(((_b = a[0]) === null || _b === void 0 ? void 0 : _b.$schemaName) === constants_2.SCHEMA.PERSON);
|
|
29
|
+
});
|
|
30
|
+
const appName = envConfig.app_name;
|
|
21
31
|
return (jsx_pdf_1.default.createElement("document", { defaultStyle: { font: "Lato", fontSize: 12 }, info: {
|
|
22
|
-
title:
|
|
23
|
-
creator:
|
|
32
|
+
title: (0, locales_1.$$)("Report.meta.title", { appName, iId: data.i_id }),
|
|
33
|
+
creator: appName,
|
|
24
34
|
producer: "Raytio",
|
|
25
35
|
subject: version,
|
|
26
36
|
}, ownerPassword: randomToken, permissions: {
|
|
27
37
|
printing: "highResolution",
|
|
28
38
|
copying: true, // allow copy/paste
|
|
29
39
|
}, pageSize: "A4", styles: style_1.classes, images: {
|
|
30
|
-
raytioLogo:
|
|
40
|
+
raytioLogo: envConfig.logo_url
|
|
41
|
+
? (0, general_1.asset)("custom-logo.png")
|
|
42
|
+
: (0, general_1.asset)("logo.png"),
|
|
31
43
|
} },
|
|
32
44
|
jsx_pdf_1.default.createElement("header", null, (currentPage) => currentPage !== 1 && (jsx_pdf_1.default.createElement("stack", { color: "#333", fontSize: 10 },
|
|
33
45
|
jsx_pdf_1.default.createElement("text", { margin: 16 },
|
|
34
|
-
jsx_pdf_1.default.createElement("text", { bold: true },
|
|
46
|
+
jsx_pdf_1.default.createElement("text", { bold: true },
|
|
47
|
+
(0, locales_1.$$)("Report.header", { appName }),
|
|
48
|
+
" - "),
|
|
35
49
|
jsx_pdf_1.default.createElement("text", null, data.i_id))))),
|
|
36
50
|
jsx_pdf_1.default.createElement("content", null,
|
|
37
51
|
jsx_pdf_1.default.createElement("image", { src: "raytioLogo", width: 150, alignment: "center" }),
|
|
38
|
-
jsx_pdf_1.default.createElement("text", { style: ["header", "marginBottom"], alignment: "center" }, "
|
|
52
|
+
jsx_pdf_1.default.createElement("text", { style: ["header", "marginBottom"], alignment: "center" }, (0, locales_1.$$)("Report.header", { appName })),
|
|
39
53
|
jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
|
|
40
54
|
jsx_pdf_1.default.createElement("column", { width: "auto" },
|
|
41
55
|
jsx_pdf_1.default.createElement("text", { style: ["subheader", "marginBottom"] },
|
|
@@ -43,14 +57,18 @@ const Report = ({ data, files, config, aId, clientUrl, version, }) => {
|
|
|
43
57
|
.map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
|
|
44
58
|
.join("\n"),
|
|
45
59
|
data.score
|
|
46
|
-
?
|
|
60
|
+
? [
|
|
61
|
+
"",
|
|
62
|
+
`${(0, locales_1.$$)("constants.score")}: ${data.score.score}`,
|
|
63
|
+
`${(0, locales_1.$$)("constants.score-category")}: ${data.score.category}`,
|
|
64
|
+
].join("\n")
|
|
47
65
|
: ""),
|
|
48
66
|
jsx_pdf_1.default.createElement(Subheader_1.Subheader, { data: data, config: config })),
|
|
49
67
|
jsx_pdf_1.default.createElement("column", { width: "*" },
|
|
50
68
|
jsx_pdf_1.default.createElement("text", null, " ")),
|
|
51
69
|
jsx_pdf_1.default.createElement("column", { width: 150 },
|
|
52
70
|
jsx_pdf_1.default.createElement(VerifyBox_1.VerifyBox, { aId: aId, iId: data.i_id, clientUrl: clientUrl }))),
|
|
53
|
-
|
|
71
|
+
schemas.map((POs) => {
|
|
54
72
|
// for each schema
|
|
55
73
|
return (jsx_pdf_1.default.createElement("stack", {
|
|
56
74
|
// unbreakable is off because it crashes if its too big for one page
|
|
@@ -65,11 +83,10 @@ const Report = ({ data, files, config, aId, clientUrl, version, }) => {
|
|
|
65
83
|
})),
|
|
66
84
|
jsx_pdf_1.default.createElement("footer", null, (currentPage, pageCount, pageSize) => (jsx_pdf_1.default.createElement("stack", { bold: true, color: "#333", fontSize: 10 },
|
|
67
85
|
jsx_pdf_1.default.createElement("text", { margin: 16 },
|
|
68
|
-
jsx_pdf_1.default.createElement("text", null,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
pageCount))))));
|
|
86
|
+
jsx_pdf_1.default.createElement("text", null,
|
|
87
|
+
(0, locales_1.$$)("Report.header", { appName }),
|
|
88
|
+
" - "),
|
|
89
|
+
jsx_pdf_1.default.createElement("text", { color: "#fb7171" }, (0, locales_1.$$)("Report.footer-private"))),
|
|
90
|
+
jsx_pdf_1.default.createElement("text", { absolutePosition: { x: pageSize.width - 50, y: 15 } }, (0, locales_1.$$)("Report.pagecount", { currentPage, pageCount })))))));
|
|
74
91
|
};
|
|
75
92
|
exports.Report = Report;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Subheader = void 0;
|
|
7
7
|
const types_1 = require("@raytio/types");
|
|
8
8
|
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
9
|
+
const locales_1 = require("locales");
|
|
9
10
|
const FieldVerificationBadge_1 = require("./FieldVerificationBadge");
|
|
10
11
|
const Subheader = () => {
|
|
11
12
|
return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
|
|
@@ -14,14 +15,14 @@ const Subheader = () => {
|
|
|
14
15
|
jsx_pdf_1.default.createElement("row", null,
|
|
15
16
|
jsx_pdf_1.default.createElement("cell", null,
|
|
16
17
|
jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: types_1.FieldVerification.Verified })),
|
|
17
|
-
jsx_pdf_1.default.createElement("cell", null, "Verified")),
|
|
18
|
+
jsx_pdf_1.default.createElement("cell", null, (0, locales_1.$$)("FieldVerification.Verified"))),
|
|
18
19
|
jsx_pdf_1.default.createElement("row", null,
|
|
19
20
|
jsx_pdf_1.default.createElement("cell", null,
|
|
20
21
|
jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: types_1.FieldVerification.NotVerified })),
|
|
21
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
22
|
+
jsx_pdf_1.default.createElement("cell", null, (0, locales_1.$$)("FieldVerification.NotVerified"))),
|
|
22
23
|
jsx_pdf_1.default.createElement("row", null,
|
|
23
24
|
jsx_pdf_1.default.createElement("cell", null,
|
|
24
25
|
jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: types_1.FieldVerification.VerifiedFalse })),
|
|
25
|
-
jsx_pdf_1.default.createElement("cell", null,
|
|
26
|
+
jsx_pdf_1.default.createElement("cell", null, (0, locales_1.$$)("FieldVerification.VerifiedFalse"))))));
|
|
26
27
|
};
|
|
27
28
|
exports.Subheader = Subheader;
|
|
@@ -19,7 +19,7 @@ const Table = ({ POs, files, config, }) => {
|
|
|
19
19
|
const fileNIds = POs.filter(helpers_1.isPOFile).map((x) => x.$nId);
|
|
20
20
|
if (fileNIds.length)
|
|
21
21
|
return jsx_pdf_1.default.createElement(Images_1.Images, { nIds: fileNIds, files: files });
|
|
22
|
-
const imageFieldNames = fieldNames.filter((fieldName) => POs.map((PO) => PO.$properties[fieldName].value).some(helpers_1.isFieldValueFile));
|
|
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
23
|
return (jsx_pdf_1.default.createElement("table", { layout: "noBorders" }, fieldNames.map((fieldName) => {
|
|
24
24
|
var _a;
|
|
25
25
|
return (jsx_pdf_1.default.createElement("row", null,
|
|
@@ -27,6 +27,11 @@ const Table = ({ POs, files, config, }) => {
|
|
|
27
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
28
|
POs.flatMap((PO) => {
|
|
29
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
|
+
}
|
|
30
35
|
const { value, verification } = PO.$properties[fieldName];
|
|
31
36
|
const color = (0, general_1.verifyColour)(verification);
|
|
32
37
|
// jsx-pdf currently doesn't support fragments, will make a PR at some point
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ValidationDisplay = void 0;
|
|
7
7
|
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
+
const locales_1 = require("locales");
|
|
8
9
|
const pieChart_1 = require("./pieChart");
|
|
9
10
|
const helpers_1 = require("../../helpers");
|
|
10
11
|
const SEVERITY_COLOURS = {
|
|
@@ -16,9 +17,7 @@ const ValidationDisplay = ({ value, }) => {
|
|
|
16
17
|
const colour = value.score > 0.5 ? "#c2d887" : "#fb7171";
|
|
17
18
|
return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
|
|
18
19
|
jsx_pdf_1.default.createElement("svg", { content: (0, pieChart_1.pieChart)(colour, value.score * 100), width: 50 }),
|
|
19
|
-
"
|
|
20
|
-
value.score * 10,
|
|
21
|
-
"/10",
|
|
20
|
+
(0, locales_1.$$)("ValidationDisplay.text", { n: value.score * 10 }),
|
|
22
21
|
Object.values(value.breakdown)
|
|
23
22
|
.filter((x) => x.severity && x.reason)
|
|
24
23
|
.map((x) => {
|
|
@@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.VerifyBox = void 0;
|
|
7
7
|
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
8
|
+
const locales_1 = require("locales");
|
|
8
9
|
const VerifyBox = ({ aId, iId, clientUrl }) => {
|
|
9
10
|
const url = `${clientUrl}/apps/s/${aId}/i/${iId}`;
|
|
10
11
|
return (jsx_pdf_1.default.createElement("stack", { alignment: "center" },
|
|
11
|
-
jsx_pdf_1.default.createElement("text", { link: url },
|
|
12
|
+
jsx_pdf_1.default.createElement("text", { link: url }, (0, locales_1.$$)("VerifyBox.text")),
|
|
12
13
|
jsx_pdf_1.default.createElement("qr", { content: url, fit: 150 }),
|
|
13
14
|
jsx_pdf_1.default.createElement("text", { color: "#1e90ff", fontSize: 9, link: url, alignment: "left" }, url)));
|
|
14
15
|
};
|
package/dist/pdf/constants.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SUBMISSION_DATA = void 0;
|
|
4
|
+
const locales_1 = require("locales");
|
|
4
5
|
exports.SUBMISSION_DATA = {
|
|
5
|
-
confirmation_code: "
|
|
6
|
-
i_id:
|
|
7
|
-
reference: "
|
|
8
|
-
start_date:
|
|
9
|
-
end_date:
|
|
6
|
+
confirmation_code: (0, locales_1.$$)("constants.confirmation_code"),
|
|
7
|
+
i_id: (0, locales_1.$$)("constants.i_id"),
|
|
8
|
+
reference: (0, locales_1.$$)("constants.reference"),
|
|
9
|
+
start_date: (0, locales_1.$$)("constants.start_date"),
|
|
10
|
+
end_date: (0, locales_1.$$)("constants.end_date"),
|
|
10
11
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transform = exports.IS_ARRAY_OF_OBJECTS = exports.IS_IMAGE = void 0;
|
|
4
|
+
const locales_1 = require("locales");
|
|
4
5
|
const general_1 = require("./general");
|
|
5
6
|
exports.IS_IMAGE = Symbol.for("image");
|
|
6
7
|
exports.IS_ARRAY_OF_OBJECTS = Symbol.for("ArrayOfObjects");
|
|
7
8
|
function transform(key, value, pdfConfig, imageFieldNames) {
|
|
8
9
|
// value is possible to be false if type boolean
|
|
9
10
|
if (value === undefined) {
|
|
10
|
-
return "
|
|
11
|
+
return (0, locales_1.$$)("field.undefined");
|
|
11
12
|
}
|
|
12
13
|
if (typeof value === "boolean") {
|
|
13
|
-
return value ? "
|
|
14
|
+
return value ? (0, locales_1.$$)("field.boolean.yes") : (0, locales_1.$$)("field.boolean.no");
|
|
14
15
|
}
|
|
15
16
|
if (imageFieldNames === null || imageFieldNames === void 0 ? void 0 : imageFieldNames.includes(key)) {
|
|
16
17
|
return exports.IS_IMAGE;
|
|
@@ -15,12 +15,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.generatePDF = exports.generatePdfJson = void 0;
|
|
16
16
|
const pdfmake_1 = __importDefault(require("pdfmake"));
|
|
17
17
|
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
18
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
18
19
|
const fs_1 = require("fs");
|
|
19
20
|
const path_1 = require("path");
|
|
21
|
+
const locales_1 = require("locales");
|
|
20
22
|
const Report_1 = require("../pdf/components/Report");
|
|
21
23
|
const style_1 = require("../pdf/style");
|
|
22
24
|
function generatePdfJson(data, DATE_FORMAT, TIMEZONE, version) {
|
|
23
|
-
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, config: { DATE_FORMAT, TIMEZONE }, version: version }));
|
|
25
|
+
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 }, version: version }));
|
|
24
26
|
}
|
|
25
27
|
exports.generatePdfJson = generatePdfJson;
|
|
26
28
|
const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -28,6 +30,20 @@ const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function*
|
|
|
28
30
|
const { DATE_FORMAT = "en-nz", TIMEZONE = "Pacific/Auckland" } = process.env;
|
|
29
31
|
const pkg = JSON.parse(yield fs_1.promises.readFile((0, path_1.join)(__dirname, "../../package.json"), "utf8"));
|
|
30
32
|
const version = `node:${process.version} pkg:${pkg.version}`;
|
|
33
|
+
if (data.envConfig.logo_url) {
|
|
34
|
+
// there is a white labelling URL, so fetch it and write it to disk, overriding the default logo
|
|
35
|
+
const arrayBuf = yield (0, node_fetch_1.default)(data.envConfig.logo_url).then((r) => r.arrayBuffer());
|
|
36
|
+
yield fs_1.promises.writeFile((0, path_1.join)(__dirname, "../../assets/custom-logo.png"), Buffer.from(arrayBuf));
|
|
37
|
+
}
|
|
38
|
+
const customLang = process.env.PDF_LANGUAGE;
|
|
39
|
+
if (customLang) {
|
|
40
|
+
if ((0, locales_1.isValidLocale)(customLang)) {
|
|
41
|
+
global.lang = customLang;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.warn(`The specified PDF_LANGUAGE is language is invalid (${customLang})`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
31
47
|
return new Promise((resolve) => {
|
|
32
48
|
const printer = new pdfmake_1.default(style_1.fonts);
|
|
33
49
|
const pdfDoc = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE, version));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AId, IId, Instance
|
|
1
|
+
import type { AId, IId, Instance } from "@raytio/types";
|
|
2
2
|
import { Config, InstanceDataToPassOn } from "../constants";
|
|
3
3
|
import { FlatPO } from "../helpers";
|
|
4
|
+
import { EnvConfig } from "../api";
|
|
4
5
|
import { ApplicationEncryptorLike } from "../types";
|
|
5
6
|
declare type DecryptData = {
|
|
6
7
|
apiToken: string;
|
|
@@ -39,12 +40,8 @@ export interface ProcessSubmissionOutput {
|
|
|
39
40
|
a_id: AId;
|
|
40
41
|
/** passed down so that pdf generation has access to it */
|
|
41
42
|
client_url: string;
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
profileObjects: ProfileObject[];
|
|
45
|
-
allSchemas: Schema[];
|
|
46
|
-
realVers: RealVer[];
|
|
47
|
-
};
|
|
43
|
+
/** passed down so that pdf generation has access to it */
|
|
44
|
+
envConfig: EnvConfig;
|
|
48
45
|
}
|
|
49
46
|
export declare function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }: ProcessSubmissionInput): Promise<ProcessSubmissionOutput>;
|
|
50
47
|
export {};
|
|
@@ -100,11 +100,7 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
|
|
|
100
100
|
files,
|
|
101
101
|
a_id: applicationId,
|
|
102
102
|
client_url: config.CLIENT_URL,
|
|
103
|
-
|
|
104
|
-
profileObjects,
|
|
105
|
-
allSchemas,
|
|
106
|
-
realVers,
|
|
107
|
-
},
|
|
103
|
+
envConfig,
|
|
108
104
|
};
|
|
109
105
|
}
|
|
110
106
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytio/decrypt-helper",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"author": "Raytio",
|
|
5
5
|
"description": "A helper to decrypt data shared by Raytio users",
|
|
6
6
|
"main": "dist",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev-pdf": "ts-node src/test/pdf",
|
|
13
|
-
"build": "tsc",
|
|
13
|
+
"build": "tsc && find dist -path \"*/__tests__*\" -delete && rm -rf dist/test",
|
|
14
|
+
"i18n": "react-intl-manager",
|
|
14
15
|
"lint": "eslint --format pretty --ext .js,.ts,.tsx --color --ignore-path .gitignore .",
|
|
15
16
|
"test": "jest --colors"
|
|
16
17
|
},
|
|
@@ -21,37 +22,39 @@
|
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@aws-amplify/auth": "3.4.25",
|
|
24
|
-
"@peculiar/webcrypto": "^1.2
|
|
25
|
-
"@raytio/core": "^9.0.
|
|
25
|
+
"@peculiar/webcrypto": "^1.3.2",
|
|
26
|
+
"@raytio/core": "^9.0.3",
|
|
26
27
|
"@raytio/maxcryptor": "^3.1.0",
|
|
27
28
|
"@raytio/types": "^6.0.0",
|
|
28
29
|
"aws-sdk": "^2.754.0",
|
|
29
30
|
"jsx-pdf": "^2.3.0",
|
|
30
31
|
"localstorage-polyfill": "^1.0.1",
|
|
31
|
-
"mime-types": "^2.1.
|
|
32
|
+
"mime-types": "^2.1.35",
|
|
32
33
|
"node-fetch": "^2.6.7",
|
|
33
34
|
"pdfmake": "^0.2.4",
|
|
34
35
|
"ramda": "^0.28.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
+
"@raytio/react-intl-manager": "^6.2.0",
|
|
39
|
+
"@types/jest": "^27.4.1",
|
|
38
40
|
"@types/jest-image-snapshot": "^4.3.1",
|
|
39
41
|
"@types/jsx-pdf": "^2.2.2",
|
|
40
42
|
"@types/mime-types": "^2.1.1",
|
|
41
|
-
"@types/node": "^16.11.
|
|
43
|
+
"@types/node": "^16.11.26",
|
|
42
44
|
"@types/node-fetch": "^2.5.12",
|
|
43
45
|
"@types/pdfmake": "^0.1.20",
|
|
44
|
-
"@types/ramda": "^0.
|
|
46
|
+
"@types/ramda": "^0.28.1",
|
|
47
|
+
"babel-preset-react-app": "^10.0.1",
|
|
45
48
|
"dotenv": "^16.0.0",
|
|
46
|
-
"eslint": "^8.
|
|
47
|
-
"eslint-config-kyle": "^8.
|
|
49
|
+
"eslint": "^8.11.0",
|
|
50
|
+
"eslint-config-kyle": "^8.13.0",
|
|
48
51
|
"jest": "^27.5.1",
|
|
49
52
|
"jest-image-snapshot": "^4.5.1",
|
|
50
53
|
"jest-junit": "^13.0.0",
|
|
51
54
|
"pdf-to-img": "^1.2.0",
|
|
52
55
|
"ts-jest": "^27.1.3",
|
|
53
|
-
"ts-node": "^10.
|
|
54
|
-
"typescript": "^4.
|
|
56
|
+
"ts-node": "^10.7.0",
|
|
57
|
+
"typescript": "^4.6.2"
|
|
55
58
|
},
|
|
56
59
|
"eslintConfig": {
|
|
57
60
|
"extends": "kyle",
|
|
@@ -70,6 +73,9 @@
|
|
|
70
73
|
}
|
|
71
74
|
},
|
|
72
75
|
"jest": {
|
|
76
|
+
"testMatch": [
|
|
77
|
+
"**/__tests__/?(*.)+(spec|test).[jt]s?(x)"
|
|
78
|
+
],
|
|
73
79
|
"transform": {
|
|
74
80
|
"^.+\\.(t|j)sx?$": "ts-jest"
|
|
75
81
|
},
|
|
@@ -88,10 +94,14 @@
|
|
|
88
94
|
"/dist/",
|
|
89
95
|
"/coverage/"
|
|
90
96
|
],
|
|
97
|
+
"moduleDirectories": [
|
|
98
|
+
"node_modules",
|
|
99
|
+
"src"
|
|
100
|
+
],
|
|
91
101
|
"testTimeout": 300000,
|
|
92
102
|
"testEnvironment": "node",
|
|
93
103
|
"setupFilesAfterEnv": [
|
|
94
|
-
"./
|
|
104
|
+
"./src/__tests__/setupTests.ts"
|
|
95
105
|
],
|
|
96
106
|
"reporters": [
|
|
97
107
|
"default",
|
|
@@ -104,5 +114,11 @@
|
|
|
104
114
|
},
|
|
105
115
|
"engines": {
|
|
106
116
|
"node": ">=14"
|
|
117
|
+
},
|
|
118
|
+
"i18n": {
|
|
119
|
+
"localeDir": "src/locales/translations",
|
|
120
|
+
"messagesDir": "tmp/.messages",
|
|
121
|
+
"codeQualityReport": "tmp/codequality.json",
|
|
122
|
+
"moduleSourceName": "locales"
|
|
107
123
|
}
|
|
108
124
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const fetchEnvConfig_1 = require("../fetchEnvConfig");
|
|
13
|
-
describe.each `
|
|
14
|
-
clientUrl | apiUrl
|
|
15
|
-
${"https://app.rayt.io"} | ${"https://api.rayt.io"}
|
|
16
|
-
${"https://app-dev.rayt.io"} | ${"https://api-dev.rayt.io"}
|
|
17
|
-
`("fetchEnvConfig $clientUrl / $apiUrl", ({ clientUrl, apiUrl }) => {
|
|
18
|
-
it("works if you pass it a valid client url", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
expect(yield (0, fetchEnvConfig_1.fetchEnvConfig)(clientUrl)).toStrictEqual({
|
|
20
|
-
api_url: apiUrl,
|
|
21
|
-
cognito_region: "us-east-1",
|
|
22
|
-
cognito_user_pool_id: expect.any(String),
|
|
23
|
-
cognito_web_client_id: expect.any(String),
|
|
24
|
-
});
|
|
25
|
-
}));
|
|
26
|
-
it("throws an error if you pass it an invalid url", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
yield expect(() => (0, fetchEnvConfig_1.fetchEnvConfig)(apiUrl)).rejects.toThrow(new Error(`The CLIENT_URL you specified is not a valid Raytio client. Are you sure you used the client URL, not the API url? You supplied: "${apiUrl}" (Error: Missing: cognito_region, cognito_user_pool_id, cognito_web_client_id, api_url)`));
|
|
28
|
-
}));
|
|
29
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,45 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const getFiles_1 = require("../getFiles");
|
|
13
|
-
const IMAGE_URL = "https://gitlab.com/raytio/tools/decrypt-helper/uploads/1d7e98aece246b19846d6d994ddca792/dl_limited.jpg";
|
|
14
|
-
describe("getFiles", () => {
|
|
15
|
-
it("can fetch files from urn:temp_object:", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const profileObjects = [
|
|
17
|
-
{
|
|
18
|
-
n_id: "my_drivers_lisense",
|
|
19
|
-
properties: {
|
|
20
|
-
name: "sam sample",
|
|
21
|
-
age: 123,
|
|
22
|
-
photo: {
|
|
23
|
-
content: `urn:temp_object:${btoa(IMAGE_URL)}`,
|
|
24
|
-
n_id: "my_image",
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
labels: ["ss_driver_license"],
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
const instance = {};
|
|
31
|
-
const envConfig = {};
|
|
32
|
-
const applicationDecryptor = {
|
|
33
|
-
decrypt() {
|
|
34
|
-
throw new Error("This shouldn't be called");
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
const files = yield (0, getFiles_1.getFiles)(profileObjects, instance, "api token", envConfig, applicationDecryptor);
|
|
38
|
-
expect(files).toStrictEqual({
|
|
39
|
-
my_image: [expect.any(String), "jpeg"],
|
|
40
|
-
});
|
|
41
|
-
expect(files.my_image[0].startsWith("data:image/jpeg;base64,/9j/4QCGRXhpZgAATU0AKgAA")).toBe(true);
|
|
42
|
-
// eslint-disable-next-line jest/prefer-to-have-length -- because jest will print the huge b64 to the terminal if it fails
|
|
43
|
-
expect(files.my_image[0].length).toBe(57987);
|
|
44
|
-
}));
|
|
45
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,129 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const types_1 = require("@raytio/types");
|
|
13
|
-
const formatOutput_1 = require("../formatOutput");
|
|
14
|
-
const api_1 = require("../../api");
|
|
15
|
-
jest.mock("../../api");
|
|
16
|
-
const profileObjects = [
|
|
17
|
-
{
|
|
18
|
-
labels: ["ss_name"],
|
|
19
|
-
properties: { fName: "john", lName: "doe" },
|
|
20
|
-
n_id: "n1",
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
labels: ["ss_nz_drivers_license"],
|
|
24
|
-
properties: { license_number: "DW012345", issuer: "NZTA" },
|
|
25
|
-
n_id: "n2",
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
labels: ["ss_nsw_drivers_license"],
|
|
29
|
-
properties: { license_number: "ABC123", city: "Sydney" },
|
|
30
|
-
n_id: "n3",
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
const allSchemas = [
|
|
34
|
-
{ name: "ss_name", title: "Your Name", description: "", properties: {} },
|
|
35
|
-
{
|
|
36
|
-
name: "ss_nz_drivers_license",
|
|
37
|
-
schema_group: "DL",
|
|
38
|
-
title: "NZ Drivers License",
|
|
39
|
-
description: "",
|
|
40
|
-
properties: {},
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "ss_nsw_drivers_license",
|
|
44
|
-
schema_group: "DL",
|
|
45
|
-
title: "NSW Drivers License",
|
|
46
|
-
description: "",
|
|
47
|
-
properties: {},
|
|
48
|
-
},
|
|
49
|
-
];
|
|
50
|
-
const realVers = [];
|
|
51
|
-
describe("formatOutput", () => {
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
m(api_1.resolveVerificationDetails).mockResolvedValue(Symbol.for("VerificationDetails"));
|
|
54
|
-
});
|
|
55
|
-
it("uses schema_group to group schema", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
-
const output = yield (0, formatOutput_1.formatOutput)(profileObjects, allSchemas, realVers, "[apiToken]",
|
|
57
|
-
// @ts-expect-error testing if it works with booleans not stringied bools
|
|
58
|
-
Symbol.for("envConfig"));
|
|
59
|
-
expect(output).toStrictEqual({
|
|
60
|
-
DL: [
|
|
61
|
-
{
|
|
62
|
-
$verification_details: Symbol.for("VerificationDetails"),
|
|
63
|
-
$verified: types_1.POVerification.NotVerified,
|
|
64
|
-
$shouldBeVerifiedFields: undefined,
|
|
65
|
-
$nId: "n2",
|
|
66
|
-
$properties: {
|
|
67
|
-
issuer: {
|
|
68
|
-
title: "issuer",
|
|
69
|
-
value: "NZTA",
|
|
70
|
-
verification: undefined,
|
|
71
|
-
},
|
|
72
|
-
license_number: {
|
|
73
|
-
title: "license_number",
|
|
74
|
-
value: "DW012345",
|
|
75
|
-
verification: undefined,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
$safeHarbour: "NOT_APPLICABLE",
|
|
79
|
-
$schemaName: "ss_nz_drivers_license",
|
|
80
|
-
$schemaTitle: "NZ Drivers License",
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
$verification_details: Symbol.for("VerificationDetails"),
|
|
84
|
-
$verified: types_1.POVerification.NotVerified,
|
|
85
|
-
$shouldBeVerifiedFields: undefined,
|
|
86
|
-
$nId: "n3",
|
|
87
|
-
$properties: {
|
|
88
|
-
city: {
|
|
89
|
-
title: "city",
|
|
90
|
-
value: "Sydney",
|
|
91
|
-
verification: undefined,
|
|
92
|
-
},
|
|
93
|
-
license_number: {
|
|
94
|
-
title: "license_number",
|
|
95
|
-
value: "ABC123",
|
|
96
|
-
verification: undefined,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
$safeHarbour: "NOT_APPLICABLE",
|
|
100
|
-
$schemaName: "ss_nsw_drivers_license",
|
|
101
|
-
$schemaTitle: "NSW Drivers License",
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
ss_name: [
|
|
105
|
-
{
|
|
106
|
-
$verification_details: Symbol.for("VerificationDetails"),
|
|
107
|
-
$verified: types_1.POVerification.NotVerified,
|
|
108
|
-
$shouldBeVerifiedFields: undefined,
|
|
109
|
-
$nId: "n1",
|
|
110
|
-
$properties: {
|
|
111
|
-
fName: {
|
|
112
|
-
title: "fName",
|
|
113
|
-
value: "john",
|
|
114
|
-
verification: undefined,
|
|
115
|
-
},
|
|
116
|
-
lName: {
|
|
117
|
-
title: "lName",
|
|
118
|
-
value: "doe",
|
|
119
|
-
verification: undefined,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
$safeHarbour: "NOT_APPLICABLE",
|
|
123
|
-
$schemaName: "ss_name",
|
|
124
|
-
$schemaTitle: "Your Name",
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
});
|
|
128
|
-
}));
|
|
129
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,79 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const getLookupOption_ts_1 = require("../../api/getLookupOption.ts");
|
|
13
|
-
const lookup_ts_1 = require("../lookup.ts");
|
|
14
|
-
jest.mock("../../api/getLookupOption.ts");
|
|
15
|
-
describe("maybeAddLookupValue", () => {
|
|
16
|
-
it("returns lookup if no value", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
getLookupOption_ts_1.getLookupOption.mockImplementation(() => []);
|
|
18
|
-
const value = "NZ";
|
|
19
|
-
const key = "country";
|
|
20
|
-
const schema = {
|
|
21
|
-
properties: {
|
|
22
|
-
country: {
|
|
23
|
-
priority: 200,
|
|
24
|
-
tags: ["display:no_autofill"],
|
|
25
|
-
description: "The country of this location",
|
|
26
|
-
default: "NZ",
|
|
27
|
-
type: "string",
|
|
28
|
-
title: "Location country",
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
|
|
33
|
-
expect(result).toBe("NZ");
|
|
34
|
-
}));
|
|
35
|
-
it("Returns lookup value", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
getLookupOption_ts_1.getLookupOption.mockImplementation(() => [
|
|
37
|
-
{ key: "NZ", value: "New Zealand" },
|
|
38
|
-
]);
|
|
39
|
-
const value = "NZ";
|
|
40
|
-
const key = "country";
|
|
41
|
-
const schema = {
|
|
42
|
-
properties: {
|
|
43
|
-
country: {
|
|
44
|
-
priority: 200,
|
|
45
|
-
tags: ["display:no_autofill"],
|
|
46
|
-
lookup: "https://LookupAPI.yes",
|
|
47
|
-
description: "The country of this location",
|
|
48
|
-
default: "NZ",
|
|
49
|
-
type: "string",
|
|
50
|
-
title: "Location country",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
|
|
55
|
-
expect(result).toBe("New Zealand");
|
|
56
|
-
}));
|
|
57
|
-
it("Returns value if no corresponding key in lookup", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
getLookupOption_ts_1.getLookupOption.mockImplementation(() => [
|
|
59
|
-
{ key: "DE", value: "Doesn't Exist" },
|
|
60
|
-
]);
|
|
61
|
-
const value = "NZ";
|
|
62
|
-
const key = "country";
|
|
63
|
-
const schema = {
|
|
64
|
-
properties: {
|
|
65
|
-
country: {
|
|
66
|
-
priority: 200,
|
|
67
|
-
tags: ["display:no_autofill"],
|
|
68
|
-
lookup: "https://LookupAPI.yes",
|
|
69
|
-
description: "The country of this location",
|
|
70
|
-
default: "NZ",
|
|
71
|
-
type: "string",
|
|
72
|
-
title: "Location country",
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
|
|
77
|
-
expect(result).toBe("NZ");
|
|
78
|
-
}));
|
|
79
|
-
});
|
package/dist/test/pdf.d.ts
DELETED
package/dist/test/pdf.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This is just for developing locally
|
|
4
|
-
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const pdfmake_1 = __importDefault(require("pdfmake"));
|
|
11
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
const Report_1 = require("../pdf/components/Report");
|
|
14
|
-
const style_1 = require("../pdf/style");
|
|
15
|
-
let json;
|
|
16
|
-
try {
|
|
17
|
-
json = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, "../../out.json"), { encoding: "utf-8" }));
|
|
18
|
-
}
|
|
19
|
-
catch (_a) {
|
|
20
|
-
console.error("You need to save some data into out.json beforing using this test script");
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
let files = {};
|
|
24
|
-
try {
|
|
25
|
-
files = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, "../../out-otherfiles.json"), {
|
|
26
|
-
encoding: "utf-8",
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
catch (_b) {
|
|
30
|
-
console.warn("Files not found");
|
|
31
|
-
}
|
|
32
|
-
const printer = new pdfmake_1.default(style_1.fonts);
|
|
33
|
-
const pdfDoc = printer.createPdfKitDocument(jsx_pdf_1.default.renderPdf(jsx_pdf_1.default.createElement(Report_1.Report, { data: json, files: files, aId: "my_a_id", clientUrl: "https://example.com", config: { DATE_FORMAT: "fr-FR", TIMEZONE: "Atlantic/Azores" }, version: "\u2764\uFE0F\u200D\uD83D\uDD25" })));
|
|
34
|
-
pdfDoc.pipe((0, fs_1.createWriteStream)("out.pdf"));
|
|
35
|
-
pdfDoc.end();
|