@raytio/decrypt-helper 2.1.1 → 2.2.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 (42) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/api/fetchAA.d.ts +3 -0
  3. package/dist/api/fetchAA.js +19 -0
  4. package/dist/api/fetchInstanceData.js +3 -5
  5. package/dist/api/getSchema.d.ts +1 -1
  6. package/dist/api/getSchema.js +4 -4
  7. package/dist/api/index.d.ts +1 -0
  8. package/dist/api/index.js +1 -0
  9. package/dist/constants.d.ts +4 -1
  10. package/dist/helpers/__tests__/formatOutput.test.js +5 -1
  11. package/dist/helpers/__tests__/lookup.test.js +3 -3
  12. package/dist/helpers/formatOutput.js +9 -2
  13. package/dist/helpers/index.d.ts +1 -0
  14. package/dist/helpers/index.js +1 -0
  15. package/dist/helpers/lookup.d.ts +1 -1
  16. package/dist/helpers/types.d.ts +1 -0
  17. package/dist/helpers/types.js +9 -0
  18. package/dist/pdf/components/FieldVerificationBadge.d.ts +2 -2
  19. package/dist/pdf/components/FieldVerificationBadge.js +2 -2
  20. package/dist/pdf/components/Images.d.ts +2 -2
  21. package/dist/pdf/components/Images.js +5 -2
  22. package/dist/pdf/components/InnerTableRows.d.ts +2 -2
  23. package/dist/pdf/components/InnerTableRows.js +5 -3
  24. package/dist/pdf/components/POVerificationBadge.d.ts +2 -2
  25. package/dist/pdf/components/POVerificationBadge.js +2 -2
  26. package/dist/pdf/components/Report.d.ts +2 -2
  27. package/dist/pdf/components/Report.js +9 -5
  28. package/dist/pdf/components/Subheader.d.ts +1 -1
  29. package/dist/pdf/components/Subheader.js +2 -2
  30. package/dist/pdf/components/Table.d.ts +2 -2
  31. package/dist/pdf/components/Table.js +3 -2
  32. package/dist/pdf/components/TableTitle.d.ts +2 -2
  33. package/dist/pdf/components/TableTitle.js +2 -2
  34. package/dist/pdf/components/ValidationDisplay.d.ts +2 -2
  35. package/dist/pdf/components/ValidationDisplay.js +8 -3
  36. package/dist/pdf/helpers/general.js +6 -1
  37. package/dist/pdf/helpers/transform.js +6 -2
  38. package/dist/public-methods/processSubmission.js +23 -4
  39. package/dist/public-methods/saveToS3Bucket.js +2 -0
  40. package/package.json +22 -22
  41. package/dist/api/__tests__/fetchInstanceData.test.d.ts +0 -1
  42. package/dist/api/__tests__/fetchInstanceData.test.js +0 -42
package/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 2.2.1 (2022-02-09)
11
+
12
+ - !158 include the submission score in the json and pdf
13
+
14
+ ## 2.2.0 (2022-02-04)
15
+
16
+ - !153 fix rendering of arrays of primitive values
17
+ - !152 Update @raytio/core to v9 to fix a bug with `hashed_n_id`
18
+ - !155, !154, !146, !147, !150, !151 automated dependency updates
19
+
20
+ ## 2.1.3 (2021-10-08)
21
+
22
+ - !134 Add more logging to `saveToS3Bucket`
23
+ - !129, !131, !132, !133 automated dependency updates
24
+
25
+ ## 2.1.2 (2021-09-24)
26
+
27
+ - !129 Update @raytio/core to v8.1.2 to support the new API format for `hashed_n_id`
28
+
10
29
  ## 2.1.1 (2021-09-15)
11
30
 
12
31
  - !126 Update @raytio/core to v8.1.1 to fix a bug with `hashed_n_id`
