@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,132 @@
|
|
|
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 { equals, mapObjIndexed, omit } from "ramda";
|
|
11
|
+
import { calculateScore, convertInstanceToRuleInput, decryptSharedData, getMissingDataForInstance, getSomeoneElsesRealVerifications, isScoreConfigValid, } from "@raytio/core";
|
|
12
|
+
import { FIELD_VER_TEXT_MAP, INSTANCE_FIELDS_TO_REMOVE, } from "../constants.js";
|
|
13
|
+
import { deepJsonToCsv, formatOutput, setupMaxcryptor, splitPOAndVers, } from "../helpers/index.js";
|
|
14
|
+
import { fetchAA, fetchEnvConfig, fetchInstanceData, getAllSchema, getFiles, signIn, updateInstanceData, } from "../api/index.js";
|
|
15
|
+
import { NULL_I_ID } from "../pdf/constants.js";
|
|
16
|
+
function decryptStage(log, config, envConfig, instanceId) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
log("Authenticating...");
|
|
19
|
+
const { apiToken, cognitoAttributes } = yield signIn(config, envConfig);
|
|
20
|
+
log("Initializing decryptor...");
|
|
21
|
+
const maxcryptor = yield setupMaxcryptor(config, cognitoAttributes);
|
|
22
|
+
log("Fetching instance (without keys or data)...");
|
|
23
|
+
const instanceWithoutData = yield fetchInstanceData(apiToken, envConfig, instanceId);
|
|
24
|
+
log("Fetching keys and data for instance...");
|
|
25
|
+
const apiResp = yield getMissingDataForInstance({
|
|
26
|
+
apiToken,
|
|
27
|
+
apiUrl: envConfig.api_url,
|
|
28
|
+
instanceWithoutData,
|
|
29
|
+
});
|
|
30
|
+
log("Decrypting submission details...");
|
|
31
|
+
const { instance, applicationDecryptor } = yield decryptSharedData({
|
|
32
|
+
apiToken,
|
|
33
|
+
apiUrl: envConfig.api_url,
|
|
34
|
+
instanceData: apiResp,
|
|
35
|
+
maxcryptor,
|
|
36
|
+
onCorruptedData: () => "🔒 Corrupted Data 🔒",
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
apiToken,
|
|
40
|
+
instance,
|
|
41
|
+
applicationDecryptor,
|
|
42
|
+
encryptedInstance: apiResp,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const log = verbose ? console.log : () => undefined;
|
|
49
|
+
try {
|
|
50
|
+
log("Fetching config...");
|
|
51
|
+
const envConfig = yield fetchEnvConfig(config.CLIENT_URL);
|
|
52
|
+
const { instance, apiToken, applicationDecryptor, encryptedInstance } = _supliedConfig ||
|
|
53
|
+
(yield decryptStage(log, config, envConfig, instanceId));
|
|
54
|
+
log("Checking verifications...");
|
|
55
|
+
const [profileObjects, verifications] = splitPOAndVers(instance.profile_objects);
|
|
56
|
+
const realVers = (_supliedConfig === null || _supliedConfig === void 0 ? void 0 : _supliedConfig.realVers) ||
|
|
57
|
+
(yield getSomeoneElsesRealVerifications({
|
|
58
|
+
aId: instance.aa_id,
|
|
59
|
+
apiUrl: envConfig.api_url,
|
|
60
|
+
profileObjects,
|
|
61
|
+
verifications,
|
|
62
|
+
}));
|
|
63
|
+
log("Fetching relevant schema...");
|
|
64
|
+
const allSchemas = yield getAllSchema(envConfig);
|
|
65
|
+
log("Fetching access application...");
|
|
66
|
+
const AA = instance.id === NULL_I_ID
|
|
67
|
+
? undefined
|
|
68
|
+
: yield fetchAA(apiToken, envConfig, instance.aa_id);
|
|
69
|
+
let score;
|
|
70
|
+
if (AA && isScoreConfigValid(AA.ruleset)) {
|
|
71
|
+
const ruleInputData = yield convertInstanceToRuleInput(instance.profile_objects, realVers, (schemaName) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const schema = allSchemas.find((x) => x.name === schemaName);
|
|
73
|
+
if (!schema) {
|
|
74
|
+
throw new Error(`Could not find schema “${schemaName}”`);
|
|
75
|
+
}
|
|
76
|
+
return schema;
|
|
77
|
+
}));
|
|
78
|
+
try {
|
|
79
|
+
// decrypt helper never uses a stored score. We always re-calculate it.
|
|
80
|
+
log("Calculating score...");
|
|
81
|
+
score = yield calculateScore(AA.ruleset, ruleInputData);
|
|
82
|
+
if (!equals(instance.score, score)) {
|
|
83
|
+
// the score we calculated is different to the one that's saved on the instance.
|
|
84
|
+
// So we save the new score.
|
|
85
|
+
log("Saving score to instance...");
|
|
86
|
+
// this can happen silently in the background, but we await it since so that we
|
|
87
|
+
// abort if this fails.
|
|
88
|
+
yield updateInstanceData(apiToken, envConfig, encryptedInstance.id, {
|
|
89
|
+
score,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (ex) {
|
|
94
|
+
log(`Score calculation failed (${ex})`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
log("No score rules configured on the AA.");
|
|
99
|
+
}
|
|
100
|
+
log("Fetching verification providers...");
|
|
101
|
+
const PODetails = yield formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig);
|
|
102
|
+
log("Fetching attached files...");
|
|
103
|
+
const files = yield getFiles(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
|
|
104
|
+
const instanceDataToPassOn = omit(INSTANCE_FIELDS_TO_REMOVE, instance);
|
|
105
|
+
// final outputs
|
|
106
|
+
const csv = deepJsonToCsv(Object.assign(Object.assign({}, instanceDataToPassOn), mapObjIndexed((POList) => POList.map((flatPO) => {
|
|
107
|
+
// this is a bit weird, but it prevents an even bigger breaking change for the csv format
|
|
108
|
+
const object = Object.entries(flatPO.$properties).flatMap(([fieldName, field]) => [
|
|
109
|
+
[fieldName, field.value],
|
|
110
|
+
[
|
|
111
|
+
`${fieldName}.verification`,
|
|
112
|
+
FIELD_VER_TEXT_MAP[field.verification],
|
|
113
|
+
],
|
|
114
|
+
]);
|
|
115
|
+
return Object.assign(Object.assign({}, flatPO), Object.fromEntries(object));
|
|
116
|
+
}), PODetails)));
|
|
117
|
+
log("Success!");
|
|
118
|
+
return {
|
|
119
|
+
json: Object.assign(Object.assign({}, instanceDataToPassOn), { score, profile_objects: PODetails }),
|
|
120
|
+
csv,
|
|
121
|
+
files,
|
|
122
|
+
a_id: applicationId,
|
|
123
|
+
client_url: config.CLIENT_URL,
|
|
124
|
+
envConfig,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
log("Processing submission failed:", error);
|
|
129
|
+
throw error; // pass on error
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 AWS from "aws-sdk";
|
|
11
|
+
function upload(s3, { bucketName, fileName, fileContent }) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
s3.upload({
|
|
15
|
+
Bucket: bucketName,
|
|
16
|
+
Key: fileName,
|
|
17
|
+
Body: fileContent,
|
|
18
|
+
}, (error, data) => {
|
|
19
|
+
if (error)
|
|
20
|
+
return reject(error);
|
|
21
|
+
console.log(`Uploaded ${data.Location}`);
|
|
22
|
+
return resolve(data);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export const saveToS3Bucket = () =>
|
|
28
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping -- deliberately to future proof the SDK for options
|
|
29
|
+
(input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
console.log("Uploading data to S3...");
|
|
31
|
+
const bucketName = process.env.S3_BUCKET;
|
|
32
|
+
if (!bucketName)
|
|
33
|
+
throw new Error("S3_BUCKET is not specified");
|
|
34
|
+
const s3 = new AWS.S3();
|
|
35
|
+
yield upload(s3, {
|
|
36
|
+
bucketName,
|
|
37
|
+
fileName: `${input.json.id}/${input.json.id}.csv`,
|
|
38
|
+
fileContent: input.csv,
|
|
39
|
+
});
|
|
40
|
+
yield upload(s3, {
|
|
41
|
+
bucketName,
|
|
42
|
+
fileName: `${input.json.id}/${input.json.id}.json`,
|
|
43
|
+
fileContent: JSON.stringify(input.json),
|
|
44
|
+
});
|
|
45
|
+
yield Promise.all(Object.entries(input.files).map(([nId, [dataUrl, fileExtension]]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
yield upload(s3, {
|
|
47
|
+
bucketName,
|
|
48
|
+
fileName: `${input.json.id}/${nId}.${fileExtension}`,
|
|
49
|
+
fileContent: Buffer.from(dataUrl.split(",")[1], "base64"),
|
|
50
|
+
});
|
|
51
|
+
})));
|
|
52
|
+
console.log("Finished uploading data to S3.");
|
|
53
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getDirname } from "../helpers/pathUtils.js";
|
|
4
|
+
export const packageDotJson = JSON.parse(readFileSync(join(getDirname(), "../../package.json"), "utf8"));
|
|
5
|
+
export const version = Object.entries({
|
|
6
|
+
LANG: process.env.PDF_LANGUAGE || "default",
|
|
7
|
+
N: process.version.slice(1),
|
|
8
|
+
DH: packageDotJson.version,
|
|
9
|
+
C: packageDotJson.dependencies["@raytio/core"].slice(1),
|
|
10
|
+
T: packageDotJson.dependencies["@raytio/types"].slice(1),
|
|
11
|
+
})
|
|
12
|
+
.map((kv) => kv.join("="))
|
|
13
|
+
.join(" ");
|