@raytio/decrypt-helper 2.1.3 → 3.0.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 (47) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/README.md +2 -5
  3. package/dist/api/fetchAA.d.ts +3 -0
  4. package/dist/api/fetchAA.js +19 -0
  5. package/dist/api/getFiles.js +1 -1
  6. package/dist/api/getSchema.d.ts +1 -1
  7. package/dist/api/getSchema.js +4 -4
  8. package/dist/api/index.d.ts +1 -0
  9. package/dist/api/index.js +1 -0
  10. package/dist/api/signIn.js +3 -3
  11. package/dist/constants.d.ts +5 -2
  12. package/dist/constants.js +2 -3
  13. package/dist/helpers/__tests__/formatOutput.test.js +9 -105
  14. package/dist/helpers/__tests__/lookup.test.js +3 -3
  15. package/dist/helpers/file.d.ts +5 -1
  16. package/dist/helpers/file.js +9 -4
  17. package/dist/helpers/formatOutput.d.ts +10 -4
  18. package/dist/helpers/formatOutput.js +19 -23
  19. package/dist/helpers/index.d.ts +1 -0
  20. package/dist/helpers/index.js +1 -0
  21. package/dist/helpers/lookup.d.ts +1 -1
  22. package/dist/helpers/setupMaxcryptor.js +1 -1
  23. package/dist/helpers/types.d.ts +1 -0
  24. package/dist/helpers/types.js +9 -0
  25. package/dist/pdf/components/FieldVerificationBadge.d.ts +2 -2
  26. package/dist/pdf/components/FieldVerificationBadge.js +2 -2
  27. package/dist/pdf/components/Images.d.ts +4 -4
  28. package/dist/pdf/components/Images.js +5 -2
  29. package/dist/pdf/components/InnerTableRows.d.ts +5 -4
  30. package/dist/pdf/components/InnerTableRows.js +5 -3
  31. package/dist/pdf/components/POVerificationBadge.d.ts +4 -4
  32. package/dist/pdf/components/POVerificationBadge.js +3 -4
  33. package/dist/pdf/components/Report.d.ts +6 -5
  34. package/dist/pdf/components/Report.js +15 -11
  35. package/dist/pdf/components/Subheader.d.ts +1 -1
  36. package/dist/pdf/components/Subheader.js +2 -2
  37. package/dist/pdf/components/Table.d.ts +7 -5
  38. package/dist/pdf/components/Table.js +24 -26
  39. package/dist/pdf/components/TableTitle.d.ts +4 -4
  40. package/dist/pdf/components/TableTitle.js +7 -4
  41. package/dist/pdf/components/ValidationDisplay.d.ts +2 -2
  42. package/dist/pdf/components/ValidationDisplay.js +8 -3
  43. package/dist/pdf/helpers/general.js +15 -10
  44. package/dist/pdf/helpers/transform.js +6 -2
  45. package/dist/public-methods/processSubmission.d.ts +6 -1
  46. package/dist/public-methods/processSubmission.js +33 -22
  47. package/package.json +21 -21
package/CHANGELOG.md CHANGED
@@ -7,9 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 3.0.1 (2022-02-15)
11
+
12
+ - fix bug with PDF generation
13
+
14
+ ## 3.0.0 (2022-02-04)
15
+
16
+ - 💥 BREAKING CHANGE: renamed the `USERNAME` & `PASSWORD` environment variables to `RAYTIO_USERNAME` & `RAYTIO_PASSWORD`
17
+ - 💥 BREAKING CHANGE: removed the `READABLE_FIELD_NAMES` option
18
+ - 💥 BREAKING CHANGE: [csv] added new columns, shifted other columns
19
+ - 💥 BREAKING CHANGE: [json] removed some duplicate legacy fields, see #33
20
+ - !156: various internal refactoring
21
+
22
+ ## 2.2.1 (2022-02-09)
23
+
24
+ - !158 include the submission score in the json and pdf
25
+
26
+ ## 2.2.0 (2022-02-04)
27
+
28
+ - !153 fix rendering of arrays of primitive values
29
+ - !152 Update @raytio/core to v9 to fix a bug with `hashed_n_id`
30
+ - !155, !154, !146, !147, !150, !151 automated dependency updates
31
+
10
32
  ## 2.1.3 (2021-10-08)
11
33
 
12
- - !126 Add more logging to `saveToS3Bucket`
34
+ - !134 Add more logging to `saveToS3Bucket`
35
+ - !129, !131, !132, !133 automated dependency updates
13
36
 
14
37
  ## 2.1.2 (2021-09-24)
15
38
 
package/README.md CHANGED
@@ -34,12 +34,9 @@ raytio
34
34
  // if using raytio.saveToS3Bucket, specify the ID of the bucket here
35
35
  S3_BUCKET: "",
36
36
 
37
- // whether the JSON and CSV output should use readable field names instead of the field IDs
38
- READABLE_FIELD_NAMES: true,
39
-
40
37
  // the credentials of an organization user