@@ -0,0 +1,3 @@
1
+ import type { AId, AA } from "@raytio/types";
2
+ import { EnvConfig } from "./fetchEnvConfig";
3
+ export declare function fetchAA(apiToken: string, envConfig: EnvConfig, aId: AId): Promise<AA>;
@@ -0,0 +1,19 @@
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.fetchAA = void 0;
13
+ const authedFetch_1 = require("./authedFetch");
14
+ function fetchAA(apiToken, envConfig, aId) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ return (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/${aId}`);
17
+ });
18
+ }
19
+ exports.fetchAA = fetchAA;
@@ -10,14 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.fetchInstanceData = void 0;
13
- const ramda_1 = require("ramda");
13
+ const core_1 = require("@raytio/core");
14
14
  const authedFetch_1 = require("./authedFetch");
15
15
  function fetchInstanceData(apiToken, envConfig, instanceId) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
- const instance = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instanceId}`);
18
- // the API sometimes returns hashed_n_id instead of n_id, so we convert it to a
19
- // consistent format for @raytio/core
20
- return Object.assign(Object.assign({}, instance), { profile_objects: instance.profile_objects.map((PO) => (Object.assign(Object.assign({}, (0, ramda_1.omit)(["hashed_n_id"], PO)), { n_id: PO.n_id || `HASHED::${PO.hashed_n_id}` }))) });
17
+ const instance = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instanceId}`).then(core_1.cleanInstance);
18
+ return instance;
21
19
  });
22
20
  }
23
21
  exports.fetchInstanceData = fetchInstanceData;
@@ -1,3 +1,3 @@
1
1
  import type { Schema } from "@raytio/types";
2
2
  import { EnvConfig } from "./fetchEnvConfig";
3
- export declare function getSchema(envConfig: EnvConfig, apiToken: string, name: string): Promise<Schema>;
3
+ export declare function getSchema(envConfig: EnvConfig, name: string): Promise<Schema>;
@@ -12,18 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getSchema = void 0;
13
13
  const authedFetch_1 = require("./authedFetch");
14
14
  const cache = new Map();
15
- function $getSchema(envConfig, apiToken, name) {
15
+ function $getSchema(envConfig, name) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  const [schemaHead, ...schemaTail] = name.split("_");
18
- const schema = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/graph/v2/schema/${schemaHead}/${schemaTail.join("_")}?expand=true`);
18
+ const schema = yield (0, authedFetch_1.authedFetch)("", `${envConfig.api_url}/graph/v2/schema_public/${schemaHead}/${schemaTail.join("_")}?expand=true`);
19
19
  return Object.assign(Object.assign({}, schema), { name });
20
20
  });
21
21
  }
22
- function getSchema(envConfig, apiToken, name) {
22
+ function getSchema(envConfig, name) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  if (cache.has(name))
25
25
  return cache.get(name);
26
- const promise = $getSchema(envConfig, apiToken, name);
26
+ const promise = $getSchema(envConfig, name);
27
27
  cache.set(name, promise);
28
28
  return promise;
29
29
  });
@@ -1,4 +1,5 @@
1
1
  export * from "./authedFetch";
2
+ export * from "./fetchAA";
2
3
  export * from "./fetchEnvConfig";
3
4
  export * from "./fetchInstanceData";
4
5
  export * from "./getFiles";
package/dist/api/index.js CHANGED
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./authedFetch"), exports);
14
+ __exportStar(require("./fetchAA"), exports);
14
15
  __exportStar(require("./fetchEnvConfig"), exports);
15
16
  __exportStar(require("./fetchInstanceData"), exports);
16
17
  __exportStar(require("./getFiles"), exports);
@@ -1,3 +1,4 @@
1
+ import { ScoreResult } from "@raytio/core";
1
2
  import { FieldVerification, Instance, POVerification } from "@raytio/types";
2
3
  export declare const ATTRIBUTE_MAP: {
3
4
  "custom:kek_derivation": string[];
@@ -12,6 +13,8 @@ export declare const INSTANCE_FIELDS_TO_REMOVE: readonly ["profile_objects", "re
12
13
  export declare const FIELDS_TO_REMOVE: readonly ["n_id", "document"];
13
14
  export declare const ENV_VARIABLES: readonly ["CLIENT_URL", "READABLE_FIELD_NAMES", "USERNAME", "PASSWORD"];
14
15
  export declare type Config = Record<typeof ENV_VARIABLES[number], string>;
15
- export declare type InstanceDataToPassOn = Omit<Instance, typeof INSTANCE_FIELDS_TO_REMOVE[number]>;
16
+ export declare type InstanceDataToPassOn = Omit<Instance, typeof INSTANCE_FIELDS_TO_REMOVE[number]> & {
17
+ score?: ScoreResult;
18
+ };
16
19
  export declare const PO_VER_TEXT_MAP: Record<POVerification, string>;
17
20
  export declare const FIELD_VER_TEXT_MAP: Record<FieldVerification, string>;
@@ -31,16 +31,20 @@ const profileObjects = [
31
31
  },
32
32
  ];
33
33
  const allSchemas = [
34
- { name: "ss_name", title: "Your Name" },
34
+ { name: "ss_name", title: "Your Name", description: "", properties: {} },
35
35
  {
36
36
  name: "ss_nz_drivers_license",
37
37
  schema_group: "DL",
38
38
  title: "NZ Drivers License",
39
+ description: "",
40
+ properties: {},
39
41
  },
40
42
  {
41
43
  name: "ss_nsw_drivers_license",
42
44
  schema_group: "DL",
43
45
  title: "NSW Drivers License",
46
+ description: "",
47
+ properties: {},
44
48
  },
45
49
  ];
46
50
  const realVers = [];
@@ -30,7 +30,7 @@ describe("maybeAddLookupValue", () => {
30
30
  },
31
31
  };
32
32
  const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
33
- expect(result).toStrictEqual("NZ");
33
+ expect(result).toBe("NZ");
34
34
  }));
