@raytio/decrypt-helper 6.4.2 → 6.4.3
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 +35 -0
- package/dist/api/fetchAA.d.ts +3 -0
- package/dist/api/fetchAA.js +18 -0
- package/dist/api/fetchEnvConfig.d.ts +6 -0
- package/dist/api/fetchEnvConfig.js +35 -0
- package/dist/api/fetchInstanceData.d.ts +3 -0
- package/dist/api/fetchInstanceData.js +19 -0
- package/dist/api/getFiles.d.ts +6 -0
- package/dist/api/getFiles.js +125 -0
- package/dist/api/getLookupOption.d.ts +2 -0
- package/dist/api/getLookupOption.js +29 -0
- package/dist/api/getSchema.d.ts +3 -0
- package/dist/api/getSchema.js +28 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.js +9 -0
- package/dist/api/resolveVerificationDetails.d.ts +11 -0
- package/dist/api/resolveVerificationDetails.js +31 -0
- package/dist/api/signIn.d.ts +7 -0
- package/dist/api/signIn.js +52 -0
- package/dist/api/updateInstanceData.d.ts +7 -0
- package/dist/api/updateInstanceData.js +23 -0
- package/dist/api/uploadToObjectStore.d.ts +5 -0
- package/dist/api/uploadToObjectStore.js +40 -0
- package/dist/api/videoToImage.d.ts +3 -0
- package/dist/api/videoToImage.js +26 -0
- package/dist/configureEnv.d.ts +1 -0
- package/dist/configureEnv.js +19 -0
- package/dist/constants.d.ts +23 -0
- package/dist/constants.js +42 -0
- package/dist/helpers/file.d.ts +17 -0
- package/dist/helpers/file.js +16 -0
- package/dist/helpers/formatOutput.d.ts +28 -0
- package/dist/helpers/formatOutput.js +100 -0
- package/dist/helpers/index.d.ts +6 -0
- package/dist/helpers/index.js +6 -0
- package/dist/helpers/json2csv.d.ts +2 -0
- package/dist/helpers/json2csv.js +20 -0
- package/dist/helpers/jsxPdf.d.ts +6 -0
- package/dist/helpers/jsxPdf.js +3 -0
- package/dist/helpers/lookup.d.ts +2 -0
- package/dist/helpers/lookup.js +31 -0
- package/dist/helpers/pathUtils.d.ts +1 -0
- package/dist/helpers/pathUtils.js +6 -0
- package/dist/helpers/setupMaxcryptor.d.ts +4 -0
- package/dist/helpers/setupMaxcryptor.js +25 -0
- package/dist/helpers/splitPOAndVers.d.ts +2 -0
- package/dist/helpers/splitPOAndVers.js +8 -0
- package/dist/helpers/types.d.ts +1 -0
- package/dist/helpers/types.js +5 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +9 -0
- package/dist/locales/index.d.ts +12 -0
- package/dist/locales/index.js +17 -0
- package/dist/locales/translations/en.json +33 -0
- package/dist/pdf/components/FieldVerificationBadge.d.ts +5 -0
- package/dist/pdf/components/FieldVerificationBadge.js +12 -0
- package/dist/pdf/components/Images.d.ts +5 -0
- package/dist/pdf/components/Images.js +13 -0
- package/dist/pdf/components/InnerTableRows.d.ts +10 -0
- package/dist/pdf/components/InnerTableRows.js +30 -0
- package/dist/pdf/components/POVerificationBadge.d.ts +7 -0
- package/dist/pdf/components/POVerificationBadge.js +34 -0
- package/dist/pdf/components/Report.d.ts +12 -0
- package/dist/pdf/components/Report.js +91 -0
- package/dist/pdf/components/Subheader.d.ts +1 -0
- package/dist/pdf/components/Subheader.js +21 -0
- package/dist/pdf/components/Table.d.ts +8 -0
- package/dist/pdf/components/Table.js +40 -0
- package/dist/pdf/components/TableTitle.d.ts +4 -0
- package/dist/pdf/components/TableTitle.js +10 -0
- package/dist/pdf/components/ValidationDisplay.d.ts +4 -0
- package/dist/pdf/components/ValidationDisplay.js +22 -0
- package/dist/pdf/components/VerifyBox.d.ts +8 -0
- package/dist/pdf/components/VerifyBox.js +12 -0
- package/dist/pdf/components/pieChart.d.ts +6 -0
- package/dist/pdf/components/pieChart.js +23 -0
- package/dist/pdf/constants.d.ts +3 -0
- package/dist/pdf/constants.js +9 -0
- package/dist/pdf/helpers/general.d.ts +8 -0
- package/dist/pdf/helpers/general.js +31 -0
- package/dist/pdf/helpers/transform.d.ts +4 -0
- package/dist/pdf/helpers/transform.js +35 -0
- package/dist/pdf/style.d.ts +10 -0
- package/dist/pdf/style.js +21 -0
- package/dist/public-methods/generatePDF.d.ts +4 -0
- package/dist/public-methods/generatePDF.js +54 -0
- package/dist/public-methods/getAndValidateConfig.d.ts +8 -0
- package/dist/public-methods/getAndValidateConfig.js +16 -0
- package/dist/public-methods/processSubmission.d.ts +49 -0
- package/dist/public-methods/processSubmission.js +132 -0
- package/dist/public-methods/saveToS3Bucket.d.ts +2 -0
- package/dist/public-methods/saveToS3Bucket.js +53 -0
- package/dist/public-methods/version.d.ts +2 -0
- package/dist/public-methods/version.js +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FieldVerification, POVerification, } from "@raytio/types";
|
|
2
|
+
import { $$ } from "./locales/index.js";
|
|
3
|
+
export const ATTRIBUTE_MAP = {
|
|
4
|
+
"custom:kek_derivation": ["kek_derivation_config"],
|
|
5
|
+
"custom:dek_encryption": ["private_key_encryption_config"],
|
|
6
|
+
"custom:aek_public": ["encryption_key_pair", "public_key"],
|
|
7
|
+
"custom:aek_private": ["encryption_key_pair", "private_key"],
|
|
8
|
+
"custom:ask_public": ["signing_key_pair", "public_key"],
|
|
9
|
+
"custom:ask_private": ["signing_key_pair", "private_key"],
|
|
10
|
+
};
|
|
11
|
+
export const INSTANCE_FIELDS_TO_REMOVE = [
|
|
12
|
+
"profile_objects",
|
|
13
|
+
"relationships",
|
|
14
|
+
"keys",
|
|
15
|
+
"score",
|
|
16
|
+
];
|
|
17
|
+
export const FIELDS_TO_REMOVE = ["n_id", "document"];
|
|
18
|
+
export const ENV_VARIABLES = [
|
|
19
|
+
"CLIENT_URL",
|
|
20
|
+
"RAYTIO_USERNAME",
|
|
21
|
+
"RAYTIO_PASSWORD",
|
|
22
|
+
];
|
|
23
|
+
export const PO_VER_TEXT_MAP = {
|
|
24
|
+
[POVerification.FullyVerified]: $$("POVerification.FullyVerified"),
|
|
25
|
+
[POVerification.PartiallyVerified]: $$("POVerification.PartiallyVerified"),
|
|
26
|
+
[POVerification.NotVerified]: $$("POVerification.NotVerified"),
|
|
27
|
+
[POVerification.Expired]: $$("POVerification.Expired"),
|
|
28
|
+
[POVerification.VerifiedFalse]: $$("POVerification.VerifiedFalse"),
|
|
29
|
+
// not possible but included here for completeness
|
|
30
|
+
[POVerification.Encrypted]: $$("POVerification.Encrypted"),
|
|
31
|
+
[POVerification.Loading]: $$("POVerification.Loading"),
|
|
32
|
+
};
|
|
33
|
+
export const FIELD_VER_TEXT_MAP = {
|
|
34
|
+
[FieldVerification.Verified]: $$("FieldVerification.Verified"),
|
|
35
|
+
[FieldVerification.NotVerified]: $$("FieldVerification.NotVerified"),
|
|
36
|
+
[FieldVerification.Expired]: $$("FieldVerification.Expired"),
|
|
37
|
+
[FieldVerification.VerifiedFalse]: $$("FieldVerification.VerifiedFalse"),
|
|
38
|
+
};
|
|
39
|
+
export const SCHEMA = {
|
|
40
|
+
VERIFICATION: "ss_Verification",
|
|
41
|
+
PERSON: "ss_Person_Name",
|
|
42
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Encrypted, NId, Urn } from "@raytio/types";
|
|
2
|
+
import type { FlatPO } from "./formatOutput.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare const isTruthy: <T>(x: "" | 0 | T | null | undefined) => x is T;
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare const isUrn: (text: string) => text is Urn;
|
|
7
|
+
export type RaytFile = {
|
|
8
|
+
n_id: NId;
|
|
9
|
+
content: Urn | Encrypted;
|
|
10
|
+
} | {
|
|
11
|
+
n_id: NId;
|
|
12
|
+
Content: Urn | Encrypted;
|
|
13
|
+
};
|
|
14
|
+
/** checks if a field value is a file */
|
|
15
|
+
export declare const isFieldValueFile: (fieldValue: unknown) => fieldValue is RaytFile;
|
|
16
|
+
/** checks if a PO is a file */
|
|
17
|
+
export declare const isPOFile: (PO: FlatPO) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isEncrypted } from "@raytio/core";
|
|
2
|
+
const URN_PREFIX = "urn:";
|
|
3
|
+
/** @internal */
|
|
4
|
+
const isObject = (x) => !!x && typeof x === "object";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export const isTruthy = (x) => !!x;
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const isUrn = (text) => text.startsWith(URN_PREFIX);
|
|
9
|
+
/** @internal */
|
|
10
|
+
const isUrnOrEncrypted = (x) => (typeof x === "string" && x.startsWith(URN_PREFIX)) || isEncrypted(x);
|
|
11
|
+
/** checks if a field value is a file */
|
|
12
|
+
export const isFieldValueFile = (fieldValue) => isObject(fieldValue) &&
|
|
13
|
+
"content" in fieldValue &&
|
|
14
|
+
isUrnOrEncrypted(fieldValue.content);
|
|
15
|
+
/** checks if a PO is a file */
|
|
16
|
+
export const isPOFile = (PO) => { var _a; return isFieldValueFile({ content: (_a = PO.$properties.content) === null || _a === void 0 ? void 0 : _a.value }); };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FieldVerification, type NId, type POVerification, type ProfileObject, type RealVer, type Schema } from "@raytio/types";
|
|
2
|
+
import { type EnvConfig, type ResolvedVerificationProvider } from "../api/index.js";
|
|
3
|
+
export type FlatPO = {
|
|
4
|
+
$verification_details: ResolvedVerificationProvider | undefined;
|
|
5
|
+
$shouldBeVerifiedFields: string[] | undefined;
|
|
6
|
+
$nId: NId;
|
|
7
|
+
$schemaName: string;
|
|
8
|
+
$schemaTitle: string;
|
|
9
|
+
$properties: {
|
|
10
|
+
[fieldName: string]: {
|
|
11
|
+
title: string;
|
|
12
|
+
value: unknown;
|
|
13
|
+
formatted_value?: string | number;
|
|
14
|
+
verification: FieldVerification;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
$badges: {
|
|
18
|
+
verified: {
|
|
19
|
+
code: POVerification;
|
|
20
|
+
statusText: string;
|
|
21
|
+
};
|
|
22
|
+
safeHarbour?: {
|
|
23
|
+
code: boolean;
|
|
24
|
+
statusText: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare function formatOutput(profileObjects: ProfileObject[], allSchemas: Schema[], realVers: RealVer[], apiToken: string, envConfig: EnvConfig): Promise<Record<string, FlatPO[]>>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { calcSafeHarbourScore, findSchemaLabel, getPOVerification, } from "@raytio/core";
|
|
11
|
+
import { omit } from "ramda";
|
|
12
|
+
import { FieldVerification, } from "@raytio/types";
|
|
13
|
+
import { $$ } from "../locales/index.js";
|
|
14
|
+
import { resolveVerificationDetails, } from "../api/index.js";
|
|
15
|
+
import { FIELDS_TO_REMOVE, PO_VER_TEXT_MAP, SCHEMA } from "../constants.js";
|
|
16
|
+
import { maybeGetLookupValue } from "./lookup.js";
|
|
17
|
+
import { assertSafeProperty } from "./types.js";
|
|
18
|
+
const byPriority = (schema) => ([a], [b]) => {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f;
|
|
20
|
+
assertSafeProperty(a);
|
|
21
|
+
assertSafeProperty(b);
|
|
22
|
+
// if no priority, it becomes the last
|
|
23
|
+
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;
|
|
24
|
+
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;
|
|
25
|
+
return aPriority - bPriority;
|
|
26
|
+
};
|
|
27
|
+
export function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const locale = process.env.PDF_LANGUAGE || process.env.DATE_FORMAT || "en-NZ";
|
|
30
|
+
const tagsToHide = [
|
|
31
|
+
"type:client_only",
|
|
32
|
+
"type:globally_unique_field",
|
|
33
|
+
];
|
|
34
|
+
const filteredPOs = profileObjects.filter((PO) => {
|
|
35
|
+
const schemaName = findSchemaLabel(PO.labels);
|
|
36
|
+
return (schemaName &&
|
|
37
|
+
!tagsToHide.some((tag) => { var _a, _b; return (_b = (_a = allSchemas.find((s) => s.name === schemaName)) === null || _a === void 0 ? void 0 : _a.tags) === null || _b === void 0 ? void 0 : _b.includes(tag); }));
|
|
38
|
+
});
|
|
39
|
+
const PODetails = filteredPOs.reduce((accumulatorPromiseOuter, PO) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a;
|
|
41
|
+
const accumulatorOuter = yield accumulatorPromiseOuter;
|
|
42
|
+
const schemaName = findSchemaLabel(PO.labels);
|
|
43
|
+
const schema = allSchemas.find((x) => x.name === schemaName);
|
|
44
|
+
if (!schema)
|
|
45
|
+
throw new Error(`${schema} is missing!`);
|
|
46
|
+
const versionDetails = getPOVerification({ PO, schema, realVers });
|
|
47
|
+
const realProperties = omit(FIELDS_TO_REMOVE, PO.properties);
|
|
48
|
+
assertSafeProperty(schemaName);
|
|
49
|
+
const existing = accumulatorOuter[schemaName] || [];
|
|
50
|
+
const poProperties = Object.entries(realProperties).sort(byPriority(schema));
|
|
51
|
+
const reducedProperties = yield poProperties.reduce((accumulatorPromiseInner, [key, value]) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
var _b, _c, _d;
|
|
53
|
+
const accumulatorInner = yield accumulatorPromiseInner;
|
|
54
|
+
assertSafeProperty(key);
|
|
55
|
+
const prettyValue = typeof value === "string"
|
|
56
|
+
? yield maybeGetLookupValue(schema, key, value, apiToken, envConfig.api_url)
|
|
57
|
+
: undefined;
|
|
58
|
+
const schemaField = Object.values(schema.properties || {}).find((f) => f.$prop.split(" <=> ")[0] === (key === null || key === void 0 ? void 0 : key.split(" <=> ")[0]));
|
|
59
|
+
const POInfo = {
|
|
60
|
+
title: ((_d = (_c = (_b = schema === null || schema === void 0 ? void 0 : schema.i18n) === null || _b === void 0 ? void 0 : _b[locale]) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.title) || (schemaField === null || schemaField === void 0 ? void 0 : schemaField.title) || key,
|
|
61
|
+
value,
|
|
62
|
+
verification: versionDetails.fieldVerifications[key] ||
|
|
63
|
+
FieldVerification.NotVerified,
|
|
64
|
+
};
|
|
65
|
+
if (prettyValue)
|
|
66
|
+
POInfo.formatted_value = prettyValue;
|
|
67
|
+
return Object.assign(Object.assign({}, accumulatorInner), { [key]: POInfo });
|
|
68
|
+
}), Promise.resolve({}));
|
|
69
|
+
const thisPO = {
|
|
70
|
+
$verification_details: yield resolveVerificationDetails(versionDetails.details.verifiers, envConfig),
|
|
71
|
+
$shouldBeVerifiedFields: (_a = schema.verified_fields) === null || _a === void 0 ? void 0 : _a.map((x) => typeof x === "string" ? x : x.field),
|
|
72
|
+
$nId: PO.n_id,
|
|
73
|
+
$schemaName: schemaName,
|
|
74
|
+
$schemaTitle: schema.title,
|
|
75
|
+
$properties: reducedProperties,
|
|
76
|
+
$badges: {
|
|
77
|
+
verified: {
|
|
78
|
+
code: versionDetails.status,
|
|
79
|
+
statusText: PO_VER_TEXT_MAP[versionDetails.status],
|
|
80
|
+
},
|
|
81
|
+
safeHarbour: schemaName === SCHEMA.PERSON
|
|
82
|
+
? yield calcSafeHarbourScore({
|
|
83
|
+
person: PO,
|
|
84
|
+
getSchema: (name) => __awaiter(this, void 0, void 0, function* () { return allSchemas.find((x) => x.name === name); }),
|
|
85
|
+
profileObjects,
|
|
86
|
+
realVers,
|
|
87
|
+
}).then(({ isSafe }) => ({
|
|
88
|
+
code: isSafe,
|
|
89
|
+
statusText: isSafe
|
|
90
|
+
? $$("POVerificationBadge.safe-harbour-yes")
|
|
91
|
+
: $$("POVerificationBadge.safe-harbour-no"),
|
|
92
|
+
}))
|
|
93
|
+
: undefined,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
return Object.assign(Object.assign({}, accumulatorOuter), { [schemaName]: [...existing, thisPO] });
|
|
97
|
+
}), Promise.resolve({}));
|
|
98
|
+
return PODetails;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { chain, fromPairs, map, toPairs, transpose, type } from "ramda";
|
|
3
|
+
// copied from raytio-client
|
|
4
|
+
export const flattenObject = (rootObject) => {
|
|
5
|
+
const go = (object) => chain(([k, v]) => {
|
|
6
|
+
if (type(v) === "Object" || type(v) === "Array") {
|
|
7
|
+
return map(([k_, v_]) => [`${k}.${k_}`, v_], go(v));
|
|
8
|
+
}
|
|
9
|
+
return [[k, v]];
|
|
10
|
+
}, toPairs(object));
|
|
11
|
+
return fromPairs(go(rootObject));
|
|
12
|
+
};
|
|
13
|
+
const toCsvRow = (row) => row
|
|
14
|
+
.map((field) => typeof field === "string" ? `"${field.replaceAll('"', '""')}"` : field)
|
|
15
|
+
.join(",");
|
|
16
|
+
export function deepJsonToCsv(json) {
|
|
17
|
+
const flatJson = flattenObject(json);
|
|
18
|
+
const [headerRow, values] = transpose(Object.entries(flatJson));
|
|
19
|
+
return `${toCsvRow(headerRow)}\n${toCsvRow(values)}`;
|
|
20
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const JsxPdf: {
|
|
2
|
+
createElement: <P extends Record<string, unknown>>(type: string | ((props: P) => JSX.Element), props: P | null, ...children: (string | number | boolean | JSX.Element | null | undefined)[]) => JSX.Element;
|
|
3
|
+
Fragment: JSX.Ele<Omit<import("pdfmake/interfaces").ContentStack, "stack">>;
|
|
4
|
+
renderPdf: (element: JSX.Element) => import("pdfmake/interfaces").TDocumentDefinitions;
|
|
5
|
+
default: any;
|
|
6
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getLookupOption } from "../api/getLookupOption.js";
|
|
11
|
+
export const maybeGetLookupValue = (schema, k, value, apiToken, apiBaseUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const lookupUrl = (_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[k]) === null || _b === void 0 ? void 0 : _b.lookup;
|
|
14
|
+
if (!lookupUrl)
|
|
15
|
+
return undefined;
|
|
16
|
+
// Replace environment variables in the lookup URL
|
|
17
|
+
const regex = /{([^}]+)}/g;
|
|
18
|
+
const matches = lookupUrl.match(regex);
|
|
19
|
+
const replaced = matches === null || matches === void 0 ? void 0 : matches.map((match) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const toReplace = match.replace("{", "").replace("}", "");
|
|
22
|
+
return (_a = process.env[toReplace]) !== null && _a !== void 0 ? _a : "";
|
|
23
|
+
});
|
|
24
|
+
const resolvedLookupUrl = matches
|
|
25
|
+
? matches
|
|
26
|
+
.reduce((url, match, i) => { var _a; return url.replace(match, (_a = replaced === null || replaced === void 0 ? void 0 : replaced[i]) !== null && _a !== void 0 ? _a : ""); }, lookupUrl)
|
|
27
|
+
.replaceAll(/([^:]\/)\/+/g, "$1") // replaces doubles slashes (bar http://)
|
|
28
|
+
: lookupUrl;
|
|
29
|
+
const lookup = yield getLookupOption(apiToken, resolvedLookupUrl, apiBaseUrl);
|
|
30
|
+
return (_c = lookup.find((l) => l.key === value)) === null || _c === void 0 ? void 0 : _c.value;
|
|
31
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDirname(): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import maxcryptor from "@raytio/maxcryptor";
|
|
2
|
+
import type { ICognitoUserAttributeData } from "amazon-cognito-identity-js";
|
|
3
|
+
import { type Config } from "../constants.js";
|
|
4
|
+
export declare function setupMaxcryptor(CONFIG: Config, cognitoAttributes: ICognitoUserAttributeData[]): Promise<maxcryptor.Maxcryptor>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import maxcryptor from "@raytio/maxcryptor";
|
|
11
|
+
import { assocPath } from "ramda";
|
|
12
|
+
import { ATTRIBUTE_MAP } from "../constants.js";
|
|
13
|
+
const { encryptorFromExistingUser } = maxcryptor;
|
|
14
|
+
const isMaxcryptorAttribute = (name) => name in ATTRIBUTE_MAP;
|
|
15
|
+
export function setupMaxcryptor(CONFIG, cognitoAttributes) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const userDocument = cognitoAttributes.reduce((accumulator, { Name, Value }) => {
|
|
18
|
+
if (!isMaxcryptorAttribute(Name))
|
|
19
|
+
return accumulator;
|
|
20
|
+
return assocPath(ATTRIBUTE_MAP[Name], JSON.parse(Value), accumulator);
|
|
21
|
+
}, {});
|
|
22
|
+
const { encryptor: maxcryptorEncryptor } = yield encryptorFromExistingUser(userDocument, CONFIG.RAYTIO_PASSWORD);
|
|
23
|
+
return maxcryptorEncryptor;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { findSchemaLabel } from "@raytio/core";
|
|
2
|
+
import { SCHEMA } from "../constants.js";
|
|
3
|
+
export const splitPOAndVers = (list) => list.reduce((accumulator, PO) => {
|
|
4
|
+
const isVerification = findSchemaLabel(PO.labels) === SCHEMA.VERIFICATION;
|
|
5
|
+
// move to the left or right array depending on whther +isVerification is 0 or 1
|
|
6
|
+
accumulator[+isVerification].push(PO);
|
|
7
|
+
return accumulator;
|
|
8
|
+
}, [[], []]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertSafeProperty(property: unknown): asserts property is string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./configureEnv.js";
|
|
2
|
+
export { fetchEnvConfig, EnvConfig } from "./api/fetchEnvConfig.js";
|
|
3
|
+
export { generatePDF } from "./public-methods/generatePDF.js";
|
|
4
|
+
export { processSubmission } from "./public-methods/processSubmission.js";
|
|
5
|
+
export { getAndValidateConfig } from "./public-methods/getAndValidateConfig.js";
|
|
6
|
+
export { saveToS3Bucket } from "./public-methods/saveToS3Bucket.js";
|
|
7
|
+
export { version } from "./public-methods/version.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// do this first
|
|
2
|
+
import "./configureEnv.js";
|
|
3
|
+
/* this is what consumers of the package have access to */
|
|
4
|
+
export { fetchEnvConfig } from "./api/fetchEnvConfig.js";
|
|
5
|
+
export { generatePDF } from "./public-methods/generatePDF.js";
|
|
6
|
+
export { processSubmission } from "./public-methods/processSubmission.js";
|
|
7
|
+
export { getAndValidateConfig } from "./public-methods/getAndValidateConfig.js";
|
|
8
|
+
export { saveToS3Bucket } from "./public-methods/saveToS3Bucket.js";
|
|
9
|
+
export { version } from "./public-methods/version.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const en: any;
|
|
2
|
+
declare const locales: {
|
|
3
|
+
readonly en: any;
|
|
4
|
+
};
|
|
5
|
+
export type I18nKey = keyof typeof en;
|
|
6
|
+
export type I18nLang = keyof typeof locales;
|
|
7
|
+
declare global {
|
|
8
|
+
var lang: I18nLang;
|
|
9
|
+
}
|
|
10
|
+
export declare const isValidLocale: (lang: string) => lang is "en";
|
|
11
|
+
export declare const $$: (key: I18nKey, variables?: Record<string, string | number>) => string;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getDirname } from "../helpers/pathUtils.js";
|
|
4
|
+
const en = JSON.parse(readFileSync(join(getDirname(), "../locales/translations/en.json"), "utf8"));
|
|
5
|
+
const locales = { en };
|
|
6
|
+
export const isValidLocale = (lang) => lang in locales;
|
|
7
|
+
export const $$ = (key, variables) => {
|
|
8
|
+
const strings = locales[global.lang || "en"];
|
|
9
|
+
const replaceWithVariable = (_, variableName) => {
|
|
10
|
+
const value = variables === null || variables === void 0 ? void 0 : variables[variableName];
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
throw new TypeError(`[i18n] variable '${variableName}' not defined`);
|
|
13
|
+
}
|
|
14
|
+
return `${value}`;
|
|
15
|
+
};
|
|
16
|
+
return strings[key].replaceAll(/{([^}]+)}/g, replaceWithVariable);
|
|
17
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FieldVerification } from "@raytio/types";
|
|
2
|
+
import { JsxPdf } from "../../helpers/jsxPdf.js";
|
|
3
|
+
import { loadAsset } from "../helpers/general.js";
|
|
4
|
+
export const FieldVerificationBadge = ({ status, width, }) => {
|
|
5
|
+
if (status === FieldVerification.VerifiedFalse) {
|
|
6
|
+
return (JsxPdf.createElement("svg", { content: loadAsset("verified_false_small.svg"), width: width }));
|
|
7
|
+
}
|
|
8
|
+
if (status === FieldVerification.Verified) {
|
|
9
|
+
return JsxPdf.createElement("svg", { content: loadAsset("verified_tick_small.svg"), width: width });
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JsxPdf } from "../../helpers/jsxPdf.js";
|
|
2
|
+
import { $$ } from "../../locales/index.js";
|
|
3
|
+
import { assertSafeProperty } from "../../helpers/index.js";
|
|
4
|
+
export const Images = ({ nIds, files, }) => {
|
|
5
|
+
return (JsxPdf.createElement(JsxPdf.Fragment, null, nIds.map((nId) => {
|
|
6
|
+
var _a;
|
|
7
|
+
// for videos, prefer the static frame over the original video
|
|
8
|
+
const file = (_a = (files[`${nId}_videoFrame`] || files[nId])) === null || _a === void 0 ? void 0 : _a[0];
|
|
9
|
+
if (file)
|
|
10
|
+
assertSafeProperty(file);
|
|
11
|
+
return file ? (JsxPdf.createElement("image", { src: file, width: 300 })) : (JsxPdf.createElement("text", null, $$("Images.file-not-found")));
|
|
12
|
+
})));
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProcessSubmissionOutput } from "../../public-methods/processSubmission.js";
|
|
2
|
+
import type { PdfConfig } from "../types.js";
|
|
3
|
+
export declare const InnerTableRows: ({ key, value, imageFieldNames, config, files, color, }: {
|
|
4
|
+
key: string;
|
|
5
|
+
value: any;
|
|
6
|
+
files: ProcessSubmissionOutput["files"];
|
|
7
|
+
config: PdfConfig;
|
|
8
|
+
color: string;
|
|
9
|
+
imageFieldNames: string[];
|
|
10
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { uniq } from "ramda";
|
|
2
|
+
import { JsxPdf } from "../../helpers/jsxPdf.js";
|
|
3
|
+
import { assertSafeProperty } from "../../helpers/index.js";
|
|
4
|
+
import { IS_ARRAY_OF_OBJECTS, IS_IMAGE, transform, } from "../helpers/transform.js";
|
|
5
|
+
import { Images } from "./Images.js";
|
|
6
|
+
import { ValidationDisplay } from "./ValidationDisplay.js";
|
|
7
|
+
export const InnerTableRows = ({ key, value, imageFieldNames, config, files, color, }) => {
|
|
8
|
+
if (typeof value === "object" &&
|
|
9
|
+
value &&
|
|
10
|
+
"score" in value &&
|
|
11
|
+
"breakdown" in value) {
|
|
12
|
+
return JsxPdf.createElement(ValidationDisplay, { value: value });
|
|
13
|
+
}
|
|
14
|
+
const text = transform(key, value, config, imageFieldNames);
|
|
15
|
+
if (typeof text !== "string" && text === IS_IMAGE) {
|
|
16
|
+
return JsxPdf.createElement(Images, { files: files, nIds: [value.n_id] });
|
|
17
|
+
}
|
|
18
|
+
if (typeof text !== "string" && text === IS_ARRAY_OF_OBJECTS) {
|
|
19
|
+
const headers = [uniq(value.flatMap(Object.keys))];
|
|
20
|
+
const tableValues = [...headers, ...value];
|
|
21
|
+
return (JsxPdf.createElement("table", { headerRows: 1, layout: "headerLineOnly" }, tableValues.map((data, tableValueIndex) => {
|
|
22
|
+
return (JsxPdf.createElement("row", null, headers[0].map((header) => {
|
|
23
|
+
assertSafeProperty(header);
|
|
24
|
+
return (JsxPdf.createElement("cell", null,
|
|
25
|
+
JsxPdf.createElement(InnerTableRows, { key: header, value: data[header] || (tableValueIndex === 0 ? header : "-"), files: files, config: config, color: color, imageFieldNames: imageFieldNames })));
|
|
26
|
+
})));
|
|
27
|
+
})));
|
|
28
|
+
}
|
|
29
|
+
return JsxPdf.createElement("text", { color: color }, text.slice(0, 100));
|
|
30
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { POVerification } from "@raytio/types";
|
|
2
|
+
import type { FlatPO } from "../../helpers/index.js";
|
|
3
|
+
export declare const FILE_MAP: Record<POVerification, string>;
|
|
4
|
+
export declare const POVerificationBadge: ({ width, POs, }: {
|
|
5
|
+
width: number;
|
|
6
|
+
POs: FlatPO[];
|
|
7
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { POVerification } from "@raytio/types";
|
|
2
|
+
import { JsxPdf } from "../../helpers/jsxPdf.js";
|
|
3
|
+
import { $$ } from "../../locales/index.js";
|
|
4
|
+
import { loadAsset } from "../helpers/general.js";
|
|
5
|
+
import { PO_VER_TEXT_MAP } from "../../constants.js";
|
|
6
|
+
export const FILE_MAP = {
|
|
7
|
+
[POVerification.FullyVerified]: "verified_user_big",
|
|
8
|
+
[POVerification.PartiallyVerified]: "verified_partial_big",
|
|
9
|
+
[POVerification.NotVerified]: "not_verified_big",
|
|
10
|
+
[POVerification.Expired]: "not_verified_big",
|
|
11
|
+
[POVerification.VerifiedFalse]: "false_verified_user_big",
|
|
12
|
+
// not possible but included here for completeness
|
|
13
|
+
[POVerification.Encrypted]: "not_verified_big",
|
|
14
|
+
[POVerification.Loading]: "not_verified_big",
|
|
15
|
+
};
|
|
16
|
+
export const POVerificationBadge = ({ width, POs, }) => {
|
|
17
|
+
// TODO: this won't work if multiple POs of the same schema are shared
|
|
18
|
+
const { $badges, $verification_details, $shouldBeVerifiedFields } = POs[0];
|
|
19
|
+
const verifiedBy = $verification_details === null || $verification_details === void 0 ? void 0 : $verification_details.verifier_id;
|
|
20
|
+
return (JsxPdf.createElement(JsxPdf.Fragment, null,
|
|
21
|
+
$shouldBeVerifiedFields && (JsxPdf.createElement(JsxPdf.Fragment, null,
|
|
22
|
+
JsxPdf.createElement("svg", { content: loadAsset(`${FILE_MAP[$badges.verified.code]}.svg`), width: width }),
|
|
23
|
+
JsxPdf.createElement("text", { alignment: "center" }, PO_VER_TEXT_MAP[$badges.verified.code]),
|
|
24
|
+
verifiedBy && (JsxPdf.createElement("text", { alignment: "center" }, $$("POVerificationBadge.verified-by", { verifiedBy }))))),
|
|
25
|
+
$badges.safeHarbour && (JsxPdf.createElement("columns", { columnGap: 10 },
|
|
26
|
+
JsxPdf.createElement("column", { width: width / 3 },
|
|
27
|
+
JsxPdf.createElement("svg", { content: loadAsset(`${FILE_MAP[$badges.safeHarbour.code
|
|
28
|
+
? POVerification.FullyVerified
|
|
29
|
+
: POVerification.VerifiedFalse]}.svg`), width: width / 3 })),
|
|
30
|
+
JsxPdf.createElement("column", { width: "auto" },
|
|
31
|
+
JsxPdf.createElement("text", { alignment: "center" }, $badges.safeHarbour.code
|
|
32
|
+
? $$("POVerificationBadge.safe-harbour-yes")
|
|
33
|
+
: $$("POVerificationBadge.safe-harbour-no")))))));
|
|
34
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AId } from "@raytio/types";
|
|
2
|
+
import type { PdfConfig } from "../types.js";
|
|
3
|
+
import type { EnvConfig } from "../../api/index.js";
|
|
4
|
+
import type { ProcessSubmissionOutput } from "../../public-methods/processSubmission.js";
|
|
5
|
+
export declare const Report: ({ data, files, config, aId, clientUrl, envConfig, }: {
|
|
6
|
+
data: ProcessSubmissionOutput["json"];
|
|
7
|
+
files: ProcessSubmissionOutput["files"];
|
|
8
|
+
config: PdfConfig;
|
|
9
|
+
aId: AId;
|
|
10
|
+
clientUrl: string;
|
|
11
|
+
envConfig: EnvConfig;
|
|
12
|
+
}) => JSX.Element;
|