41
- USERNAME: "...",
42
- PASSWORD: "...",
38
+ RAYTIO_USERNAME: "...",
39
+ RAYTIO_PASSWORD: "...",
43
40
 
44
41
  // used when generating a PDF report, if not supplied defaults to "en-NZ" and "Pacific/Auckland"
45
42
  // for available timezone options, see the map on https://momentjs.com/timezone
@@ -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;
@@ -43,7 +43,7 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
43
43
  // [nId: NId, fieldName: string, file: RaytFile][]
44
44
  const urnOrEncryptedList = profileObjects.flatMap((PO) => {
45
45
  return Object.entries(PO.properties)
46
- .filter((kv) => (0, file_1.isFile)(kv[1]))
46
+ .filter((kv) => (0, file_1.isFieldValueFile)(kv[1]))
47
47
  .map(([k, v]) => {
48
48
  return [
49
49
  PO.n_id,
@@ -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);
@@ -24,11 +24,11 @@ function signIn(CONFIG, envConfig) {
24
24
  userPoolWebClientId: envConfig.cognito_web_client_id,
25
25
  });
26
26
  const userObj = yield auth_1.default.signIn({
27
- username: CONFIG.USERNAME,
28
- password: yield (0, core_1.hashPassword)(CONFIG.PASSWORD),
27
+ username: CONFIG.RAYTIO_USERNAME,
28
+ password: yield (0, core_1.hashPassword)(CONFIG.RAYTIO_PASSWORD),
29
29
  });
30
30
  if (userObj.challengeName === "SOFTWARE_TOKEN_MFA") {
31
- throw new Error(`The configured account (${CONFIG.USERNAME}) has two factor authentication enabled. You must disable 2FA or use a different account`);
31
+ throw new Error(`The configured account (${CONFIG.RAYTIO_USERNAME}) has two factor authentication enabled. You must disable 2FA or use a different account`);
32
32
  }
33
33
  const user = yield auth_1.default.currentAuthenticatedUser();
34
34
  const apiToken = (_b = (_a = user.signInUserSession) === null || _a === void 0 ? void 0 : _a.idToken) === null || _b === void 0 ? void 0 : _b.jwtToken;
@@ -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[];
@@ -10,8 +11,10 @@ export declare const ATTRIBUTE_MAP: {
10
11
  export declare const VERIFICATION_SCHEMA = "ss_Verification";
11
12
  export declare const INSTANCE_FIELDS_TO_REMOVE: readonly ["profile_objects", "relationships", "keys"];
12
13
  export declare const FIELDS_TO_REMOVE: readonly ["n_id", "document"];
13
- export declare const ENV_VARIABLES: readonly ["CLIENT_URL", "READABLE_FIELD_NAMES", "USERNAME", "PASSWORD"];
14
+ export declare const ENV_VARIABLES: readonly ["CLIENT_URL", "RAYTIO_USERNAME", "RAYTIO_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>;
package/dist/constants.js CHANGED
@@ -19,9 +19,8 @@ exports.INSTANCE_FIELDS_TO_REMOVE = [
19
19
  exports.FIELDS_TO_REMOVE = ["n_id", "document"];
20
20
  exports.ENV_VARIABLES = [
21
21
  "CLIENT_URL",
22
- "READABLE_FIELD_NAMES",
23
- "USERNAME",
24
- "PASSWORD",
22
+ "RAYTIO_USERNAME",
23
+ "RAYTIO_PASSWORD",
25
24
  ];
26
25
  exports.PO_VER_TEXT_MAP = {
27
26
  [types_1.POVerification.FullyVerified]: "Fully Verified",
@@ -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 = [];
@@ -51,7 +55,7 @@ describe("formatOutput", () => {
51
55
  it("uses schema_group to group schema", () => __awaiter(void 0, void 0, void 0, function* () {
52
56
  const output = yield (0, formatOutput_1.formatOutput)(profileObjects, allSchemas, realVers, "[apiToken]",
53
57
  // @ts-expect-error testing if it works with booleans not stringied bools
54
- { READABLE_FIELD_NAMES: false }, Symbol.for("envConfig"));
58
+ Symbol.for("envConfig"));
55
59
  expect(output).toStrictEqual({
56
60
  DL: [
57
61
  {
@@ -73,11 +77,7 @@ describe("formatOutput", () => {
73
77
  },
74
78
  $safeHarbour: "NOT_APPLICABLE",
75
79
  $schemaName: "ss_nz_drivers_license",
76
- // legacy
77
- issuer: "NZTA",
78
- "issuer.verification": undefined,
79
- license_number: "DW012345",
80
- "license_number.verification": undefined,
80
+ $schemaTitle: "NZ Drivers License",
81
81
  },
82
82
  {
83
83
  $verification_details: Symbol.for("VerificationDetails"),
@@ -98,11 +98,7 @@ describe("formatOutput", () => {
98
98
  },
99
99
  $safeHarbour: "NOT_APPLICABLE",
100
100
  $schemaName: "ss_nsw_drivers_license",
101
- // legacy
102
- city: "Sydney",
103
- "city.verification": undefined,
104
- license_number: "ABC123",
105
- "license_number.verification": undefined,
101
+ $schemaTitle: "NSW Drivers License",
106
102
  },
107
103
  ],
108
104
  ss_name: [
@@ -125,99 +121,7 @@ describe("formatOutput", () => {
125
121
  },
126
122
  $safeHarbour: "NOT_APPLICABLE",
127
123
  $schemaName: "ss_name",
128
- // legacy
129
- fName: "john",
130
- "fName.verification": undefined,
131
- lName: "doe",
132
- "lName.verification": undefined,
133
- },
134
- ],
135
- });
136
- }));
137
- it("doesn't use schema_group if READABLE_FIELD_NAMES is true", () => __awaiter(void 0, void 0, void 0, function* () {
138
- const output = yield (0, formatOutput_1.formatOutput)(profileObjects, allSchemas, realVers, "[apiToken]",
139
- // @ts-expect-error testing if it works with booleans not stringied bools
140
- { READABLE_FIELD_NAMES: true }, Symbol.for("envConfig"));
141
- expect(output).toStrictEqual({
142
- "NSW Drivers License": [
143
- {
144
- $verification_details: Symbol.for("VerificationDetails"),
145
- $verified: types_1.POVerification.NotVerified,
146
- $shouldBeVerifiedFields: undefined,
147
- $nId: "n3",
148
- $properties: {
149
- city: {
150
- title: "city",
151
- value: "Sydney",
152
- verification: undefined,
153
- },
154
- license_number: {
155
- title: "license_number",
156
- value: "ABC123",
157
- verification: undefined,
158
- },
159
- },
160
- $safeHarbour: "NOT_APPLICABLE",
161
- $schemaName: "ss_nsw_drivers_license",
162
- // legacy
163
- city: "Sydney",
164
- "city Verification": undefined,
165
- license_number: "ABC123",
166
- "license_number Verification": undefined,
167
- },
168
- ],
169
- "NZ Drivers License": [
170
- {
171
- $verification_details: Symbol.for("VerificationDetails"),
172
- $verified: types_1.POVerification.NotVerified,
173
- $shouldBeVerifiedFields: undefined,
174
- $nId: "n2",
175
- $properties: {
176
- issuer: {
177
- title: "issuer",
178
- value: "NZTA",
179
- verification: undefined,
180
- },
181
- license_number: {
182
- title: "license_number",
183
- value: "DW012345",
184
- verification: undefined,
185
- },
186
- },
187
- $safeHarbour: "NOT_APPLICABLE",
188
- $schemaName: "ss_nz_drivers_license",
189
- // legacy
190
- issuer: "NZTA",
191
- "issuer Verification": undefined,
192
- license_number: "DW012345",
193
- "license_number Verification": undefined,
194
- },
195
- ],
196
- "Your Name": [
197
- {
198
- $verification_details: Symbol.for("VerificationDetails"),
199
- $verified: types_1.POVerification.NotVerified,
200
- $shouldBeVerifiedFields: undefined,
201
- $nId: "n1",
202
- $properties: {
203
- fName: {
204
- title: "fName",
205
- value: "john",
206
- verification: undefined,
207
- },
208
- lName: {
209
- title: "lName",
210
- value: "doe",
211
- verification: undefined,
212
- },
213
- },
214
- $safeHarbour: "NOT_APPLICABLE",
215
- $schemaName: "ss_name",
216
- // legacy
217
- fName: "john",
218
- "fName Verification": undefined,
219
- lName: "doe",
220
- "lName Verification": undefined,
124
+ $schemaTitle: "Your Name",
221
125
  },
222
126
  ],
223
127
  });
@@ -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
  });
@@ -1,4 +1,5 @@
1
1
  import type { Encrypted, NId, Urn } from "@raytio/types";
2
+ import type { FlatPO } from "./formatOutput";
2
3
  export declare type RaytFile = {
3
4
  n_id: NId;
4
5
  content: Urn | Encrypted;
@@ -6,4 +7,7 @@ export declare type RaytFile = {
6
7
  n_id: NId;
7
8
  Content: Urn | Encrypted;
8
9
  };
9
- export declare const isFile: (field: unknown) => field is RaytFile;
10
+ /** checks if a field value is a file */
11
+ export declare const isFieldValueFile: (fieldValue: unknown) => fieldValue is RaytFile;
12
+ /** checks if a PO is a file */
13
+ export declare const isPOFile: (PO: FlatPO) => boolean;
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFile = void 0;
3
+ exports.isPOFile = exports.isFieldValueFile = void 0;
4
4
  const core_1 = require("@raytio/core");
5
5
  const URN_PREFIX = "urn:";
6
6
  /** @internal */
7
7
  const isObject = (x) => !!x && typeof x === "object";
8
8
  /** @internal */
9
9
  const isUrnOrEncrypted = (x) => (typeof x === "string" && x.startsWith(URN_PREFIX)) || (0, core_1.isEncrypted)(x);
10
- const isFile = (field) => isObject(field) &&
11
- (isUrnOrEncrypted(field.content) || isUrnOrEncrypted(field.Content));
12
- exports.isFile = isFile;
10
+ /** checks if a field value is a file */
11
+ const isFieldValueFile = (fieldValue) => isObject(fieldValue) &&
12
+ "content" in fieldValue &&
13
+ isUrnOrEncrypted(fieldValue.content);
14
+ exports.isFieldValueFile = isFieldValueFile;
15
+ /** checks if a PO is a file */
16
+ const isPOFile = (PO) => { var _a; return (0, exports.isFieldValueFile)({ content: (_a = PO.$properties.content) === null || _a === void 0 ? void 0 : _a.value }); };
17
+ exports.isPOFile = isPOFile;
@@ -1,13 +1,19 @@
1
- import type { NId, POVerification, ProfileObject, RealVer, Schema } from "@raytio/types";
1
+ import type { FieldVerification, NId, POVerification, ProfileObject, RealVer, Schema } from "@raytio/types";
2
2
  import { ResolvedVerificationProvider, EnvConfig } from "../api";
3
- import { Config } from "../constants";
4
3
  export declare type FlatPO = {
5
4
  $verified: POVerification;
6
5
  $verification_details: ResolvedVerificationProvider | undefined;
7
6
  $shouldBeVerifiedFields: string[] | undefined;
8
7
  $nId: NId;
9
8
  $schemaName: string;
9
+ $schemaTitle: string;
10
+ $properties: {
11
+ [fieldName: string]: {
12
+ title: string;
13
+ value: unknown;
14
+ verification: FieldVerification;
15
+ };
16
+ };
10
17
  $safeHarbour: boolean | "NOT_APPLICABLE";
11
- [schemaField: string]: any;
12
18
  };
13
- export declare function formatOutput(profileObjects: ProfileObject[], allSchemas: Schema[], realVers: RealVer[], apiToken: string, CONFIG: Config, envConfig: EnvConfig): Promise<Record<string, FlatPO[]>>;
19
+ export declare function formatOutput(profileObjects: ProfileObject[], allSchemas: Schema[], realVers: RealVer[], apiToken: string, envConfig: EnvConfig): Promise<Record<string, FlatPO[]>>;
@@ -15,17 +15,18 @@ 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;
23
26
  return aPriority - bPriority;
24
27
  };
25
- // TODO: clean up
26
- function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, envConfig) {
28
+ function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig) {
27
29
  return __awaiter(this, void 0, void 0, function* () {
28
- const readable = CONFIG.READABLE_FIELD_NAMES.toString() === "true";
29
30
  const PODetails = profileObjects.reduce((acPromise, PO) => __awaiter(this, void 0, void 0, function* () {
30
31
  var _a, _b;
31
32
  const ac = yield acPromise;
@@ -36,11 +37,13 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, en
36
37
  const verDetails = (0, core_1.getPOVerification)({ PO, schema, realVers });
37
38
  const realProps = (0, ramda_1.omit)(constants_1.FIELDS_TO_REMOVE, PO.properties);
38
39
  const schemaNameOrGroup = (_a = schema.schema_group) !== null && _a !== void 0 ? _a : schema.name;
40
+ (0, types_1.assertSafeProperty)(schemaNameOrGroup);
39
41
  const existing = ac[schemaNameOrGroup] || [];
40
42
  const poProperties = Object.entries(realProps).sort(byPriority(schema));
41
43
  const reducedProperties = yield poProperties.reduce((acc, [key, value]) => __awaiter(this, void 0, void 0, function* () {
42
44
  var _c, _d;
43
45
  const accP = yield acc;
46
+ (0, types_1.assertSafeProperty)(key);
44
47
  return Object.assign(Object.assign({}, accP), { [key]: {
45
48
  title: ((_d = (_c = schema.properties) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.title) || key,
46
49
  value: typeof value === "string"
@@ -49,31 +52,24 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, en
49
52
  verification: verDetails.fieldVerifications[key],
50
53
  } });
51
54
  }), Promise.resolve({}));
52
- const thisPO = Object.assign({
53
- // 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),
55
- // these are not included in the CSV for legacy reasons
56
- $nId: PO.n_id, $schemaName: schemaName, $properties: reducedProperties, $safeHarbour: schemaName === "ss_Person_Name"
55
+ const thisPO = {
56
+ $verified: verDetails.status,
57
+ $verification_details: yield (0, api_1.resolveVerificationDetails)(verDetails.details.verifiers, apiToken, envConfig),
58
+ $shouldBeVerifiedFields: (_b = schema.verified_fields) === null || _b === void 0 ? void 0 : _b.map((x) => typeof x === "string" ? x : x.field),
59
+ $nId: PO.n_id,
60
+ $schemaName: schemaName,
61
+ $schemaTitle: schema.title,
62
+ $properties: reducedProperties,
63
+ $safeHarbour: schemaName === "ss_Person_Name"
57
64
  ? (yield (0, core_1.calcSafeHarbourScore)({
58
65
  person: PO,
59
- getSchema: (name) => (0, api_1.getSchema)(envConfig, apiToken, name),
66
+ getSchema: (name) => (0, api_1.getSchema)(envConfig, name),
60
67
  profileObjects,
61
68
  realVers,
62
69
  })).isSafe
63
- : "NOT_APPLICABLE" }, Object.entries(realProps)
64
- .sort(byPriority(schema))
65
- .reduce((acc, [key, value]) => {
66
- var _a, _b;
67
- const title = readable
68
- ? ((_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.title) || key
69
- : key;
70
- const titleV = readable
71
- ? `${title} Verification`
72
- : `${title}.verification`;
73
- return Object.assign(Object.assign({}, acc), { [title]: value, [titleV]: verDetails.fieldVerifications[key] });
74
- }, {}));
75
- const schemaTitle = (readable && schema.title) || schemaNameOrGroup;
76
- return Object.assign(Object.assign({}, ac), { [schemaTitle]: [...existing, thisPO] });
70
+ : "NOT_APPLICABLE",
71
+ };
72
+ return Object.assign(Object.assign({}, ac), { [schemaNameOrGroup]: [...existing, thisPO] });
77
73
  }), Promise.resolve({}));
78
74
  return PODetails;
79
75
  });
@@ -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>;
@@ -21,7 +21,7 @@ function setupMaxcryptor(CONFIG, cognitoAttributes) {
21
21
  return acc;
22
22
  return (0, ramda_1.assocPath)(constants_1.ATTRIBUTE_MAP[Name], JSON.parse(Value), acc);
23
23
  }, {});
24
- const { encryptor: maxcryptor } = yield (0, maxcryptor_1.encryptorFromExistingUser)(userDoc, CONFIG.PASSWORD);
24
+ const { encryptor: maxcryptor } = yield (0, maxcryptor_1.encryptorFromExistingUser)(userDoc, CONFIG.RAYTIO_PASSWORD);
25
25
  return maxcryptor;
26
26
  });
27
27
  }
@@ -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
- import { Files } from "../types";
3
- export declare function Images({ nIds, files, }: {
2
+ import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
3
+ export declare const Images: ({ nIds, files, }: {
4
4
  nIds: string[];
5
- files: Files;
6
- }): JSX.Element;
5
+ files: ProcessSubmissionOutput["files"];
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,11 @@
1
1
  /// <reference types="jsx-pdf" />
2
- import { Files, PdfConfig } from "../types";
3
- export declare function InnerTableRows({ key, value, imageFieldNames, config, files, color, }: {
2
+ import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
3
+ import { PdfConfig } from "../types";
4
+ export declare const InnerTableRows: ({ key, value, imageFieldNames, config, files, color, }: {
4
5
  key: string;
5
6
  value: any;
6
- files: Files;
7
+ files: ProcessSubmissionOutput["files"];
7
8
  config: PdfConfig;
8
9
  color: string;
9
10
  imageFieldNames: string[];
10
- }): JSX.Element;
11
+ }) => 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;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import { POVerification } from "@raytio/types";
3
- import { PdfSchema } from "../types";
3
+ import { FlatPO } from "../../helpers";
4
4
  export declare const FILE_MAP: Record<POVerification, string>;
5
- export declare function POVerificationBadge({ width, schema, }: {
5
+ export declare const POVerificationBadge: ({ width, POs, }: {
6
6
  width: number;
7
- schema: PdfSchema;
8
- }): JSX.Element;
7
+ POs: FlatPO[];
8
+ }) => JSX.Element;
@@ -18,10 +18,9 @@ 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, }) {
22
- const [, profileObjects] = schema;
21
+ const POVerificationBadge = ({ width, POs, }) => {
23
22
  // TODO: this won't work if multiple POs of the same schema are shared
24
- const { $verified, $verification_details, $shouldBeVerifiedFields, $safeHarbour, } = profileObjects[0];
23
+ const { $verified, $verification_details, $shouldBeVerifiedFields, $safeHarbour, } = POs[0];
25
24
  const verifiedBy = $verification_details === null || $verification_details === void 0 ? void 0 : $verification_details.verifier_id;
26
25
  return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
27
26
  $shouldBeVerifiedFields && (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
@@ -39,5 +38,5 @@ function POVerificationBadge({ width, schema, }) {
39
38
  jsx_pdf_1.default.createElement("text", { alignment: "center" },
40
39
  $safeHarbour ? "" : "Not ",
41
40
  "Safe Harbour Compliant"))))));
42
- }
41
+ };
43
42
  exports.POVerificationBadge = POVerificationBadge;
@@ -1,11 +1,12 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import type { AId } from "@raytio/types";
3
- import { Files, PdfConfig, ReportData } from "../types";
4
- export declare function Report({ data, files, config, aId, clientUrl, version, }: {
5
- data: ReportData;
6
- files: Files;
3
+ import { PdfConfig } from "../types";
4
+ import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
5
+ export declare const Report: ({ data, files, config, aId, clientUrl, version, }: {
6
+ data: ProcessSubmissionOutput["json"];
7
+ files: ProcessSubmissionOutput["files"];
7
8
  config: PdfConfig;
8
9
  aId: AId;
9
10
  clientUrl: string;
10
11
  version: string;
11
- }): JSX.Element;
12
+ }) => JSX.Element;
@@ -15,8 +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, }) {
19
- const schemas = Object.entries(data).filter(([, val]) => Array.isArray(val) && val.length && "$verified" in val[0]);
18
+ const Report = ({ data, files, config, aId, clientUrl, version, }) => {
20
19
  // The PDF is read only; there's no reason why anyone would ever need to unlock it.
21
20
  const randomToken = (0, crypto_1.randomBytes)(32).toString("base64");
22
21
  return (jsx_pdf_1.default.createElement("document", { defaultStyle: { font: "Lato", fontSize: 12 }, info: {
@@ -39,25 +38,30 @@ function Report({ data, files, config, aId, clientUrl, version, }) {
39
38
  jsx_pdf_1.default.createElement("text", { style: ["header", "marginBottom"], alignment: "center" }, "Raytio Verification Report"),
40
39
  jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
41
40
  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")),
41
+ jsx_pdf_1.default.createElement("text", { style: ["subheader", "marginBottom"] },
42
+ Object.entries(constants_1.SUBMISSION_DATA)
43
+ .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
44
+ .join("\n"),
45
+ data.score
46
+ ? `\nScore: ${data.score.score}\nScore Category: ${data.score.category}`
47
+ : ""),
45
48
  jsx_pdf_1.default.createElement(Subheader_1.Subheader, { data: data, config: config })),
46
49
  jsx_pdf_1.default.createElement("column", { width: "*" },
47
50
  jsx_pdf_1.default.createElement("text", null, " ")),
48
51
  jsx_pdf_1.default.createElement("column", { width: 150 },
49
52
  jsx_pdf_1.default.createElement(VerifyBox_1.VerifyBox, { aId: aId, iId: data.i_id, clientUrl: clientUrl }))),
50
- schemas.map((schema) => {
53
+ Object.values(data.profile_objects).map((POs) => {
54
+ // for each schema
51
55
  return (jsx_pdf_1.default.createElement("stack", {
52
56
  // unbreakable is off because it crashes if its too big for one page
53
- // TODO: PR to pdfmake to fix this
57
+ // This is a 7-year-old issue in pdfmake (https://github.com/bpampuch/pdfmake/issues/207)
54
58
  unbreakable: false, style: "marginY" },
55
- jsx_pdf_1.default.createElement(TableTitle_1.TableTitle, { schema: schema }),
59
+ jsx_pdf_1.default.createElement(TableTitle_1.TableTitle, { POs: POs }),
56
60
  jsx_pdf_1.default.createElement("columns", { columnGap: 15 },
57
61
  jsx_pdf_1.default.createElement("column", { width: 80 },
58
- jsx_pdf_1.default.createElement(POVerificationBadge_1.POVerificationBadge, { width: 80, schema: schema })),
62
+ jsx_pdf_1.default.createElement(POVerificationBadge_1.POVerificationBadge, { width: 80, POs: POs })),
59
63
  jsx_pdf_1.default.createElement("column", { width: "auto" },
60
- jsx_pdf_1.default.createElement(Table_1.Table, { schema: schema, files: files, config: config })))));
64
+ jsx_pdf_1.default.createElement(Table_1.Table, { POs: POs, files: files, config: config })))));
61
65
  })),
62
66
  jsx_pdf_1.default.createElement("footer", null, (currentPage, pageCount, pageSize) => (jsx_pdf_1.default.createElement("stack", { bold: true, color: "#333", fontSize: 10 },
63
67
  jsx_pdf_1.default.createElement("text", { margin: 16 },
@@ -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,9 @@
1
1
  /// <reference types="jsx-pdf" />
2
- import { PdfSchema, Files, PdfConfig } from "../types";
3
- export declare function Table({ schema, files, config, }: {
4
- schema: PdfSchema;
5
- files: Files;
2
+ import { PdfConfig } from "../types";
3
+ import { FlatPO } from "../../helpers";
4
+ import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
5
+ export declare const Table: ({ POs, files, config, }: {
6
+ POs: FlatPO[];
7
+ files: ProcessSubmissionOutput["files"];
6
8
  config: PdfConfig;
7
- }): JSX.Element;
9
+ }) => JSX.Element;
@@ -10,35 +10,33 @@ 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, }) {
14
- const [, profileObjects] = schema;
15
- /** every fieldName in this profile object */
13
+ const Table = ({ POs, files, config, }) => {
14
+ /** every fieldName in these profile object */
16
15
  const fieldNames = [
17
- ...new Set(profileObjects
18
- .flatMap(Object.keys)
19
- .filter((x) => !x.startsWith("$") &&
20
- !x.endsWith(".verification") &&
21
- !x.endsWith(" Verification"))),
16
+ ...new Set(POs.flatMap((PO) => Object.keys(PO.$properties))),
22
17
  ];
23
18
  // some or all POs in this schema are files themselves. So render the file, assuming it's an image
24
- const fileNIds = profileObjects.filter(helpers_1.isFile).map((x) => x.n_id);
19
+ const fileNIds = POs.filter(helpers_1.isPOFile).map((x) => x.$nId);
25
20
  if (fileNIds.length)
26
21
  return jsx_pdf_1.default.createElement(Images_1.Images, { nIds: fileNIds, files: files });
27
- const imageFieldNames = fieldNames.filter((x) => profileObjects.map((PO) => PO[x]).some(helpers_1.isFile));
28
- return (jsx_pdf_1.default.createElement("table", { layout: "noBorders" }, fieldNames.map((fieldName) => (jsx_pdf_1.default.createElement("row", null,
29
- jsx_pdf_1.default.createElement("cell", null,
30
- jsx_pdf_1.default.createElement("text", { color: "#12130e" }, fieldName.replace(/_/g, " "))),
31
- profileObjects.flatMap((PO) => {
32
- const status = PO[`${fieldName}.verification`] ||
33
- PO[`${fieldName} Verification`];
34
- const color = (0, general_1.verifyColour)(status);
35
- // jsx-pdf currently doesn't support fragments, will make a PR at some point
36
- return [
37
- jsx_pdf_1.default.createElement("cell", null,
38
- jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: status })),
39
- jsx_pdf_1.default.createElement("cell", null,
40
- jsx_pdf_1.default.createElement(InnerTableRows_1.InnerTableRows, { key: fieldName, value: PO[fieldName], files: files, config: config, color: color, imageFieldNames: imageFieldNames })),
41
- ];
42
- }))))));
43
- }
22
+ const imageFieldNames = fieldNames.filter((fieldName) => POs.map((PO) => { var _a; return (_a = PO.$properties[fieldName]) === null || _a === void 0 ? void 0 : _a.value; }).some(helpers_1.isFieldValueFile));
23
+ return (jsx_pdf_1.default.createElement("table", { layout: "noBorders" }, fieldNames.map((fieldName) => {
24
+ var _a;
25
+ return (jsx_pdf_1.default.createElement("row", null,
26
+ jsx_pdf_1.default.createElement("cell", null,
27
+ jsx_pdf_1.default.createElement("text", { color: "#12130e" }, ((_a = POs.find((PO) => PO.$properties[fieldName])) === null || _a === void 0 ? void 0 : _a.$properties[fieldName].title) || fieldName)),
28
+ POs.filter((PO) => PO.$properties[fieldName]).flatMap((PO) => {
29
+ (0, helpers_1.assertSafeProperty)(fieldName);
30
+ const { value, verification } = PO.$properties[fieldName];
31
+ const color = (0, general_1.verifyColour)(verification);
32
+ // jsx-pdf currently doesn't support fragments, will make a PR at some point
33
+ return [
34
+ jsx_pdf_1.default.createElement("cell", null,
35
+ jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: verification })),
36
+ jsx_pdf_1.default.createElement("cell", null,
37
+ jsx_pdf_1.default.createElement(InnerTableRows_1.InnerTableRows, { key: fieldName, value: value, files: files, config: config, color: color, imageFieldNames: imageFieldNames })),
38
+ ];
39
+ })));
40
+ })));
41
+ };
44
42
  exports.Table = Table;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="jsx-pdf" />
2
- import { PdfSchema } from "../types";
3
- export declare function TableTitle({ schema }: {
4
- schema: PdfSchema;
5
- }): JSX.Element;
2
+ import { FlatPO } from "../../helpers";
3
+ export declare const TableTitle: ({ POs }: {
4
+ POs: FlatPO[];
5
+ }) => JSX.Element;
@@ -6,9 +6,12 @@ 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 }) {
10
- const [schemaTitle, POs] = schema;
11
- const maybeFileName = POs.some(helpers_1.isFile) && (POs[0].title || POs[0].Title);
9
+ const TableTitle = ({ POs }) => {
10
+ var _a;
11
+ const schemaTitle = POs[0].$schemaTitle;
12
+ const maybeFileName = POs.some(helpers_1.isPOFile)
13
+ ? (_a = POs[0].$properties.title) === null || _a === void 0 ? void 0 : _a.value
14
+ : undefined;
12
15
  return (jsx_pdf_1.default.createElement("text", { bold: true, fontSize: 14, style: "marginBottom" }, maybeFileName || schemaTitle));
13
- }
16
+ };
14
17
  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,20 +4,25 @@ 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;
11
- // TODO: clean this up
12
- /* eslint-disable no-nested-ternary */
13
- const verifyColour = (x) => x === types_1.FieldVerification.Verified
14
- ? "#12130e"
15
- : x === types_1.FieldVerification.VerifiedFalse ||
16
- x === types_1.POVerification.VerifiedFalse
17
- ? "#fb7171"
18
- : "#000";
16
+ const verifyColour = (x) => {
17
+ if (x === types_1.FieldVerification.Verified)
18
+ return "#12130e";
19
+ if (x === types_1.FieldVerification.VerifiedFalse ||
20
+ x === types_1.POVerification.VerifiedFalse) {
21
+ return "#fb7171";
22
+ }
23
+ return "#000";
24
+ };
19
25
  exports.verifyColour = verifyColour;
20
- /* eslint-enable no-nested-ternary */
21
26
  /**
22
27
  * Produces a date with a long month
23
28
  */
@@ -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
  }