35
35
  it("Returns lookup value", () => __awaiter(void 0, void 0, void 0, function* () {
36
36
  getLookupOption_ts_1.getLookupOption.mockImplementation(() => [
@@ -52,7 +52,7 @@ describe("maybeAddLookupValue", () => {
52
52
  },
53
53
  };
54
54
  const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
55
- expect(result).toStrictEqual("New Zealand");
55
+ expect(result).toBe("New Zealand");
56
56
  }));
57
57
  it("Returns value if no corresponding key in lookup", () => __awaiter(void 0, void 0, void 0, function* () {
58
58
  getLookupOption_ts_1.getLookupOption.mockImplementation(() => [
@@ -74,6 +74,6 @@ describe("maybeAddLookupValue", () => {
74
74
  },
75
75
  };
76
76
  const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
77
- expect(result).toStrictEqual("NZ");
77
+ expect(result).toBe("NZ");
78
78
  }));
79
79
  });
@@ -15,8 +15,11 @@ const ramda_1 = require("ramda");
15
15
  const api_1 = require("../api");
16
16
  const constants_1 = require("../constants");
17
17
  const lookup_1 = require("./lookup");
18
+ const types_1 = require("./types");
18
19
  const byPriority = (schema) => ([a], [b]) => {
19
20
  var _a, _b, _c, _d, _e, _f;
21
+ (0, types_1.assertSafeProperty)(a);
22
+ (0, types_1.assertSafeProperty)(b);
20
23
  // if no priority, it becomes the last
21
24
  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;
22
25
  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;
@@ -36,11 +39,13 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, en
36
39
  const verDetails = (0, core_1.getPOVerification)({ PO, schema, realVers });
37
40
  const realProps = (0, ramda_1.omit)(constants_1.FIELDS_TO_REMOVE, PO.properties);
38
41
  const schemaNameOrGroup = (_a = schema.schema_group) !== null && _a !== void 0 ? _a : schema.name;
42
+ (0, types_1.assertSafeProperty)(schemaNameOrGroup);
39
43
  const existing = ac[schemaNameOrGroup] || [];
40
44
  const poProperties = Object.entries(realProps).sort(byPriority(schema));
41
45
  const reducedProperties = yield poProperties.reduce((acc, [key, value]) => __awaiter(this, void 0, void 0, function* () {
42
46
  var _c, _d;
43
47
  const accP = yield acc;
48
+ (0, types_1.assertSafeProperty)(key);
44
49
  return Object.assign(Object.assign({}, accP), { [key]: {
45
50
  title: ((_d = (_c = schema.properties) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.title) || key,
46
51
  value: typeof value === "string"
@@ -51,12 +56,12 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, en
51
56
  }), Promise.resolve({}));
52
57
  const thisPO = Object.assign({
53
58
  // these are always included
54
- $verified: verDetails.status, $verification_details: yield (0, api_1.resolveVerificationDetails)(verDetails.details, apiToken, envConfig), $shouldBeVerifiedFields: (_b = schema.verified_fields) === null || _b === void 0 ? void 0 : _b.map((x) => typeof x === "string" ? x : x.field),
59
+ $verified: verDetails.status, $verification_details: yield (0, api_1.resolveVerificationDetails)(verDetails.details.verifiers, apiToken, envConfig), $shouldBeVerifiedFields: (_b = schema.verified_fields) === null || _b === void 0 ? void 0 : _b.map((x) => typeof x === "string" ? x : x.field),
55
60
  // these are not included in the CSV for legacy reasons
56
61
  $nId: PO.n_id, $schemaName: schemaName, $properties: reducedProperties, $safeHarbour: schemaName === "ss_Person_Name"
57
62
  ? (yield (0, core_1.calcSafeHarbourScore)({
58
63
  person: PO,
59
- getSchema: (name) => (0, api_1.getSchema)(envConfig, apiToken, name),
64
+ getSchema: (name) => (0, api_1.getSchema)(envConfig, name),
60
65
  profileObjects,
61
66
  realVers,
62
67
  })).isSafe
@@ -64,9 +69,11 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, en
64
69
  .sort(byPriority(schema))
65
70
  .reduce((acc, [key, value]) => {
66
71
  var _a, _b;
72
+ (0, types_1.assertSafeProperty)(key);
67
73
  const title = readable
68
74
  ? ((_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.title) || key
69
75
  : key;
76
+ (0, types_1.assertSafeProperty)(title);
70
77
  const titleV = readable
71
78
  ? `${title} Verification`
72
79
  : `${title}.verification`;
@@ -3,3 +3,4 @@ export * from "./json2csv";
3
3
  export * from "./setupMaxcryptor";
4
4
  export * from "./splitPOAndVers";
5
5
  export * from "./file";
6
+ export * from "./types";
@@ -15,3 +15,4 @@ __exportStar(require("./json2csv"), exports);
15
15
  __exportStar(require("./setupMaxcryptor"), exports);
16
16
  __exportStar(require("./splitPOAndVers"), exports);
17
17
  __exportStar(require("./file"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -1,2 +1,2 @@
1
1
  import { Schema } from "@raytio/types";
2
- export declare const maybeAddLookupValue: <T extends unknown>(schema: Schema, k: string, value: T, apiToken: string) => Promise<string | number | T>;
2
+ export declare const maybeAddLookupValue: <T>(schema: Schema, k: string, value: T, apiToken: string) => Promise<string | number | T>;
@@ -0,0 +1 @@
1
+ export declare function assertSafeProperty(property: unknown): asserts property is string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertSafeProperty = void 0;
4
+ function assertSafeProperty(property) {
5
+ if (typeof property !== "string" || property in {}) {
6
+ throw new Error(`Invalid property name '${property}'`);
7
+ }
8
+ }
9
+ exports.assertSafeProperty = assertSafeProperty;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import { FieldVerification } from "@raytio/types";
3
- export declare function FieldVerificationBadge({ status, width, }: {
3
+ export declare const FieldVerificationBadge: ({ status, width, }: {
4
4
  status: FieldVerification | undefined;
5
5
  width: number;
6
- }): null | JSX.Element;
6
+ }) => null | JSX.Element;
@@ -7,7 +7,7 @@ exports.FieldVerificationBadge = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
8
  const types_1 = require("@raytio/types");
9
9
  const general_1 = require("../helpers/general");
10
- function FieldVerificationBadge({ status, width, }) {
10
+ const FieldVerificationBadge = ({ status, width, }) => {
11
11
  if (status === types_1.FieldVerification.VerifiedFalse) {
12
12
  return (jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)("verified_false_small.svg"), width: width }));
13
13
  }
@@ -15,5 +15,5 @@ function FieldVerificationBadge({ status, width, }) {
15
15
  return jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)("verified_tick_small.svg"), width: width });
16
16
  }
17
17
  return null;
18
- }
18
+ };
19
19
  exports.FieldVerificationBadge = FieldVerificationBadge;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import { Files } from "../types";
3
- export declare function Images({ nIds, files, }: {
3
+ export declare const Images: ({ nIds, files, }: {
4
4
  nIds: string[];
5
5
  files: Files;
6
- }): JSX.Element;
6
+ }) => JSX.Element;
@@ -5,11 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Images = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
- function Images({ nIds, files, }) {
8
+ const helpers_1 = require("../../helpers");
9
+ const Images = ({ nIds, files, }) => {
9
10
  return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null, nIds.map((nId) => {
10
11
  var _a;
11
12
  const file = (_a = files[nId]) === null || _a === void 0 ? void 0 : _a[0];
13
+ if (file)
14
+ (0, helpers_1.assertSafeProperty)(file);
12
15
  return file ? (jsx_pdf_1.default.createElement("image", { src: file, width: 300 })) : (jsx_pdf_1.default.createElement("text", null, "File not found"));
13
16
  })));
14
- }
17
+ };
15
18
  exports.Images = Images;
@@ -1,10 +1,10 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import { Files, PdfConfig } from "../types";
3
- export declare function InnerTableRows({ key, value, imageFieldNames, config, files, color, }: {
3
+ export declare const InnerTableRows: ({ key, value, imageFieldNames, config, files, color, }: {
4
4
  key: string;
5
5
  value: any;
6
6
  files: Files;
7
7
  config: PdfConfig;
8
8
  color: string;
9
9
  imageFieldNames: string[];
10
- }): JSX.Element;
10
+ }) => JSX.Element;
@@ -6,10 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.InnerTableRows = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
8
  const ramda_1 = require("ramda");
9
+ const helpers_1 = require("../../helpers");
9
10
  const transform_1 = require("../helpers/transform");
10
11
  const Images_1 = require("./Images");
11
12
  const ValidationDisplay_1 = require("./ValidationDisplay");
12
- function InnerTableRows({ key, value, imageFieldNames, config, files, color, }) {
13
+ const InnerTableRows = ({ key, value, imageFieldNames, config, files, color, }) => {
13
14
  if (typeof value === "object" &&
14
15
  value &&
15
16
  "score" in value &&
@@ -25,11 +26,12 @@ function InnerTableRows({ key, value, imageFieldNames, config, files, color, })
25
26
  const tableValues = [...headers, ...value];
26
27
  return (jsx_pdf_1.default.createElement("table", { headerRows: 1, layout: "headerLineOnly" }, tableValues.map((data, tableValueIndex) => {
27
28
  return (jsx_pdf_1.default.createElement("row", null, headers[0].map((header) => {
29
+ (0, helpers_1.assertSafeProperty)(header);
28
30
  return (jsx_pdf_1.default.createElement("cell", null,
29
- jsx_pdf_1.default.createElement(InnerTableRows, { key: header, value: data[header] || (tableValueIndex === 0 ? header : "-"), files: files, config: config, color: color, imageFieldNames: imageFieldNames })));
31
+ jsx_pdf_1.default.createElement(exports.InnerTableRows, { key: header, value: data[header] || (tableValueIndex === 0 ? header : "-"), files: files, config: config, color: color, imageFieldNames: imageFieldNames })));
30
32
  })));
31
33
  })));
32
34
  }
33
35
  return jsx_pdf_1.default.createElement("text", { color: color }, text.slice(0, 100));
34
- }
36
+ };
35
37
  exports.InnerTableRows = InnerTableRows;
@@ -2,7 +2,7 @@
2
2
  import { POVerification } from "@raytio/types";
3
3
  import { PdfSchema } from "../types";
4
4
  export declare const FILE_MAP: Record<POVerification, string>;
5
- export declare function POVerificationBadge({ width, schema, }: {
5
+ export declare const POVerificationBadge: ({ width, schema, }: {
6
6
  width: number;
7
7
  schema: PdfSchema;
8
- }): JSX.Element;
8
+ }) => JSX.Element;
@@ -18,7 +18,7 @@ exports.FILE_MAP = {
18
18
  [types_1.POVerification.Encrypted]: "not_verified_big",
19
19
  [types_1.POVerification.Loading]: "not_verified_big",
20
20
  };
21
- function POVerificationBadge({ width, schema, }) {
21
+ const POVerificationBadge = ({ width, schema, }) => {
22
22
  const [, profileObjects] = schema;
23
23
  // TODO: this won't work if multiple POs of the same schema are shared
24
24
  const { $verified, $verification_details, $shouldBeVerifiedFields, $safeHarbour, } = profileObjects[0];
@@ -39,5 +39,5 @@ function POVerificationBadge({ width, schema, }) {
39
39
  jsx_pdf_1.default.createElement("text", { alignment: "center" },
40
40
  $safeHarbour ? "" : "Not ",
41
41
  "Safe Harbour Compliant"))))));
42
- }
42
+ };
43
43
  exports.POVerificationBadge = POVerificationBadge;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import type { AId } from "@raytio/types";
