@raytio/decrypt-helper 6.2.0 → 6.3.1

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.
Files changed (83) hide show
  1. package/README.md +2 -2
  2. package/dist/api/authedFetch.js +1 -5
  3. package/dist/api/fetchAA.d.ts +2 -2
  4. package/dist/api/fetchAA.js +3 -7
  5. package/dist/api/fetchEnvConfig.js +2 -6
  6. package/dist/api/fetchInstanceData.d.ts +3 -3
  7. package/dist/api/fetchInstanceData.js +3 -8
  8. package/dist/api/getFiles.d.ts +2 -2
  9. package/dist/api/getFiles.js +59 -26
  10. package/dist/api/getLookupOption.d.ts +1 -1
  11. package/dist/api/getLookupOption.js +3 -7
  12. package/dist/api/getSchema.d.ts +1 -1
  13. package/dist/api/getSchema.js +5 -9
  14. package/dist/api/index.d.ts +9 -9
  15. package/dist/api/index.js +9 -25
  16. package/dist/api/resolveVerificationDetails.d.ts +1 -1
  17. package/dist/api/resolveVerificationDetails.js +2 -7
  18. package/dist/api/signIn.d.ts +2 -2
  19. package/dist/api/signIn.js +10 -14
  20. package/dist/api/updateInstanceData.d.ts +7 -2
  21. package/dist/api/updateInstanceData.js +7 -7
  22. package/dist/api/uploadToObjectStore.d.ts +1 -1
  23. package/dist/api/uploadToObjectStore.js +3 -7
  24. package/dist/api/videoToImage.d.ts +1 -1
  25. package/dist/api/videoToImage.js +5 -9
  26. package/dist/configureEnv.js +17 -28
  27. package/dist/constants.d.ts +3 -3
  28. package/dist/constants.js +20 -23
  29. package/dist/helpers/file.d.ts +5 -1
  30. package/dist/helpers/file.js +8 -9
  31. package/dist/helpers/formatOutput.d.ts +2 -2
  32. package/dist/helpers/formatOutput.js +24 -28
  33. package/dist/helpers/index.d.ts +6 -6
  34. package/dist/helpers/index.js +6 -22
  35. package/dist/helpers/json2csv.js +11 -15
  36. package/dist/helpers/lookup.d.ts +1 -1
  37. package/dist/helpers/lookup.js +16 -7
  38. package/dist/helpers/pathUtils.d.ts +1 -0
  39. package/dist/helpers/pathUtils.js +6 -0
  40. package/dist/helpers/setupMaxcryptor.d.ts +3 -3
  41. package/dist/helpers/setupMaxcryptor.js +9 -12
  42. package/dist/helpers/splitPOAndVers.js +4 -8
  43. package/dist/helpers/types.js +1 -5
  44. package/dist/index.d.ts +7 -7
  45. package/dist/index.js +7 -16
  46. package/dist/locales/index.js +4 -12
  47. package/dist/pdf/components/FieldVerificationBadge.d.ts +0 -1
  48. package/dist/pdf/components/FieldVerificationBadge.js +8 -15
  49. package/dist/pdf/components/Images.d.ts +1 -2
  50. package/dist/pdf/components/Images.js +7 -14
  51. package/dist/pdf/components/InnerTableRows.d.ts +2 -3
  52. package/dist/pdf/components/InnerTableRows.js +19 -26
  53. package/dist/pdf/components/POVerificationBadge.d.ts +1 -2
  54. package/dist/pdf/components/POVerificationBadge.js +28 -35
  55. package/dist/pdf/components/Report.d.ts +3 -4
  56. package/dist/pdf/components/Report.js +61 -68
  57. package/dist/pdf/components/Subheader.d.ts +0 -1
  58. package/dist/pdf/components/Subheader.js +20 -27
  59. package/dist/pdf/components/Table.d.ts +3 -4
  60. package/dist/pdf/components/Table.js +21 -28
  61. package/dist/pdf/components/TableTitle.d.ts +1 -2
  62. package/dist/pdf/components/TableTitle.js +5 -12
  63. package/dist/pdf/components/ValidationDisplay.d.ts +1 -2
  64. package/dist/pdf/components/ValidationDisplay.js +10 -17
  65. package/dist/pdf/components/VerifyBox.d.ts +0 -1
  66. package/dist/pdf/components/VerifyBox.js +9 -16
  67. package/dist/pdf/components/pieChart.js +1 -5
  68. package/dist/pdf/constants.js +8 -11
  69. package/dist/pdf/helpers/general.js +12 -18
  70. package/dist/pdf/helpers/transform.d.ts +1 -1
  71. package/dist/pdf/helpers/transform.js +11 -15
  72. package/dist/pdf/style.d.ts +1 -1
  73. package/dist/pdf/style.js +7 -10
  74. package/dist/public-methods/generatePDF.d.ts +2 -2
  75. package/dist/public-methods/generatePDF.js +15 -22
  76. package/dist/public-methods/getAndValidateConfig.d.ts +1 -1
  77. package/dist/public-methods/getAndValidateConfig.js +3 -7
  78. package/dist/public-methods/processSubmission.d.ts +4 -4
  79. package/dist/public-methods/processSubmission.js +37 -33
  80. package/dist/public-methods/saveToS3Bucket.d.ts +1 -1
  81. package/dist/public-methods/saveToS3Bucket.js +6 -13
  82. package/dist/public-methods/version.js +8 -10
  83. package/package.json +36 -65