@@ -1,5 +1,6 @@
1
1
  import type { AId, IId, Instance, ProfileObject, RealVer, Schema } from "@raytio/types";
2
2
  import { Config, InstanceDataToPassOn } from "../constants";
3
+ import { FlatPO } from "../helpers";
3
4
  import { ApplicationEncryptorLike } from "../types";
4
5
  declare type DecryptData = {
5
6
  apiToken: string;
@@ -23,7 +24,11 @@ export interface ProcessSubmissionInput {
23
24
  }
24
25
  export interface ProcessSubmissionOutput {
25
26
  /** details of the submission, included the decrypted profile objects */
26
- json: InstanceDataToPassOn & Record<string, any>;
27
+ json: InstanceDataToPassOn & {
28
+ profile_objects: {
29
+ [schemaName: string]: FlatPO[];
30
+ };
31
+ };
27
32
  /** A string of a CSV file containing the same data as in `json` */
28
33
  csv: string;
29
34
  /** an object of files that were attached to the submission, such as images */
@@ -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,35 +57,45 @@ 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
- // TODO: resolve URNs if any fields are URNs
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
+ }
61
79
  log("Fetching verification providers...");
62
- const PODetails = yield (0, helpers_1.formatOutput)(profileObjects, allSchemas, realVers, apiToken, config, envConfig);
80
+ const PODetails = yield (0, helpers_1.formatOutput)(profileObjects, allSchemas, realVers, apiToken, envConfig);
63
81
  log("Fetching attached files...");
64
82
  const files = yield (0, api_1.getFiles)(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
65
83
  const instanceDataToPassOn = (0, ramda_1.omit)(constants_1.INSTANCE_FIELDS_TO_REMOVE, instance);
66
84
  // 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)(
68
- // TODO: (semver breaking) we omit these fields because it would a breaking change for the csv format.
69
- (v) => v.map((a) => {
70
- // TODO: (semver breaking) map the verification enums to the text to prevent a breaking change
71
- const b = Object.assign(Object.assign({}, (0, ramda_1.omit)([
72
- "$nId",
73
- "$schemaName",
74
- "$properties",
75
- "$shouldBeVerifiedFields",
76
- ], a)), { $verified: constants_1.PO_VER_TEXT_MAP[a.$verified] });
77
- return (0, ramda_1.mapObjIndexed)((fieldVal, fieldName) => {
78
- if (fieldName.endsWith(" Verification") ||
79
- fieldName.endsWith(".verification")) {
80
- return constants_1.FIELD_VER_TEXT_MAP[+fieldVal];
81
- }
82
- return fieldVal;
83
- }, b);
85
+ const csv = (0, helpers_1.deepJsonToCsv)(Object.assign(Object.assign({}, instanceDataToPassOn), (0, ramda_1.mapObjIndexed)((POList) => POList.map((flatPO) => {
86
+ // this is a bit weird, but it prevents an even bigger breaking change for the csv format
87
+ const obj = Object.entries(flatPO.$properties).flatMap(([fieldName, field]) => [
88
+ [fieldName, field.value],
89
+ [
90
+ `${fieldName}.verification`,
91
+ constants_1.FIELD_VER_TEXT_MAP[field.verification],
92
+ ],
93
+ ]);
94
+ return Object.assign(Object.assign(Object.assign({}, flatPO), { $verified: constants_1.PO_VER_TEXT_MAP[flatPO.$verified] }), Object.fromEntries(obj));
84
95
  }), PODetails)));
85
96
  log("Success!");
86
97
  return {
87
- json: Object.assign(Object.assign({}, instanceDataToPassOn), PODetails),
98
+ json: Object.assign(Object.assign({}, instanceDataToPassOn), { score, profile_objects: PODetails }),
88
99
  csv,
89
100
  files,
90
101
  a_id: applicationId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "2.1.3",
3
+ "version": "3.0.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.2",
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.33",
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.2",
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.18",
41
+ "@types/node": "^16.11.24",
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.3.0",
48
- "jest": "^27.2.1",
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.3.0",
48
+ "jest": "^27.5.1",
49
49
  "jest-image-snapshot": "^4.5.1",
50
50
  "jest-junit": "^13.0.0",
51
- "pdf-to-img": "^1.1.1",
52
- "ts-jest": "^27.0.5",
53
- "ts-node": "^10.2.1",
54
- "typescript": "^4.4.3"
51
+ "pdf-to-img": "^1.2.0",
52
+ "ts-jest": "^27.1.3",
53
+ "ts-node": "^10.5.0",
54
+ "typescript": "^4.5.5"
55
55
  },
56
56
  "eslintConfig": {
57
57
  "extends": "kyle",