3
3
  import { Files, PdfConfig, ReportData } from "../types";
4
- export declare function Report({ data, files, config, aId, clientUrl, version, }: {
4
+ export declare const Report: ({ data, files, config, aId, clientUrl, version, }: {
5
5
  data: ReportData;
6
6
  files: Files;
7
7
  config: PdfConfig;
8
8
  aId: AId;
9
9
  clientUrl: string;
10
10
  version: string;
11
- }): JSX.Element;
11
+ }) => JSX.Element;
@@ -15,7 +15,7 @@ const general_1 = require("../helpers/general");
15
15
  const VerifyBox_1 = require("./VerifyBox");
16
16
  const constants_1 = require("../constants");
17
17
  const transform_1 = require("../helpers/transform");
18
- function Report({ data, files, config, aId, clientUrl, version, }) {
18
+ const Report = ({ data, files, config, aId, clientUrl, version, }) => {
19
19
  const schemas = Object.entries(data).filter(([, val]) => Array.isArray(val) && val.length && "$verified" in val[0]);
20
20
  // The PDF is read only; there's no reason why anyone would ever need to unlock it.
21
21
  const randomToken = (0, crypto_1.randomBytes)(32).toString("base64");
@@ -39,9 +39,13 @@ function Report({ data, files, config, aId, clientUrl, version, }) {
39
39
  jsx_pdf_1.default.createElement("text", { style: ["header", "marginBottom"], alignment: "center" }, "Raytio Verification Report"),
40
40
  jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
41
41
  jsx_pdf_1.default.createElement("column", { width: "auto" },
42
- jsx_pdf_1.default.createElement("text", { style: ["subheader", "marginBottom"] }, Object.entries(constants_1.SUBMISSION_DATA)
43
- .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
44
- .join("\n")),
42
+ jsx_pdf_1.default.createElement("text", { style: ["subheader", "marginBottom"] },
43
+ Object.entries(constants_1.SUBMISSION_DATA)
44
+ .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
45
+ .join("\n"),
46
+ data.score
47
+ ? `\nScore: ${data.score.score}\nScore Category: ${data.score.category}`
48
+ : ""),
45
49
  jsx_pdf_1.default.createElement(Subheader_1.Subheader, { data: data, config: config })),
46
50
  jsx_pdf_1.default.createElement("column", { width: "*" },
47
51
  jsx_pdf_1.default.createElement("text", null, " ")),
@@ -67,5 +71,5 @@ function Report({ data, files, config, aId, clientUrl, version, }) {
67
71
  currentPage,
68
72
  " of ",
69
73
  pageCount))))));