@@ -1,29 +1,22 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ValidationDisplay = void 0;
7
- const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
- const locales_1 = require("../../locales");
9
- const pieChart_1 = require("./pieChart");
10
- const helpers_1 = require("../../helpers");
1
+ import JsxPdf from "jsx-pdf";
2
+ import { $$ } from "../../locales/index.js";
3
+ import { assertSafeProperty } from "../../helpers/index.js";
4
+ import { pieChart } from "./pieChart.js";
11
5
  const SEVERITY_COLOURS = {
12
6
  low: "#2e8bc0",
13
7
  medium: "#ff9800",
14
8
  high: "#fb7171",
15
9
  };
16
- const ValidationDisplay = ({ value, }) => {
10
+ export const ValidationDisplay = ({ value, }) => {
17
11
  const colour = value.score > 0.5 ? "#c2d887" : "#fb7171";
18
- return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
19
- jsx_pdf_1.default.createElement("svg", { content: (0, pieChart_1.pieChart)(colour, value.score * 100), width: 50 }),
20
- (0, locales_1.$$)("ValidationDisplay.text", { n: value.score * 10 }),
12
+ return (JsxPdf.createElement(JsxPdf.Fragment, null,
13
+ JsxPdf.createElement("svg", { content: pieChart(colour, value.score * 100), width: 50 }),
14
+ $$("ValidationDisplay.text", { n: value.score * 10 }),
21
15
  Object.values(value.breakdown)
22
16
  .filter((x) => x.severity && x.reason)
23
17
  .map((x) => {
24
18
  const key = x.severity;
25
- (0, helpers_1.assertSafeProperty)(key);
26
- return jsx_pdf_1.default.createElement("text", { color: SEVERITY_COLOURS[key] }, x.reason);
19
+ assertSafeProperty(key);
20
+ return JsxPdf.createElement("text", { color: SEVERITY_COLOURS[key] }, x.reason);
27
21
  })));
28
22
  };
29
- exports.ValidationDisplay = ValidationDisplay;
@@ -1,4 +1,3 @@
1
- /// <reference types="jsx-pdf" />
2
1
  import type { AId, IId } from "@raytio/types";
3
2
  type Props = {
4
3
  aId: AId;
@@ -1,19 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VerifyBox = void 0;
7
- const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
- const locales_1 = require("../../locales");
9
- const constants_1 = require("../constants");
10
- const VerifyBox = ({ aId, iId, clientUrl }) => {
11
- if (iId === constants_1.NULL_I_ID)
1
+ import JsxPdf from "jsx-pdf";
2
+ import { $$ } from "../../locales/index.js";
3
+ import { NULL_I_ID } from "../constants.js";
4
+ export const VerifyBox = ({ aId, iId, clientUrl }) => {
5
+ if (iId === NULL_I_ID)
12
6
  return null;
13
7
  const url = `${clientUrl}/apps/s/${aId}/i/${iId}`;
14
- return (jsx_pdf_1.default.createElement("stack", { alignment: "center" },
15
- jsx_pdf_1.default.createElement("text", { link: url }, (0, locales_1.$$)("VerifyBox.text")),
16
- jsx_pdf_1.default.createElement("qr", { content: url, fit: 150 }),
17
- jsx_pdf_1.default.createElement("text", { color: "#1e90ff", fontSize: 9, link: url, alignment: "left" }, url)));
8
+ return (JsxPdf.createElement("stack", { alignment: "center" },
9
+ JsxPdf.createElement("text", { link: url }, $$("VerifyBox.text")),
10
+ JsxPdf.createElement("qr", { content: url, fit: 150 }),
11
+ JsxPdf.createElement("text", { color: "#1e90ff", fontSize: 9, link: url, alignment: "left" }, url)));
18
12
  };
19
- exports.VerifyBox = VerifyBox;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pieChart = void 0;
4
1
  /**
5
2
  * A semi-cirle pie chart
6
3
  * (!) generates a SVG string, not a JSX component.
7
4
  * @param percentage a number from 0 to 100
8
5
  */
9
- function pieChart(colour, percentage) {
6
+ export function pieChart(colour, percentage) {
10
7
  return `
11
8
  <svg height="70" width="140" viewBox="0 -5 20 15">
12
9
  <circle r="10" cx="10" cy="10" fill="bisque" />
@@ -24,4 +21,3 @@ function pieChart(colour, percentage) {
24
21
  </svg>
25
22
  `;
26
23
  }
27
- exports.pieChart = pieChart;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUBMISSION_DATA = exports.NULL_I_ID = void 0;
4
- const locales_1 = require("../locales");
5
- exports.NULL_I_ID = "00000000-0000-0000-0000-000000000000";
6
- exports.SUBMISSION_DATA = {
7
- confirmation_code: (0, locales_1.$$)("constants.confirmation_code"),
8
- i_id: (0, locales_1.$$)("constants.i_id"),
9
- reference: (0, locales_1.$$)("constants.reference"),
10
- start_date: (0, locales_1.$$)("constants.start_date"),
11
- end_date: (0, locales_1.$$)("constants.end_date"),
1
+ import { $$ } from "../locales/index.js";
2
+ export const NULL_I_ID = "00000000-0000-0000-0000-000000000000";
3
+ export const SUBMISSION_DATA = {
4
+ confirmation_code: $$("constants.confirmation_code"),
5
+ id: $$("constants.i_id"),
6
+ reference: $$("constants.reference"),
7
+ start_date: $$("constants.start_date"),
8
+ end_date: $$("constants.end_date"),
12
9
  };
@@ -1,32 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatDate = exports.verifyColour = exports.loadAsset = exports.asset = void 0;
4
- const node_fs_1 = require("node:fs");
5
- const node_path_1 = require("node:path");
6
- const types_1 = require("@raytio/types");
7
- const asset = (name) => {
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { FieldVerification, POVerification } from "@raytio/types";
4
+ import { getDirname } from "../../helpers/pathUtils.js";
5
+ export const asset = (name) => {
8
6
  if (/[^.A-Z_a-z-]/.test(name) || name.includes("..")) {
9
7
  throw new Error("Invalid asset name");
10
8
  }
11
- return (0, node_path_1.join)(__dirname, "../../../assets/", name);
9
+ return join(getDirname(), "./../../assets/", name);
12
10
  };
13
- exports.asset = asset;
14
- const loadAsset = (name) => (0, node_fs_1.readFileSync)((0, exports.asset)(name), { encoding: "utf8" });
15
- exports.loadAsset = loadAsset;
16
- const verifyColour = (x) => {
17
- if (x === types_1.FieldVerification.Verified)
11
+ export const loadAsset = (name) => readFileSync(asset(name), { encoding: "utf8" });
12
+ export const verifyColour = (x) => {
13
+ if (x === FieldVerification.Verified)
18
14
  return "#12130e";
19
- if (x === types_1.FieldVerification.VerifiedFalse ||
20
- x === types_1.POVerification.VerifiedFalse) {
15
+ if (x === FieldVerification.VerifiedFalse ||
16
+ x === POVerification.VerifiedFalse) {
21
17
  return "#fb7171";
22
18
  }
23
19
  return "#000";
24
20
  };
25
- exports.verifyColour = verifyColour;
26
21
  /**
27
22
  * Produces a date with a long month
28
23
  */
29
- const formatDate = (d, locale, timeZone) => new Intl.DateTimeFormat(locale, {
24
+ export const formatDate = (d, locale, timeZone) => new Intl.DateTimeFormat(locale, {
30
25
  day: "2-digit",
31
26
  month: "long",
32
27
  year: "numeric",
@@ -34,4 +29,3 @@ const formatDate = (d, locale, timeZone) => new Intl.DateTimeFormat(locale, {
34
29
  minute: "numeric",
35
30
  timeZone,
36
31
  }).format(d);
37
- exports.formatDate = formatDate;
@@ -1,4 +1,4 @@
1
- import { PdfConfig } from "../types";
1
+ import type { PdfConfig } from "../types";
2
2
  export declare const IS_IMAGE: unique symbol;
3
3
  export declare const IS_ARRAY_OF_OBJECTS: unique symbol;
4
4
  export declare function transform(key: string, value: unknown, pdfConfig: PdfConfig, imageFieldNames?: string[]): string | typeof IS_IMAGE | typeof IS_ARRAY_OF_OBJECTS;
@@ -1,25 +1,22 @@
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) {
1
+ import { repairDate } from "@raytio/core";
2
+ import { $$ } from "../../locales/index.js";
3
+ import { formatDate } from "./general.js";
4
+ export const IS_IMAGE = Symbol.for("image");
5
+ export const IS_ARRAY_OF_OBJECTS = Symbol.for("ArrayOfObjects");
6
+ export function transform(key, value, pdfConfig, imageFieldNames) {
10
7
  // value is possible to be false if type boolean
11
8
  if (value === undefined) {
12
- return (0, locales_1.$$)("field.undefined");
9
+ return $$("field.undefined");
13
10
  }
14
11
  if (typeof value === "boolean") {
15
- return value ? (0, locales_1.$$)("field.boolean.yes") : (0, locales_1.$$)("field.boolean.no");
12
+ return value ? $$("field.boolean.yes") : $$("field.boolean.no");
16
13
  }
17
14
  if (imageFieldNames === null || imageFieldNames === void 0 ? void 0 : imageFieldNames.includes(key)) {
18
- return exports.IS_IMAGE;
15
+ return IS_IMAGE;
19
16
  }
20
17
  if (Array.isArray(value)) {
21
18
  if (value.every((v) => typeof v === "object")) {
22
- return exports.IS_ARRAY_OF_OBJECTS;
19
+ return IS_ARRAY_OF_OBJECTS;
23
20
  }
24
21
  return value.join(", ");
25
22
  }
@@ -29,11 +26,10 @@ function transform(key, value, pdfConfig, imageFieldNames) {
29
26
  switch (key) {
30
27
  case "start_date":
31
28
  case "end_date": {
32
- return (0, general_1.formatDate)((0, core_1.repairDate)(value), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
29
+ return formatDate(repairDate(value), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
33
30
  }
34
31
  default: {
35
32
  return value;
36
33
  }
37
34
  }
38
35
  }
39
- exports.transform = transform;
@@ -1,4 +1,4 @@
1
- import { StyleDictionary } from "pdfmake/interfaces";
1
+ import type { StyleDictionary } from "pdfmake/interfaces";
2
2
  export declare const classes: StyleDictionary;
3
3
  export declare const fonts: {
4
4
  Lato: {
package/dist/pdf/style.js CHANGED
@@ -1,8 +1,5 @@
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 = {
1
+ import { asset } from "./helpers/general.js";
2
+ export const classes = {
6
3
  header: {
7
4
  fontSize: 18,
8
5
  },
@@ -14,11 +11,11 @@ exports.classes = {
14
11
  marginBottom: { margin: [0, 0, 0, 10] },
15
12
  marginY: { margin: [0, 15, 0, 15] },
16
13
  };
17
- exports.fonts = {
14
+ export const fonts = {
18
15
  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"),
16
+ normal: asset("Lato-Light.ttf"),
17
+ bold: asset("Lato-Bold.ttf"),
18
+ italics: asset("Lato-LightItalic.ttf"),
19
+ bolditalics: asset("Lato-BoldItalic.ttf"),
23
20
  },
24
21
  };
@@ -1,4 +1,4 @@
1
- import { TDocumentDefinitions } from "pdfmake/interfaces";
2
- import { ProcessSubmissionOutput } from "./processSubmission";
1
+ import type { TDocumentDefinitions } from "pdfmake/interfaces";
2
+ import type { ProcessSubmissionOutput } from "./processSubmission.js";
3
3
  export declare function generatePdfJson(data: ProcessSubmissionOutput, DATE_FORMAT: string, TIMEZONE: string): TDocumentDefinitions;
4
4
  export declare const generatePDF: () => (data: ProcessSubmissionOutput) => Promise<ProcessSubmissionOutput>;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,23 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.generatePDF = exports.generatePdfJson = void 0;
16
- const node_fs_1 = require("node:fs");
17
- const node_path_1 = require("node:path");
18
- const pdfmake_1 = __importDefault(require("pdfmake"));
19
- const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
20
- const locales_1 = require("../locales");
21
- const Report_1 = require("../pdf/components/Report");
22
- const style_1 = require("../pdf/style");
23
- function generatePdfJson(data, DATE_FORMAT, TIMEZONE) {
24
- return jsx_pdf_1.default.renderPdf(jsx_pdf_1.default.createElement(Report_1.Report, { data: data.json, files: data.files, aId: data.a_id, clientUrl: data.client_url, envConfig: data.envConfig, config: { DATE_FORMAT, TIMEZONE } }));
10
+ import { promises as fs } from "node:fs";
11
+ import { join } from "node:path";
12
+ import PdfPrinter from "pdfmake";
13
+ import JsxPdf from "jsx-pdf";
14
+ import { isValidLocale } from "../locales/index.js";
15
+ import { Report } from "../pdf/components/Report.js";
16
+ import { fonts } from "../pdf/style.js";
17
+ import { getDirname } from "../helpers/pathUtils.js";
18
+ export function generatePdfJson(data, DATE_FORMAT, TIMEZONE) {
19
+ return JsxPdf.renderPdf(JsxPdf.createElement(Report, { data: data.json, files: data.files, aId: data.a_id, clientUrl: data.client_url, envConfig: data.envConfig, config: { DATE_FORMAT, TIMEZONE } }));
25
20
  }
26
- exports.generatePdfJson = generatePdfJson;
27
- const generatePDF = () =>
21
+ export const generatePDF = () =>
28
22
  // eslint-disable-next-line unicorn/consistent-function-scoping -- deliberately to future proof the SDK for options
29
23
  (data) => __awaiter(void 0, void 0, void 0, function* () {
30
24
  console.log("Generating PDF Report...");
@@ -32,10 +26,10 @@ const generatePDF = () =>
32
26
  if (data.envConfig.logo_url) {
33
27
  // there is a white labelling URL, so fetch it and write it to disk, overriding the default logo
34
28
  const arrayBuf = yield fetch(data.envConfig.logo_url).then((r) => r.arrayBuffer());
35
- yield node_fs_1.promises.writeFile((0, node_path_1.join)(__dirname, "../../assets/custom-logo.png"), Buffer.from(arrayBuf));
29
+ yield fs.writeFile(join(getDirname(), "../../assets/custom-logo.png"), Buffer.from(arrayBuf));
36
30
  }
37
31
  if (customLang) {
38
- if ((0, locales_1.isValidLocale)(customLang)) {
32
+ if (isValidLocale(customLang)) {
39
33
  global.lang = customLang;
40
34
  }
41
35
  else {
@@ -43,7 +37,7 @@ const generatePDF = () =>
43
37
  }
44
38
  }
45
39
  return new Promise((resolve) => {
46
- const printer = new pdfmake_1.default(style_1.fonts);
40
+ const printer = new PdfPrinter(fonts);
47
41
  const pdfDocument = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE));
48
42
  const chunks = [];
49
43
  pdfDocument.on("data", (chunk) => chunks.push(chunk));
@@ -52,9 +46,8 @@ const generatePDF = () =>
52
46
  const dataUrl = `data:application/pdf;base64,${final.toString("base64")}`;
53
47
  resolve(Object.assign(Object.assign({}, data), { files: Object.assign(Object.assign({}, data.files), {
54
48
  // do not change name, will be a breaking change
55
- [data.json.i_id]: [dataUrl, "pdf"] }) }));
49
+ [data.json.id]: [dataUrl, "pdf"] }) }));
56
50
  });
57
51
  pdfDocument.end();
58
52
  });
59
53
  });
60
- exports.generatePDF = generatePDF;
@@ -1,4 +1,4 @@
1
- import { Config } from "../constants";
1
+ import { type Config } from "../constants.js";
2
2
  /**
3
3
  * This helper is designed for environments where the configuration
4
4
  * options are in the environment variables, such as AWS lambda.
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAndValidateConfig = void 0;
4
- const constants_1 = require("../constants");
1
+ import { ENV_VARIABLES } from "../constants.js";
5
2
  /**
6
3
  * This helper is designed for environments where the configuration
7
4
  * options are in the environment variables, such as AWS lambda.
8
5
  * It extracts the relevant ENV variables and throws an error if
9
6
  * any are missing.
10
7
  */
11
- function getAndValidateConfig() {
12
- const CONFIG = constants_1.ENV_VARIABLES.reduce((accumulator, name) => {
8
+ export function getAndValidateConfig() {
9
+ const CONFIG = ENV_VARIABLES.reduce((accumulator, name) => {
13
10
  const value = process.env[name];
14
11
  if (!value)
15
12
  throw new Error(`${name} is not configured`);
@@ -17,4 +14,3 @@ function getAndValidateConfig() {
17
14
  }, {});
18
15
  return CONFIG;
19
16
  }
20
- exports.getAndValidateConfig = getAndValidateConfig;
@@ -1,8 +1,8 @@
1
1
  import type { AId, IId, Instance, RealVer } from "@raytio/types";
2
- import { Config, InstanceDataToPassOn } from "../constants";
3
- import { FlatPO } from "../helpers";
4
- import { EnvConfig } from "../api";
5
- import { ApplicationEncryptorLike } from "../types";
2
+ import { type Config, type InstanceDataToPassOn } from "../constants.js";
3
+ import { type FlatPO } from "../helpers/index.js";
4
+ import { type EnvConfig } from "../api/index.js";
5
+ import type { ApplicationEncryptorLike } from "../types.js";
6
6
  type DecryptData = {
7
7
  apiToken: string;
8
8
  instance: Instance;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,24 +7,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
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
- const constants_2 = require("../pdf/constants");
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";
19
16
  function decryptStage(log, config, envConfig, instanceId) {
20
17
  return __awaiter(this, void 0, void 0, function* () {
21
18
  log("Authenticating...");
22
- const { apiToken, cognitoAttributes } = yield (0, api_1.signIn)(config, envConfig);
19
+ const { apiToken, cognitoAttributes } = yield signIn(config, envConfig);
23
20
  log("Initializing decryptor...");
24
- const maxcryptor = yield (0, helpers_1.setupMaxcryptor)(config, cognitoAttributes);
25
- log("Fetching submission details...");
26
- const apiResp = yield (0, api_1.fetchInstanceData)(apiToken, envConfig, instanceId);
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
+ });
27
30
  log("Decrypting submission details...");
28
- const { instance, applicationDecryptor } = yield (0, core_1.decryptSharedData)({
31
+ const { instance, applicationDecryptor } = yield decryptSharedData({
29
32
  apiToken,
30
33
  apiUrl: envConfig.api_url,
31
34
  instanceData: apiResp,
@@ -40,32 +43,32 @@ function decryptStage(log, config, envConfig, instanceId) {
40
43
  };
41
44
  });
42
45
  }
43
- function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }) {
46
+ export function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }) {
44
47
  return __awaiter(this, void 0, void 0, function* () {
45
48
  const log = verbose ? console.log : () => undefined;
46
49
  try {
47
50
  log("Fetching config...");
48
- const envConfig = yield (0, api_1.fetchEnvConfig)(config.CLIENT_URL);
51
+ const envConfig = yield fetchEnvConfig(config.CLIENT_URL);
49
52
  const { instance, apiToken, applicationDecryptor, encryptedInstance } = _supliedConfig ||
50
53
  (yield decryptStage(log, config, envConfig, instanceId));
51
54
  log("Checking verifications...");
52
- const [profileObjects, verifications] = (0, helpers_1.splitPOAndVers)(instance.profile_objects);
55
+ const [profileObjects, verifications] = splitPOAndVers(instance.profile_objects);
53
56
  const realVers = (_supliedConfig === null || _supliedConfig === void 0 ? void 0 : _supliedConfig.realVers) ||
54
- (yield (0, core_1.getSomeoneElsesRealVerifications)({
55
- aId: instance.a_id,
57
+ (yield getSomeoneElsesRealVerifications({
58
+ aId: instance.aa_id,
56
59
  apiUrl: envConfig.api_url,
57
60
  profileObjects,
58
61
  verifications,
59
62
  }));
60
63
  log("Fetching relevant schema...");
61
- const allSchemas = yield (0, api_1.getAllSchema)(envConfig);
64
+ const allSchemas = yield getAllSchema(envConfig);
62
65
  log("Fetching access application...");
63
- const AA = instance.i_id === constants_2.NULL_I_ID
66
+ const AA = instance.id === NULL_I_ID
64
67
  ? undefined
65
- : yield (0, api_1.fetchAA)(apiToken, envConfig, instance.a_id);
68
+ : yield fetchAA(apiToken, envConfig, instance.aa_id);
66
69
  let score;
67
- if (AA && (0, core_1.isScoreConfigValid)(AA.ruleset)) {
68
- const ruleInputData = yield (0, core_1.convertInstanceToRuleInput)(instance.profile_objects, realVers, (schemaName) => __awaiter(this, void 0, void 0, function* () {
70
+ if (AA && isScoreConfigValid(AA.ruleset)) {
71
+ const ruleInputData = yield convertInstanceToRuleInput(instance.profile_objects, realVers, (schemaName) => __awaiter(this, void 0, void 0, function* () {
69
72
  const schema = allSchemas.find((x) => x.name === schemaName);
70
73
  if (!schema) {
71
74
  throw new Error(`Could not find schema “${schemaName}”`);
@@ -75,14 +78,16 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
75
78
  try {
76
79
  // decrypt helper never uses a stored score. We always re-calculate it.
77
80
  log("Calculating score...");
78
- score = yield (0, core_1.calculateScore)(AA.ruleset, ruleInputData);
79
- if (!(0, ramda_1.equals)(instance.score, score)) {
81
+ score = yield calculateScore(AA.ruleset, ruleInputData);
82
+ if (!equals(instance.score, score)) {
80
83
  // the score we calculated is different to the one that's saved on the instance.
81
84
  // So we save the new score.
82
85
  log("Saving score to instance...");
83
86
  // this can happen silently in the background, but we await it since so that we
84
87
  // abort if this fails.
85
- yield (0, api_1.updateInstanceData)(apiToken, Object.assign(Object.assign({}, encryptedInstance), { score }));
88
+ yield updateInstanceData(apiToken, envConfig, encryptedInstance.id, {
89
+ score,
90
+ });
86
91
  }
87
92
  }
88
93
  catch (ex) {
@@ -93,18 +98,18 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
93
98
  log("No score rules configured on the AA.");
94
99
  }
95
100
  log("Fetching verification providers...");
96
- const PODetails = yield (0, helpers_1.formatOutput)(profileObjects, allSchemas, realVers, apiToken, envConfig);
101
+ const PODetails = yield formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig);
97
102
  log("Fetching attached files...");
98
- const files = yield (0, api_1.getFiles)(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
99
- const instanceDataToPassOn = (0, ramda_1.omit)(constants_1.INSTANCE_FIELDS_TO_REMOVE, instance);
103
+ const files = yield getFiles(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
104
+ const instanceDataToPassOn = omit(INSTANCE_FIELDS_TO_REMOVE, instance);
100
105
  // final outputs
101
- const csv = (0, helpers_1.deepJsonToCsv)(Object.assign(Object.assign({}, instanceDataToPassOn), (0, ramda_1.mapObjIndexed)((POList) => POList.map((flatPO) => {
106
+ const csv = deepJsonToCsv(Object.assign(Object.assign({}, instanceDataToPassOn), mapObjIndexed((POList) => POList.map((flatPO) => {
102
107
  // this is a bit weird, but it prevents an even bigger breaking change for the csv format
103
108
  const object = Object.entries(flatPO.$properties).flatMap(([fieldName, field]) => [
104
109
  [fieldName, field.value],
105
110
  [
106
111
  `${fieldName}.verification`,
107
- constants_1.FIELD_VER_TEXT_MAP[field.verification],
112
+ FIELD_VER_TEXT_MAP[field.verification],
108
113
  ],
109
114
  ]);
110
115
  return Object.assign(Object.assign({}, flatPO), Object.fromEntries(object));
@@ -125,4 +130,3 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
125
130
  }
126
131
  });
127
132
  }
128
- exports.processSubmission = processSubmission;
@@ -1,2 +1,2 @@
1
- import { ProcessSubmissionOutput } from "./processSubmission";
1
+ import type { ProcessSubmissionOutput } from "./processSubmission.js";
2
2
  export declare const saveToS3Bucket: () => (input: ProcessSubmissionOutput) => Promise<void>;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,12 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
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"));
10
+ import AWS from "aws-sdk";
17
11
  function upload(s3, { bucketName, fileName, fileContent }) {
18
12
  return __awaiter(this, void 0, void 0, function* () {
19
13
  return new Promise((resolve, reject) => {
@@ -30,31 +24,30 @@ function upload(s3, { bucketName, fileName, fileContent }) {
30
24
  });
31
25
  });
32
26
  }
33
- const saveToS3Bucket = () =>
27
+ export const saveToS3Bucket = () =>
34
28
  // eslint-disable-next-line unicorn/consistent-function-scoping -- deliberately to future proof the SDK for options
35
29
  (input) => __awaiter(void 0, void 0, void 0, function* () {
36
30
  console.log("Uploading data to S3...");
37
31
  const bucketName = process.env.S3_BUCKET;
38
32
  if (!bucketName)
39
33
  throw new Error("S3_BUCKET is not specified");
40
- const s3 = new aws_sdk_1.default.S3();
34
+ const s3 = new AWS.S3();
41
35
  yield upload(s3, {
42
36
  bucketName,
43
- fileName: `${input.json.i_id}/${input.json.i_id}.csv`,
37
+ fileName: `${input.json.id}/${input.json.id}.csv`,
44
38
  fileContent: input.csv,
45
39
  });
46
40
  yield upload(s3, {
47
41
  bucketName,
48
- fileName: `${input.json.i_id}/${input.json.i_id}.json`,
42
+ fileName: `${input.json.id}/${input.json.id}.json`,
49
43
  fileContent: JSON.stringify(input.json),
50
44
  });
51
45
  yield Promise.all(Object.entries(input.files).map(([nId, [dataUrl, fileExtension]]) => __awaiter(void 0, void 0, void 0, function* () {
52
46
  yield upload(s3, {
53
47
  bucketName,
54
- fileName: `${input.json.i_id}/${nId}.${fileExtension}`,
48
+ fileName: `${input.json.id}/${nId}.${fileExtension}`,
55
49
  fileContent: Buffer.from(dataUrl.split(",")[1], "base64"),
56
50
  });
57
51
  })));
58
52
  console.log("Finished uploading data to S3.");
59
53
  });
60
- exports.saveToS3Bucket = saveToS3Bucket;
@@ -1,15 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.version = exports.packageDotJson = void 0;
4
- const node_fs_1 = require("node:fs");
5
- const node_path_1 = require("node:path");
6
- exports.packageDotJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "../../package.json"), "utf8"));
7
- exports.version = Object.entries({
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({
8
6
  LANG: process.env.PDF_LANGUAGE || "default",
9
7
  N: process.version.slice(1),
10
- DH: exports.packageDotJson.version,
11
- C: exports.packageDotJson.dependencies["@raytio/core"].slice(1),
12
- T: exports.packageDotJson.dependencies["@raytio/types"].slice(1),
8
+ DH: packageDotJson.version,
9
+ C: packageDotJson.dependencies["@raytio/core"].slice(1),
10
+ T: packageDotJson.dependencies["@raytio/types"].slice(1),
13
11
  })
14
12
  .map((kv) => kv.join("="))
15
13
  .join(" ");