@raytio/decrypt-helper 5.1.3 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/package.json +32 -23
- package/CHANGELOG.md +0 -221
- package/dist/api/authedFetch.d.ts +0 -1
- package/dist/api/authedFetch.js +0 -32
- package/dist/api/fetchAA.d.ts +0 -3
- package/dist/api/fetchAA.js +0 -19
- package/dist/api/fetchEnvConfig.d.ts +0 -6
- package/dist/api/fetchEnvConfig.js +0 -39
- package/dist/api/fetchInstanceData.d.ts +0 -3
- package/dist/api/fetchInstanceData.js +0 -21
- package/dist/api/getFiles.d.ts +0 -4
- package/dist/api/getFiles.js +0 -82
- package/dist/api/getLookupOption.d.ts +0 -2
- package/dist/api/getLookupOption.js +0 -32
- package/dist/api/getSchema.d.ts +0 -3
- package/dist/api/getSchema.js +0 -31
- package/dist/api/index.d.ts +0 -9
- package/dist/api/index.js +0 -25
- package/dist/api/resolveVerificationDetails.d.ts +0 -9
- package/dist/api/resolveVerificationDetails.js +0 -35
- package/dist/api/signIn.d.ts +0 -7
- package/dist/api/signIn.js +0 -56
- package/dist/api/updateInstanceData.d.ts +0 -2
- package/dist/api/updateInstanceData.js +0 -19
- package/dist/configureEnv.d.ts +0 -1
- package/dist/configureEnv.js +0 -16
- package/dist/constants.d.ts +0 -23
- package/dist/constants.js +0 -45
- package/dist/helpers/file.d.ts +0 -13
- package/dist/helpers/file.js +0 -17
- package/dist/helpers/formatOutput.d.ts +0 -28
- package/dist/helpers/formatOutput.js +0 -92
- package/dist/helpers/index.d.ts +0 -6
- package/dist/helpers/index.js +0 -22
- package/dist/helpers/json2csv.d.ts +0 -2
- package/dist/helpers/json2csv.js +0 -24
- package/dist/helpers/lookup.d.ts +0 -2
- package/dist/helpers/lookup.js +0 -22
- package/dist/helpers/setupMaxcryptor.d.ts +0 -4
- package/dist/helpers/setupMaxcryptor.js +0 -28
- package/dist/helpers/splitPOAndVers.d.ts +0 -2
- package/dist/helpers/splitPOAndVers.js +0 -11
- package/dist/helpers/types.d.ts +0 -1
- package/dist/helpers/types.js +0 -9
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -16
- package/dist/locales/index.d.ts +0 -44
- package/dist/locales/index.js +0 -21
- package/dist/locales/translations/en.json +0 -33
- package/dist/pdf/components/FieldVerificationBadge.d.ts +0 -6
- package/dist/pdf/components/FieldVerificationBadge.js +0 -19
- package/dist/pdf/components/Images.d.ts +0 -6
- package/dist/pdf/components/Images.js +0 -19
- package/dist/pdf/components/InnerTableRows.d.ts +0 -11
- package/dist/pdf/components/InnerTableRows.js +0 -37
- package/dist/pdf/components/POVerificationBadge.d.ts +0 -8
- package/dist/pdf/components/POVerificationBadge.js +0 -41
- package/dist/pdf/components/Report.d.ts +0 -14
- package/dist/pdf/components/Report.js +0 -95
- package/dist/pdf/components/Subheader.d.ts +0 -2
- package/dist/pdf/components/Subheader.js +0 -28
- package/dist/pdf/components/Table.d.ts +0 -9
- package/dist/pdf/components/Table.js +0 -47
- package/dist/pdf/components/TableTitle.d.ts +0 -5
- package/dist/pdf/components/TableTitle.js +0 -17
- package/dist/pdf/components/ValidationDisplay.d.ts +0 -5
- package/dist/pdf/components/ValidationDisplay.js +0 -29
- package/dist/pdf/components/VerifyBox.d.ts +0 -9
- package/dist/pdf/components/VerifyBox.js +0 -16
- package/dist/pdf/components/pieChart.d.ts +0 -6
- package/dist/pdf/components/pieChart.js +0 -27
- package/dist/pdf/constants.d.ts +0 -2
- package/dist/pdf/constants.js +0 -11
- package/dist/pdf/helpers/general.d.ts +0 -8
- package/dist/pdf/helpers/general.js +0 -37
- package/dist/pdf/helpers/transform.d.ts +0 -4
- package/dist/pdf/helpers/transform.js +0 -39
- package/dist/pdf/style.d.ts +0 -10
- package/dist/pdf/style.js +0 -24
- package/dist/public-methods/generatePDF.d.ts +0 -4
- package/dist/public-methods/generatePDF.js +0 -62
- package/dist/public-methods/getAndValidateConfig.d.ts +0 -8
- package/dist/public-methods/getAndValidateConfig.js +0 -20
- package/dist/public-methods/processSubmission.d.ts +0 -48
- package/dist/public-methods/processSubmission.js +0 -124
- package/dist/public-methods/saveToS3Bucket.d.ts +0 -2
- package/dist/public-methods/saveToS3Bucket.js +0 -58
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transform = exports.IS_ARRAY_OF_OBJECTS = exports.IS_IMAGE = void 0;
|
|
4
|
-
const core_1 = require("@raytio/core");
|
|
5
|
-
const locales_1 = require("../../locales");
|
|
6
|
-
const general_1 = require("./general");
|
|
7
|
-
exports.IS_IMAGE = Symbol.for("image");
|
|
8
|
-
exports.IS_ARRAY_OF_OBJECTS = Symbol.for("ArrayOfObjects");
|
|
9
|
-
function transform(key, value, pdfConfig, imageFieldNames) {
|
|
10
|
-
// value is possible to be false if type boolean
|
|
11
|
-
if (value === undefined) {
|
|
12
|
-
return (0, locales_1.$$)("field.undefined");
|
|
13
|
-
}
|
|
14
|
-
if (typeof value === "boolean") {
|
|
15
|
-
return value ? (0, locales_1.$$)("field.boolean.yes") : (0, locales_1.$$)("field.boolean.no");
|
|
16
|
-
}
|
|
17
|
-
if (imageFieldNames === null || imageFieldNames === void 0 ? void 0 : imageFieldNames.includes(key)) {
|
|
18
|
-
return exports.IS_IMAGE;
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(value)) {
|
|
21
|
-
if (value.every((v) => typeof v === "object")) {
|
|
22
|
-
return exports.IS_ARRAY_OF_OBJECTS;
|
|
23
|
-
}
|
|
24
|
-
return value.join(", ");
|
|
25
|
-
}
|
|
26
|
-
if (typeof value !== "string") {
|
|
27
|
-
return `${value}`;
|
|
28
|
-
}
|
|
29
|
-
switch (key) {
|
|
30
|
-
case "start_date":
|
|
31
|
-
case "end_date": {
|
|
32
|
-
return (0, general_1.formatDate)((0, core_1.repairDate)(value), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
|
|
33
|
-
}
|
|
34
|
-
default: {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.transform = transform;
|
package/dist/pdf/style.d.ts
DELETED
package/dist/pdf/style.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fonts = exports.classes = void 0;
|
|
4
|
-
const general_1 = require("./helpers/general");
|
|
5
|
-
exports.classes = {
|
|
6
|
-
header: {
|
|
7
|
-
fontSize: 18,
|
|
8
|
-
},
|
|
9
|
-
listing: {
|
|
10
|
-
fontSize: 10,
|
|
11
|
-
color: "#333",
|
|
12
|
-
},
|
|
13
|
-
// [l, t, r, b]
|
|
14
|
-
marginBottom: { margin: [0, 0, 0, 10] },
|
|
15
|
-
marginY: { margin: [0, 15, 0, 15] },
|
|
16
|
-
};
|
|
17
|
-
exports.fonts = {
|
|
18
|
-
Lato: {
|
|
19
|
-
normal: (0, general_1.asset)("Lato-Light.ttf"),
|
|
20
|
-
bold: (0, general_1.asset)("Lato-Bold.ttf"),
|
|
21
|
-
italics: (0, general_1.asset)("Lato-LightItalic.ttf"),
|
|
22
|
-
bolditalics: (0, general_1.asset)("Lato-BoldItalic.ttf"),
|
|
23
|
-
},
|
|
24
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { TDocumentDefinitions } from "pdfmake/interfaces";
|
|
2
|
-
import { ProcessSubmissionOutput } from "./processSubmission";
|
|
3
|
-
export declare function generatePdfJson(data: ProcessSubmissionOutput, DATE_FORMAT: string, TIMEZONE: string, version: string): TDocumentDefinitions;
|
|
4
|
-
export declare const generatePDF: () => (data: ProcessSubmissionOutput) => Promise<ProcessSubmissionOutput>;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.generatePDF = exports.generatePdfJson = void 0;
|
|
16
|
-
const pdfmake_1 = __importDefault(require("pdfmake"));
|
|
17
|
-
const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
|
|
18
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
19
|
-
const fs_1 = require("fs");
|
|
20
|
-
const path_1 = require("path");
|
|
21
|
-
const locales_1 = require("../locales");
|
|
22
|
-
const Report_1 = require("../pdf/components/Report");
|
|
23
|
-
const style_1 = require("../pdf/style");
|
|
24
|
-
function generatePdfJson(data, DATE_FORMAT, TIMEZONE, 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 }));
|
|
26
|
-
}
|
|
27
|
-
exports.generatePdfJson = generatePdfJson;
|
|
28
|
-
const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
console.log("Generating PDF Report...");
|
|
30
|
-
const { DATE_FORMAT = "en-nz", TIMEZONE = "Pacific/Auckland" } = process.env;
|
|
31
|
-
const pkg = JSON.parse(yield fs_1.promises.readFile((0, path_1.join)(__dirname, "../../package.json"), "utf8"));
|
|
32
|
-
if (data.envConfig.logo_url) {
|
|
33
|
-
// there is a white labelling URL, so fetch it and write it to disk, overriding the default logo
|
|
34
|
-
const arrayBuf = yield (0, node_fetch_1.default)(data.envConfig.logo_url).then((r) => r.arrayBuffer());
|
|
35
|
-
yield fs_1.promises.writeFile((0, path_1.join)(__dirname, "../../assets/custom-logo.png"), Buffer.from(arrayBuf));
|
|
36
|
-
}
|
|
37
|
-
const customLang = process.env.PDF_LANGUAGE;
|
|
38
|
-
if (customLang) {
|
|
39
|
-
if ((0, locales_1.isValidLocale)(customLang)) {
|
|
40
|
-
global.lang = customLang;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
console.warn(`The specified PDF_LANGUAGE is language is invalid (${customLang})`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const subject = `node:${process.version} pkg:${pkg.version} lang:${global.lang}`;
|
|
47
|
-
return new Promise((resolve) => {
|
|
48
|
-
const printer = new pdfmake_1.default(style_1.fonts);
|
|
49
|
-
const pdfDoc = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE, subject));
|
|
50
|
-
const chunks = [];
|
|
51
|
-
pdfDoc.on("data", (chunk) => chunks.push(chunk));
|
|
52
|
-
pdfDoc.on("end", () => {
|
|
53
|
-
const final = Buffer.concat(chunks);
|
|
54
|
-
const dataUrl = `data:application/pdf;base64,${final.toString("base64")}`;
|
|
55
|
-
resolve(Object.assign(Object.assign({}, data), { files: Object.assign(Object.assign({}, data.files), {
|
|
56
|
-
// do not change name, will be a breaking change
|
|
57
|
-
[data.json.i_id]: [dataUrl, "pdf"] }) }));
|
|
58
|
-
});
|
|
59
|
-
pdfDoc.end();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
exports.generatePDF = generatePDF;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Config } from "../constants";
|
|
2
|
-
/**
|
|
3
|
-
* This helper is designed for environments where the configuration
|
|
4
|
-
* options are in the environment variables, such as AWS lambda.
|
|
5
|
-
* It extracts the relevant ENV variables and throws an error if
|
|
6
|
-
* any are missing.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getAndValidateConfig(): Config;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAndValidateConfig = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
5
|
-
/**
|
|
6
|
-
* This helper is designed for environments where the configuration
|
|
7
|
-
* options are in the environment variables, such as AWS lambda.
|
|
8
|
-
* It extracts the relevant ENV variables and throws an error if
|
|
9
|
-
* any are missing.
|
|
10
|
-
*/
|
|
11
|
-
function getAndValidateConfig() {
|
|
12
|
-
const CONFIG = constants_1.ENV_VARIABLES.reduce((acc, name) => {
|
|
13
|
-
const value = process.env[name];
|
|
14
|
-
if (!value)
|
|
15
|
-
throw new Error(`${name} is not configured`);
|
|
16
|
-
return Object.assign(Object.assign({}, acc), { [name]: value });
|
|
17
|
-
}, {});
|
|
18
|
-
return CONFIG;
|
|
19
|
-
}
|
|
20
|
-
exports.getAndValidateConfig = getAndValidateConfig;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { AId, IId, Instance } from "@raytio/types";
|
|
2
|
-
import { Config, InstanceDataToPassOn } from "../constants";
|
|
3
|
-
import { FlatPO } from "../helpers";
|
|
4
|
-
import { EnvConfig } from "../api";
|
|
5
|
-
import { ApplicationEncryptorLike } from "../types";
|
|
6
|
-
declare type DecryptData = {
|
|
7
|
-
apiToken: string;
|
|
8
|
-
instance: Instance;
|
|
9
|
-
encryptedInstance: Instance;
|
|
10
|
-
applicationDecryptor: ApplicationEncryptorLike;
|
|
11
|
-
};
|
|
12
|
-
export interface ProcessSubmissionInput {
|
|
13
|
-
/** The a_id of the application */
|
|
14
|
-
applicationId: AId;
|
|
15
|
-
/** The i_id of this submission */
|
|
16
|
-
instanceId: IId;
|
|
17
|
-
/** whether to enable extra logging. Default = false */
|
|
18
|
-
verbose?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* the configuration options. You can extract these from the environment
|
|
21
|
-
* variables by using @see getAndValidateConfig
|
|
22
|
-
*/
|
|
23
|
-
config: Config;
|
|
24
|
-
/** You can optionally supply Instance data and an API token - for Raytio internal use */
|
|
25
|
-
_supliedConfig?: DecryptData;
|
|
26
|
-
}
|
|
27
|
-
export interface ProcessSubmissionOutput {
|
|
28
|
-
/** details of the submission, included the decrypted profile objects */
|
|
29
|
-
json: InstanceDataToPassOn & {
|
|
30
|
-
profile_objects: {
|
|
31
|
-
[schemaName: string]: FlatPO[];
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
/** A string of a CSV file containing the same data as in `json` */
|
|
35
|
-
csv: string;
|
|
36
|
-
/** an object of files that were attached to the submission, such as images */
|
|
37
|
-
files: {
|
|
38
|
-
[nId: string]: [dataUrl: string, fileExtension: string];
|
|
39
|
-
};
|
|
40
|
-
/** the a_id is passed on */
|
|
41
|
-
a_id: AId;
|
|
42
|
-
/** passed down so that pdf generation has access to it */
|
|
43
|
-
client_url: string;
|
|
44
|
-
/** passed down so that pdf generation has access to it */
|
|
45
|
-
envConfig: EnvConfig;
|
|
46
|
-
}
|
|
47
|
-
export declare function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }: ProcessSubmissionInput): Promise<ProcessSubmissionOutput>;
|
|
48
|
-
export {};
|
|
@@ -1,124 +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
|
-
exports.processSubmission = void 0;
|
|
13
|
-
const ramda_1 = require("ramda");
|
|
14
|
-
const core_1 = require("@raytio/core");
|
|
15
|
-
const constants_1 = require("../constants");
|
|
16
|
-
const helpers_1 = require("../helpers");
|
|
17
|
-
const api_1 = require("../api");
|
|
18
|
-
function decryptStage(log, config, envConfig, instanceId) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
log("Authenticating...");
|
|
21
|
-
const { apiToken, cognitoAttributes } = yield (0, api_1.signIn)(config, envConfig);
|
|
22
|
-
log("Initializing decryptor...");
|
|
23
|
-
const maxcryptor = yield (0, helpers_1.setupMaxcryptor)(config, cognitoAttributes);
|
|
24
|
-
log("Fetching submission details...");
|
|
25
|
-
const apiResp = yield (0, api_1.fetchInstanceData)(apiToken, envConfig, instanceId);
|
|
26
|
-
log("Decrypting submission details...");
|
|
27
|
-
const { instance, applicationDecryptor } = yield (0, core_1.decryptSharedData)({
|
|
28
|
-
apiToken,
|
|
29
|
-
apiUrl: envConfig.api_url,
|
|
30
|
-
instanceData: apiResp,
|
|
31
|
-
maxcryptor,
|
|
32
|
-
onCorruptedData: () => "🔒 Corrupted Data 🔒",
|
|
33
|
-
});
|
|
34
|
-
return {
|
|
35
|
-
apiToken,
|
|
36
|
-
instance,
|
|
37
|
-
applicationDecryptor,
|
|
38
|
-
encryptedInstance: apiResp,
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const log = verbose ? console.log : () => undefined;
|
|
45
|
-
try {
|
|
46
|
-
log("Fetching config...");
|
|
47
|
-
const envConfig = yield (0, api_1.fetchEnvConfig)(config.CLIENT_URL);
|
|
48
|
-
const { instance, apiToken, applicationDecryptor, encryptedInstance } = _supliedConfig ||
|
|
49
|
-
(yield decryptStage(log, config, envConfig, instanceId));
|
|
50
|
-
log("Checking verifications...");
|
|
51
|
-
const [profileObjects, verifications] = (0, helpers_1.splitPOAndVers)(instance.profile_objects);
|
|
52
|
-
const realVers = yield (0, core_1.getSomeoneElsesRealVerifications)({
|
|
53
|
-
aId: instance.a_id,
|
|
54
|
-
apiUrl: envConfig.api_url,
|
|
55
|
-
profileObjects,
|
|
56
|
-
verifications,
|
|
57
|
-
});
|
|
58
|
-
log("Fetching relevant schema...");
|
|
59
|
-
const schemaNames = profileObjects.map((PO) => {
|
|
60
|
-
const schemaName = (0, core_1.findSchemaLabel)(PO.labels);
|
|
61
|
-
if (!schemaName)
|
|
62
|
-
throw new Error("Submission contains invalid objects");
|
|
63
|
-
return schemaName;
|
|
64
|
-
});
|
|
65
|
-
const allSchemas = yield Promise.all((0, ramda_1.uniq)(schemaNames).map((name) => (0, api_1.getSchema)(envConfig, name)));
|
|
66
|
-
log("Fetching access application...");
|
|
67
|
-
const AA = yield (0, api_1.fetchAA)(apiToken, envConfig, instance.a_id);
|
|
68
|
-
let score;
|
|
69
|
-
if ((0, core_1.isScoreConfigValid)(AA.ruleset)) {
|
|
70
|
-
const ruleInputData = yield (0, core_1.convertInstanceToRuleInput)(instance, realVers, (schemaName) => (0, api_1.getSchema)(envConfig, schemaName));
|
|
71
|
-
try {
|
|
72
|
-
// decrypt helper never uses a stored score. We always re-calculate it.
|
|
73
|
-
log("Calculating score...");
|
|
74
|
-
score = yield (0, core_1.calculateScore)(AA.ruleset, ruleInputData);
|
|
75
|
-
if (!(0, ramda_1.equals)(instance.score, score)) {
|
|
76
|
-
// the score we calculated is different to the one that's saved on the instance.
|
|
77
|
-
// So we save the new score.
|
|
78
|
-
log("Saving score to instance...");
|
|
79
|
-
// this can happen silently in the background, but we await it since so that we
|
|
80
|
-
// abort if this fails.
|
|
81
|
-
yield (0, api_1.updateInstanceData)(apiToken, Object.assign(Object.assign({}, encryptedInstance), { score }));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (ex) {
|
|
85
|
-
log(`Score calculation failed (${ex})`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
log("No score rules configured on the AA.");
|
|
90
|
-
}
|
|
91
|
-
log("Fetching verification providers...");
|
|
92
|
-
const PODetails = yield (0, helpers_1.formatOutput)(profileObjects, allSchemas, realVers, apiToken, envConfig);
|
|
93
|
-
log("Fetching attached files...");
|
|
94
|
-
const files = yield (0, api_1.getFiles)(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
|
|
95
|
-
const instanceDataToPassOn = (0, ramda_1.omit)(constants_1.INSTANCE_FIELDS_TO_REMOVE, instance);
|
|
96
|
-
// final outputs
|
|
97
|
-
const csv = (0, helpers_1.deepJsonToCsv)(Object.assign(Object.assign({}, instanceDataToPassOn), (0, ramda_1.mapObjIndexed)((POList) => POList.map((flatPO) => {
|
|
98
|
-
// this is a bit weird, but it prevents an even bigger breaking change for the csv format
|
|
99
|
-
const obj = Object.entries(flatPO.$properties).flatMap(([fieldName, field]) => [
|
|
100
|
-
[fieldName, field.value],
|
|
101
|
-
[
|
|
102
|
-
`${fieldName}.verification`,
|
|
103
|
-
constants_1.FIELD_VER_TEXT_MAP[field.verification],
|
|
104
|
-
],
|
|
105
|
-
]);
|
|
106
|
-
return Object.assign(Object.assign({}, flatPO), Object.fromEntries(obj));
|
|
107
|
-
}), PODetails)));
|
|
108
|
-
log("Success!");
|
|
109
|
-
return {
|
|
110
|
-
json: Object.assign(Object.assign({}, instanceDataToPassOn), { score, profile_objects: PODetails }),
|
|
111
|
-
csv,
|
|
112
|
-
files,
|
|
113
|
-
a_id: applicationId,
|
|
114
|
-
client_url: config.CLIENT_URL,
|
|
115
|
-
envConfig,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
catch (err) {
|
|
119
|
-
log("Processing submission failed:", err);
|
|
120
|
-
throw err; // pass on error
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
exports.processSubmission = processSubmission;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.saveToS3Bucket = void 0;
|
|
16
|
-
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
17
|
-
function upload(s3, { bucketName, fileName, fileContent }) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
s3.upload({
|
|
21
|
-
Bucket: bucketName,
|
|
22
|
-
Key: fileName,
|
|
23
|
-
Body: fileContent,
|
|
24
|
-
}, (err, data) => {
|
|
25
|
-
if (err)
|
|
26
|
-
return reject(err);
|
|
27
|
-
console.log(`Uploaded ${data.Location}`);
|
|
28
|
-
return resolve(data);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
const saveToS3Bucket = () => (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
console.log("Uploading data to S3...");
|
|
35
|
-
const bucketName = process.env.S3_BUCKET;
|
|
36
|
-
if (!bucketName)
|
|
37
|
-
throw new Error("S3_BUCKET is not specified");
|
|
38
|
-
const s3 = new aws_sdk_1.default.S3();
|
|
39
|
-
yield upload(s3, {
|
|
40
|
-
bucketName,
|
|
41
|
-
fileName: `${input.json.i_id}/${input.json.i_id}.csv`,
|
|
42
|
-
fileContent: input.csv,
|
|
43
|
-
});
|
|
44
|
-
yield upload(s3, {
|
|
45
|
-
bucketName,
|
|
46
|
-
fileName: `${input.json.i_id}/${input.json.i_id}.json`,
|
|
47
|
-
fileContent: JSON.stringify(input.json),
|
|
48
|
-
});
|
|
49
|
-
yield Promise.all(Object.entries(input.files).map(([nId, [dataUrl, fileExtension]]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
yield upload(s3, {
|
|
51
|
-
bucketName,
|
|
52
|
-
fileName: `${input.json.i_id}/${nId}.${fileExtension}`,
|
|
53
|
-
fileContent: Buffer.from(dataUrl.split(",")[1], "base64"),
|
|
54
|
-
});
|
|
55
|
-
})));
|
|
56
|
-
console.log("Finished uploading data to S3.");
|
|
57
|
-
});
|
|
58
|
-
exports.saveToS3Bucket = saveToS3Bucket;
|