70
- }
74
+ };
71
75
  exports.Report = Report;
@@ -1,2 +1,2 @@
1
1
  /// <reference types="jsx-pdf" />
2
- export declare function Subheader(): JSX.Element;
2
+ export declare const Subheader: () => JSX.Element;
@@ -7,7 +7,7 @@ exports.Subheader = void 0;
7
7
  const types_1 = require("@raytio/types");
8
8
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
9
9
  const FieldVerificationBadge_1 = require("./FieldVerificationBadge");
10
- function Subheader() {
10
+ const Subheader = () => {
11
11
  return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
12
12
  jsx_pdf_1.default.createElement("text", { bold: true, style: "marginBottom" }, "Key:"),
13
13
  jsx_pdf_1.default.createElement("table", { layout: "noBorders" },
@@ -23,5 +23,5 @@ function Subheader() {
23
23
  jsx_pdf_1.default.createElement("cell", null,
24
24
  jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: types_1.FieldVerification.VerifiedFalse })),
25
25
  jsx_pdf_1.default.createElement("cell", null, "Verified False")))));
26
- }
26
+ };
27
27
  exports.Subheader = Subheader;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import { PdfSchema, Files, PdfConfig } from "../types";
3
- export declare function Table({ schema, files, config, }: {
3
+ export declare const Table: ({ schema, files, config, }: {
4
4
  schema: PdfSchema;
5
5
  files: Files;
6
6
  config: PdfConfig;
7
- }): JSX.Element;
7
+ }) => JSX.Element;
@@ -10,7 +10,7 @@ const FieldVerificationBadge_1 = require("./FieldVerificationBadge");
10
10
  const Images_1 = require("./Images");
11
11
  const InnerTableRows_1 = require("./InnerTableRows");
12
12
  const helpers_1 = require("../../helpers");
13
- function Table({ schema, files, config, }) {
13
+ const Table = ({ schema, files, config, }) => {
14
14
  const [, profileObjects] = schema;
15
15
  /** every fieldName in this profile object */
16
16
  const fieldNames = [
@@ -29,6 +29,7 @@ function Table({ schema, files, config, }) {
29
29
  jsx_pdf_1.default.createElement("cell", null,
30
30
  jsx_pdf_1.default.createElement("text", { color: "#12130e" }, fieldName.replace(/_/g, " "))),
31
31
  profileObjects.flatMap((PO) => {
32
+ (0, helpers_1.assertSafeProperty)(fieldName);
32
33
  const status = PO[`${fieldName}.verification`] ||
33
34
  PO[`${fieldName} Verification`];
34
35
  const color = (0, general_1.verifyColour)(status);
@@ -40,5 +41,5 @@ function Table({ schema, files, config, }) {
40
41
  jsx_pdf_1.default.createElement(InnerTableRows_1.InnerTableRows, { key: fieldName, value: PO[fieldName], files: files, config: config, color: color, imageFieldNames: imageFieldNames })),
41
42
  ];
42
43
  }))))));
43
- }
44
+ };
44
45
  exports.Table = Table;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import { PdfSchema } from "../types";
3
- export declare function TableTitle({ schema }: {
3
+ export declare const TableTitle: ({ schema }: {
4
4
  schema: PdfSchema;
5
- }): JSX.Element;
5
+ }) => JSX.Element;
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TableTitle = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
8
  const helpers_1 = require("../../helpers");
9
- function TableTitle({ schema }) {
9
+ const TableTitle = ({ schema }) => {
10
10
  const [schemaTitle, POs] = schema;
11
11
  const maybeFileName = POs.some(helpers_1.isFile) && (POs[0].title || POs[0].Title);
12
12
  return (jsx_pdf_1.default.createElement("text", { bold: true, fontSize: 14, style: "marginBottom" }, maybeFileName || schemaTitle));
13
- }
13
+ };
14
14
  exports.TableTitle = TableTitle;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import { Validation } from "@raytio/types";
3
- export declare function ValidationDisplay({ value, }: {
3
+ export declare const ValidationDisplay: ({ value, }: {
4
4
  value: Validation;
5
- }): null | JSX.Element;
5
+ }) => null | JSX.Element;
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ValidationDisplay = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
8
  const pieChart_1 = require("./pieChart");
9
+ const helpers_1 = require("../../helpers");
9
10
  const SEVERITY_COLOURS = {
10
11
  low: "#2e8bc0",
11
12
  medium: "#ff9800",
12
13
  high: "#fb7171",
13
14
  };
14
- function ValidationDisplay({ value, }) {
15
+ const ValidationDisplay = ({ value, }) => {
15
16
  const colour = value.score > 0.5 ? "#c2d887" : "#fb7171";
16
17
  return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
17
18
  jsx_pdf_1.default.createElement("svg", { content: (0, pieChart_1.pieChart)(colour, value.score * 100), width: 50 }),
@@ -20,6 +21,10 @@ function ValidationDisplay({ value, }) {
20
21
  "/10",
21
22
  Object.values(value.breakdown)
22
23
  .filter((x) => x.severity && x.reason)
23
- .map((x) => (jsx_pdf_1.default.createElement("text", { color: SEVERITY_COLOURS[x.severity] }, x.reason)))));
24
- }
24
+ .map((x) => {
25
+ const key = x.severity;
26
+ (0, helpers_1.assertSafeProperty)(key);
27
+ return jsx_pdf_1.default.createElement("text", { color: SEVERITY_COLOURS[key] }, x.reason);
28
+ })));
29
+ };
25
30
  exports.ValidationDisplay = ValidationDisplay;
@@ -4,7 +4,12 @@ exports.formatDate = exports.verifyColour = exports.loadAsset = exports.asset =
4
4
  const types_1 = require("@raytio/types");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
- const asset = (name) => (0, path_1.join)(__dirname, "../../../assets/", name);
7
+ const asset = (name) => {
8
+ if (name.match(/[^A-Za-z\-_.]/) || name.includes("..")) {
9
+ throw new Error("Invalid asset name");
10
+ }
11
+ return (0, path_1.join)(__dirname, "../../../assets/", name);
12
+ };
8
13
  exports.asset = asset;
9
14
  const loadAsset = (name) => (0, fs_1.readFileSync)((0, exports.asset)(name), { encoding: "utf-8" });
10
15
  exports.loadAsset = loadAsset;
@@ -15,8 +15,12 @@ function transform(key, value, pdfConfig, imageFieldNames) {
15
15
  if (imageFieldNames === null || imageFieldNames === void 0 ? void 0 : imageFieldNames.includes(key)) {
16
16
  return exports.IS_IMAGE;
17
17
  }
18
- if (Array.isArray(value))
19
- return exports.IS_ARRAY_OF_OBJECTS;
18
+ if (Array.isArray(value)) {
19
+ if (value.every((v) => typeof v === "object")) {
20
+ return exports.IS_ARRAY_OF_OBJECTS;
21
+ }
22
+ return value.join(", ");
23
+ }
20
24
  if (typeof value !== "string") {
21
25
  return `${value}`;
22
26
  }
@@ -44,7 +44,8 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
44
44
  (yield decryptStage(log, config, envConfig, instanceId));
45
45
  log("Checking verifications...");
46
46
  const [profileObjects, verifications] = (0, helpers_1.splitPOAndVers)(instance.profile_objects);
47
- const realVers = yield (0, core_1.getRealVerifications)({
47
+ const realVers = yield (0, core_1.getSomeoneElsesRealVerifications)({
48
+ aId: instance.a_id,
48
49
  apiUrl: envConfig.api_url,
49
50
  profileObjects,
50
51
  verifications,
@@ -56,7 +57,25 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
56
57
  throw new Error("Submission contains invalid objects");
57
58
  return schemaName;
58
59
  });
59
- const allSchemas = yield Promise.all((0, ramda_1.uniq)(schemaNames).map((name) => (0, api_1.getSchema)(envConfig, apiToken, name)));
60
+ const allSchemas = yield Promise.all((0, ramda_1.uniq)(schemaNames).map((name) => (0, api_1.getSchema)(envConfig, name)));
61
+ log("Fetching access application...");
62
+ const AA = yield (0, api_1.fetchAA)(apiToken, envConfig, instance.a_id);
63
+ let score;
64
+ if (AA.ruleset &&
65
+ typeof AA.ruleset === "object" &&
66
+ Object.keys(AA.ruleset).length) {
67
+ const ruleInputData = yield (0, core_1.convertInstanceToRuleInput)(instance, realVers, (schemaName) => (0, api_1.getSchema)(envConfig, schemaName));
68
+ try {
69
+ log("Calculating score...");
70
+ score = (0, core_1.calculateScore)(AA.ruleset, ruleInputData);
71
+ }
72
+ catch (ex) {
73
+ log(`Score calculation failed (${ex})`);
74
+ }
75
+ }
76
+ else {
77
+ log("No score rules configured on the AA.");
78
+ }
60
79
  // TODO: resolve URNs if any fields are URNs
61
80
  log("Fetching verification providers...");
62
81
  const PODetails = yield (0, helpers_1.formatOutput)(profileObjects, allSchemas, realVers, apiToken, config, envConfig);
@@ -64,7 +83,7 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
64
83
  const files = yield (0, api_1.getFiles)(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
65
84
  const instanceDataToPassOn = (0, ramda_1.omit)(constants_1.INSTANCE_FIELDS_TO_REMOVE, instance);
66
85
  // final outputs
67
- const csv = (0, helpers_1.deepJsonToCsv)(Object.assign(Object.assign({}, (0, ramda_1.omit)(["a_id", "aa_name"], instanceDataToPassOn)), (0, ramda_1.mapObjIndexed)(
86
+ const csv = (0, helpers_1.deepJsonToCsv)(Object.assign(Object.assign({}, (0, ramda_1.omit)(["a_id", "aa_name", "device_id", "source_ip"], instanceDataToPassOn)), (0, ramda_1.mapObjIndexed)(
68
87
  // TODO: (semver breaking) we omit these fields because it would a breaking change for the csv format.
69
88
  (v) => v.map((a) => {
70
89
  // TODO: (semver breaking) map the verification enums to the text to prevent a breaking change
@@ -84,7 +103,7 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
84
103
  }), PODetails)));
85
104
  log("Success!");
86
105
  return {
87
- json: Object.assign(Object.assign({}, instanceDataToPassOn), PODetails),
106
+ json: Object.assign(Object.assign(Object.assign({}, instanceDataToPassOn), { score }), PODetails),
88
107
  csv,
89
108
  files,
90
109
  a_id: applicationId,
@@ -31,6 +31,7 @@ function upload(s3, { bucketName, fileName, fileContent }) {
31
31
  });
32
32
  }
33
33
  const saveToS3Bucket = () => (input) => __awaiter(void 0, void 0, void 0, function* () {
34
+ console.log("Uploading data to S3...");
34
35
  const bucketName = process.env.S3_BUCKET;
35
36
  if (!bucketName)
36
37
  throw new Error("S3_BUCKET is not specified");
@@ -52,5 +53,6 @@ const saveToS3Bucket = () => (input) => __awaiter(void 0, void 0, void 0, functi
52
53
  fileContent: Buffer.from(dataUrl.split(",")[1], "base64"),
53
54
  });
54
55
  })));
56
+ console.log("Finished uploading data to S3.");
55
57
  });
56
58
  exports.saveToS3Bucket = saveToS3Bucket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "2.1.1",
3
+ "version": "2.2.1",
4
4
  "author": "Raytio",
5
5
  "description": "A helper to decrypt data shared by Raytio users",
6
6
  "main": "dist",
@@ -21,37 +21,37 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@aws-amplify/auth": "3.4.25",
24
- "@peculiar/webcrypto": "^1.1.7",
25
- "@raytio/core": "^8.1.1",
26
- "@raytio/maxcryptor": "^3.0.1",
27
- "@raytio/types": "^5.2.0",
24
+ "@peculiar/webcrypto": "^1.2.3",
25
+ "@raytio/core": "^9.0.1",
26
+ "@raytio/maxcryptor": "^3.1.0",
27
+ "@raytio/types": "^6.0.0",
28
28
  "aws-sdk": "^2.754.0",
29
29
  "jsx-pdf": "^2.3.0",
30
30
  "localstorage-polyfill": "^1.0.1",
31
- "mime-types": "^2.1.32",
32
- "node-fetch": "^2.6.2",
33
- "pdfmake": "^0.2.2",
34
- "ramda": "^0.27.1"
31
+ "mime-types": "^2.1.34",
32
+ "node-fetch": "^2.6.7",
33
+ "pdfmake": "^0.2.4",
34
+ "ramda": "^0.28.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@types/jest": "^27.0.1",
37
+ "@types/jest": "^27.4.0",
38
38
  "@types/jest-image-snapshot": "^4.3.1",
39
39
  "@types/jsx-pdf": "^2.2.2",
40
40
  "@types/mime-types": "^2.1.1",
41
- "@types/node": "^14.17.14",
41
+ "@types/node": "^16.11.22",
42
42
  "@types/node-fetch": "^2.5.12",
43
- "@types/pdfmake": "^0.1.18",
44
- "@types/ramda": "^0.27.44",
45
- "dotenv": "^10.0.0",
46
- "eslint": "^7.32.0",
47
- "eslint-config-kyle": "^3.1.0",
48
- "jest": "^27.1.0",
43
+ "@types/pdfmake": "^0.1.20",
44
+ "@types/ramda": "^0.27.64",
45
+ "dotenv": "^16.0.0",
46
+ "eslint": "^8.8.0",
47
+ "eslint-config-kyle": "^8.1.1",
48
+ "jest": "^27.4.7",
49
49
  "jest-image-snapshot": "^4.5.1",
50
- "jest-junit": "^12.2.0",
51
- "pdf-to-img": "^1.1.1",
52
- "ts-jest": "^27.0.5",
53
- "ts-node": "^10.2.1",
54
- "typescript": "^4.4.2"
50
+ "jest-junit": "^13.0.0",
51
+ "pdf-to-img": "^1.2.0",
52
+ "ts-jest": "^27.1.3",
53
+ "ts-node": "^10.4.0",
54
+ "typescript": "^4.5.5"
55
55
  },
56
56
  "eslintConfig": {
57
57
  "extends": "kyle",
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const __1 = require("..");
13
- jest.mock("../authedFetch", () => ({
14
- authedFetch: () => __awaiter(void 0, void 0, void 0, function* () {
15
- return ({
16
- i_id: "i1",
17
- profile_objects: [
18
- { n_id: "n1", properties: { a: 1 } },
19
- { hashed_n_id: "n2", properties: { b: 2 } },
20
- ],
21
- keys: {
22
- n1: { cryptoStuff: 123 },
23
- n2: { xyz: 789 },
24
- },
25
- });
26
- }),
27
- }));
28
- describe("fetchInstanceData", () => {
29
- it("converts the hashed_n_id format into n_id", () => __awaiter(void 0, void 0, void 0, function* () {
30
- expect(yield (0, __1.fetchInstanceData)("myApiToken", { api_url: "https://example.com" }, "i1")).toStrictEqual({
31
- i_id: "i1",
32
- profile_objects: [
33
- { n_id: "n1", properties: { a: 1 } },
34
- { n_id: "HASHED::n2", properties: { b: 2 } },
35
- ],
36
- keys: {
37
- n1: { cryptoStuff: 123 },
38
- n2: { xyz: 789 },
39
- },
40
- });
41
- }));
42
- });