@raytio/decrypt-helper 2.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 3.0.0 (2022-02-04)
11
+
12
+ - 💥 BREAKING CHANGE: renamed the `USERNAME` & `PASSWORD` environment variables to `RAYTIO_USERNAME` & `RAYTIO_PASSWORD`
13
+ - 💥 BREAKING CHANGE: removed the `READABLE_FIELD_NAMES` option
14
+ - 💥 BREAKING CHANGE: [csv] added new columns, shifted other columns
15
+ - 💥 BREAKING CHANGE: [json] removed some duplicate legacy fields, see #33
16
+ - !156: various internal refactoring
17
+
10
18
  ## 2.2.1 (2022-02-09)
11
19
 
12
20
  - !158 include the submission score in the json and pdf
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
@@ -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,
@@ -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;
@@ -11,7 +11,7 @@ export declare const ATTRIBUTE_MAP: {
11
11
  export declare const VERIFICATION_SCHEMA = "ss_Verification";
12
12
  export declare const INSTANCE_FIELDS_TO_REMOVE: readonly ["profile_objects", "relationships", "keys"];
13
13
  export declare const FIELDS_TO_REMOVE: readonly ["n_id", "document"];
14
- 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"];
15
15
  export declare type Config = Record<typeof ENV_VARIABLES[number], string>;
16
16
  export declare type InstanceDataToPassOn = Omit<Instance, typeof INSTANCE_FIELDS_TO_REMOVE[number]> & {
17
17
  score?: ScoreResult;
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",
@@ -55,7 +55,7 @@ describe("formatOutput", () => {
55
55
  it("uses schema_group to group schema", () => __awaiter(void 0, void 0, void 0, function* () {
56
56
  const output = yield (0, formatOutput_1.formatOutput)(profileObjects, allSchemas, realVers, "[apiToken]",
57
57
  // @ts-expect-error testing if it works with booleans not stringied bools
58
- { READABLE_FIELD_NAMES: false }, Symbol.for("envConfig"));
58
+ Symbol.for("envConfig"));
59
59
  expect(output).toStrictEqual({
60
60
  DL: [
61
61
  {
@@ -77,11 +77,7 @@ describe("formatOutput", () => {
77
77
  },
78
78
  $safeHarbour: "NOT_APPLICABLE",
79
79
  $schemaName: "ss_nz_drivers_license",
80
- // legacy
81
- issuer: "NZTA",
82
- "issuer.verification": undefined,
83
- license_number: "DW012345",
84
- "license_number.verification": undefined,
80
+ $schemaTitle: "NZ Drivers License",
85
81
  },
86
82
  {
87
83
  $verification_details: Symbol.for("VerificationDetails"),
@@ -102,11 +98,7 @@ describe("formatOutput", () => {
102
98
  },
103
99
  $safeHarbour: "NOT_APPLICABLE",
104
100
  $schemaName: "ss_nsw_drivers_license",
105
- // legacy
106
- city: "Sydney",
107
- "city.verification": undefined,
108
- license_number: "ABC123",
109
- "license_number.verification": undefined,
101
+ $schemaTitle: "NSW Drivers License",
110
102
  },
111
103
  ],
112
104
  ss_name: [
@@ -129,99 +121,7 @@ describe("formatOutput", () => {
129
121
  },
130
122
  $safeHarbour: "NOT_APPLICABLE",
131
123
  $schemaName: "ss_name",
132
- // legacy
133
- fName: "john",
134
- "fName.verification": undefined,
135
- lName: "doe",
136
- "lName.verification": undefined,
137
- },
138
- ],
139
- });
140
- }));
141
- it("doesn't use schema_group if READABLE_FIELD_NAMES is true", () => __awaiter(void 0, void 0, void 0, function* () {
142
- const output = yield (0, formatOutput_1.formatOutput)(profileObjects, allSchemas, realVers, "[apiToken]",
143
- // @ts-expect-error testing if it works with booleans not stringied bools
144
- { READABLE_FIELD_NAMES: true }, Symbol.for("envConfig"));
145
- expect(output).toStrictEqual({
146
- "NSW Drivers License": [
147
- {
148
- $verification_details: Symbol.for("VerificationDetails"),
149
- $verified: types_1.POVerification.NotVerified,
150
- $shouldBeVerifiedFields: undefined,
151
- $nId: "n3",
152
- $properties: {
153
- city: {
154
- title: "city",
155
- value: "Sydney",
156
- verification: undefined,
157
- },
158
- license_number: {
159
- title: "license_number",
160
- value: "ABC123",
161
- verification: undefined,
162
- },
163
- },
164
- $safeHarbour: "NOT_APPLICABLE",
165
- $schemaName: "ss_nsw_drivers_license",
166
- // legacy
167
- city: "Sydney",
168
- "city Verification": undefined,
169
- license_number: "ABC123",
170
- "license_number Verification": undefined,
171
- },
172
- ],
173
- "NZ Drivers License": [
174
- {
175
- $verification_details: Symbol.for("VerificationDetails"),
176
- $verified: types_1.POVerification.NotVerified,
177
- $shouldBeVerifiedFields: undefined,
178
- $nId: "n2",
179
- $properties: {
180
- issuer: {
181
- title: "issuer",
182
- value: "NZTA",
183
- verification: undefined,
184
- },
185
- license_number: {
186
- title: "license_number",
187
- value: "DW012345",
188
- verification: undefined,
189
- },
190
- },
191
- $safeHarbour: "NOT_APPLICABLE",
192
- $schemaName: "ss_nz_drivers_license",
193
- // legacy
194
- issuer: "NZTA",
195
- "issuer Verification": undefined,
196
- license_number: "DW012345",
197
- "license_number Verification": undefined,
198
- },
199
- ],
200
- "Your Name": [
201
- {
202
- $verification_details: Symbol.for("VerificationDetails"),
203
- $verified: types_1.POVerification.NotVerified,
204
- $shouldBeVerifiedFields: undefined,
205
- $nId: "n1",
206
- $properties: {
207
- fName: {
208
- title: "fName",
209
- value: "john",
210
- verification: undefined,
211
- },
212
- lName: {
213
- title: "lName",
214
- value: "doe",
215
- verification: undefined,
216
- },
217
- },
218
- $safeHarbour: "NOT_APPLICABLE",
219
- $schemaName: "ss_name",
220
- // legacy
221
- fName: "john",
222
- "fName Verification": undefined,
223
- lName: "doe",
224
- "lName Verification": undefined,
124
+ $schemaTitle: "Your Name",
225
125
  },
226
126
  ],
227
127
  });
@@ -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[]>>;
@@ -25,10 +25,8 @@ const byPriority = (schema) => ([a], [b]) => {
25
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;
26
26
  return aPriority - bPriority;
27
27
  };
28
- // TODO: clean up
29
- function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, envConfig) {
28
+ function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig) {
30
29
  return __awaiter(this, void 0, void 0, function* () {
31
- const readable = CONFIG.READABLE_FIELD_NAMES.toString() === "true";
32
30
  const PODetails = profileObjects.reduce((acPromise, PO) => __awaiter(this, void 0, void 0, function* () {
33
31
  var _a, _b;
34
32
  const ac = yield acPromise;
@@ -54,33 +52,24 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, en
54
52
  verification: verDetails.fieldVerifications[key],
55
53
  } });
56
54
  }), Promise.resolve({}));
57
- const thisPO = Object.assign({
58
- // these are always included
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),
60
- // these are not included in the CSV for legacy reasons
61
- $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"
62
64
  ? (yield (0, core_1.calcSafeHarbourScore)({
63
65
  person: PO,
64
66
  getSchema: (name) => (0, api_1.getSchema)(envConfig, name),
65
67
  profileObjects,
66
68
  realVers,
67
69
  })).isSafe
68
- : "NOT_APPLICABLE" }, Object.entries(realProps)
69
- .sort(byPriority(schema))
70
- .reduce((acc, [key, value]) => {
71
- var _a, _b;
72
- (0, types_1.assertSafeProperty)(key);
73
- const title = readable
74
- ? ((_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.title) || key
75
- : key;
76
- (0, types_1.assertSafeProperty)(title);
77
- const titleV = readable
78
- ? `${title} Verification`
79
- : `${title}.verification`;
80
- return Object.assign(Object.assign({}, acc), { [title]: value, [titleV]: verDetails.fieldVerifications[key] });
81
- }, {}));
82
- const schemaTitle = (readable && schema.title) || schemaNameOrGroup;
83
- return Object.assign(Object.assign({}, ac), { [schemaTitle]: [...existing, thisPO] });
70
+ : "NOT_APPLICABLE",
71
+ };
72
+ return Object.assign(Object.assign({}, ac), { [schemaNameOrGroup]: [...existing, thisPO] });
84
73
  }), Promise.resolve({}));
85
74
  return PODetails;
86
75
  });
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="jsx-pdf" />
2
- import { Files } from "../types";
2
+ import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
3
3
  export declare const Images: ({ nIds, files, }: {
4
4
  nIds: string[];
5
- files: Files;
5
+ files: ProcessSubmissionOutput["files"];
6
6
  }) => JSX.Element;
@@ -1,9 +1,10 @@
1
1
  /// <reference types="jsx-pdf" />
2
- import { Files, PdfConfig } from "../types";
2
+ import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
3
+ import { PdfConfig } from "../types";
3
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[];
@@ -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 const POVerificationBadge: ({ width, schema, }: {
5
+ export declare const POVerificationBadge: ({ width, POs, }: {
6
6
  width: number;
7
- schema: PdfSchema;
7
+ POs: FlatPO[];
8
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
- const 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,
@@ -1,9 +1,10 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import type { AId } from "@raytio/types";
3
- import { Files, PdfConfig, ReportData } from "../types";
3
+ import { PdfConfig } from "../types";
4
+ import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
4
5
  export declare const Report: ({ data, files, config, aId, clientUrl, version, }: {
5
- data: ReportData;
6
- files: Files;
6
+ data: ProcessSubmissionOutput["json"];
7
+ files: ProcessSubmissionOutput["files"];
7
8
  config: PdfConfig;
8
9
  aId: AId;
9
10
  clientUrl: string;
@@ -16,7 +16,6 @@ const VerifyBox_1 = require("./VerifyBox");
16
16
  const constants_1 = require("../constants");
17
17
  const transform_1 = require("../helpers/transform");
18
18
  const Report = ({ data, files, config, aId, clientUrl, version, }) => {
19
- const schemas = Object.entries(data).filter(([, val]) => Array.isArray(val) && val.length && "$verified" in val[0]);
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: {
@@ -51,17 +50,18 @@ const Report = ({ data, files, config, aId, clientUrl, version, }) => {
51
50
  jsx_pdf_1.default.createElement("text", null, " ")),
52
51
  jsx_pdf_1.default.createElement("column", { width: 150 },
53
52
  jsx_pdf_1.default.createElement(VerifyBox_1.VerifyBox, { aId: aId, iId: data.i_id, clientUrl: clientUrl }))),
54
- schemas.map((schema) => {
53
+ Object.values(data.profile_objects).map((POs) => {
54
+ // for each schema
55
55
  return (jsx_pdf_1.default.createElement("stack", {
56
56
  // unbreakable is off because it crashes if its too big for one page
57
- // TODO: PR to pdfmake to fix this
57
+ // This is a 7-year-old issue in pdfmake (https://github.com/bpampuch/pdfmake/issues/207)
58
58
  unbreakable: false, style: "marginY" },
59
- jsx_pdf_1.default.createElement(TableTitle_1.TableTitle, { schema: schema }),
59
+ jsx_pdf_1.default.createElement(TableTitle_1.TableTitle, { POs: POs }),
60
60
  jsx_pdf_1.default.createElement("columns", { columnGap: 15 },
61
61
  jsx_pdf_1.default.createElement("column", { width: 80 },
62
- 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 })),
63
63
  jsx_pdf_1.default.createElement("column", { width: "auto" },
64
- 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 })))));
65
65
  })),
66
66
  jsx_pdf_1.default.createElement("footer", null, (currentPage, pageCount, pageSize) => (jsx_pdf_1.default.createElement("stack", { bold: true, color: "#333", fontSize: 10 },
67
67
  jsx_pdf_1.default.createElement("text", { margin: 16 },
@@ -1,7 +1,9 @@
1
1
  /// <reference types="jsx-pdf" />
2
- import { PdfSchema, Files, PdfConfig } from "../types";
3
- export declare const 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
9
  }) => JSX.Element;
@@ -10,36 +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
- const 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
- (0, helpers_1.assertSafeProperty)(fieldName);
33
- const status = PO[`${fieldName}.verification`] ||
34
- PO[`${fieldName} Verification`];
35
- const color = (0, general_1.verifyColour)(status);
36
- // jsx-pdf currently doesn't support fragments, will make a PR at some point
37
- return [
38
- jsx_pdf_1.default.createElement("cell", null,
39
- jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: status })),
40
- jsx_pdf_1.default.createElement("cell", null,
41
- jsx_pdf_1.default.createElement(InnerTableRows_1.InnerTableRows, { key: fieldName, value: PO[fieldName], files: files, config: config, color: color, imageFieldNames: imageFieldNames })),
42
- ];
43
- }))))));
22
+ const imageFieldNames = fieldNames.filter((fieldName) => POs.map((PO) => PO.$properties[fieldName].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.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
+ })));
44
41
  };
45
42
  exports.Table = Table;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="jsx-pdf" />
2
- import { PdfSchema } from "../types";
3
- export declare const TableTitle: ({ schema }: {
4
- schema: PdfSchema;
2
+ import { FlatPO } from "../../helpers";
3
+ export declare const TableTitle: ({ POs }: {
4
+ POs: FlatPO[];
5
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
- const 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;
@@ -13,16 +13,16 @@ const asset = (name) => {
13
13
  exports.asset = asset;
14
14
  const loadAsset = (name) => (0, fs_1.readFileSync)((0, exports.asset)(name), { encoding: "utf-8" });
15
15
  exports.loadAsset = loadAsset;
16
- // TODO: clean this up
17
- /* eslint-disable no-nested-ternary */
18
- const verifyColour = (x) => x === types_1.FieldVerification.Verified
19
- ? "#12130e"
20
- : x === types_1.FieldVerification.VerifiedFalse ||
21
- x === types_1.POVerification.VerifiedFalse
22
- ? "#fb7171"
23
- : "#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
+ };
24
25
  exports.verifyColour = verifyColour;
25
- /* eslint-enable no-nested-ternary */
26
26
  /**
27
27
  * Produces a date with a long month
28
28
  */
@@ -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 */
@@ -76,34 +76,26 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
76
76
  else {
77
77
  log("No score rules configured on the AA.");
78
78
  }
79
- // TODO: resolve URNs if any fields are URNs
80
79
  log("Fetching verification providers...");
81
- 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);
82
81
  log("Fetching attached files...");
83
82
  const files = yield (0, api_1.getFiles)(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
84
83
  const instanceDataToPassOn = (0, ramda_1.omit)(constants_1.INSTANCE_FIELDS_TO_REMOVE, instance);
85
84
  // final outputs
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)(
87
- // TODO: (semver breaking) we omit these fields because it would a breaking change for the csv format.
88
- (v) => v.map((a) => {
89
- // TODO: (semver breaking) map the verification enums to the text to prevent a breaking change
90
- const b = Object.assign(Object.assign({}, (0, ramda_1.omit)([
91
- "$nId",
92
- "$schemaName",
93
- "$properties",
94
- "$shouldBeVerifiedFields",
95
- ], a)), { $verified: constants_1.PO_VER_TEXT_MAP[a.$verified] });
96
- return (0, ramda_1.mapObjIndexed)((fieldVal, fieldName) => {
97
- if (fieldName.endsWith(" Verification") ||
98
- fieldName.endsWith(".verification")) {
99
- return constants_1.FIELD_VER_TEXT_MAP[+fieldVal];
100
- }
101
- return fieldVal;
102
- }, 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));
103
95
  }), PODetails)));
104
96
  log("Success!");
105
97
  return {
106
- json: Object.assign(Object.assign(Object.assign({}, instanceDataToPassOn), { score }), PODetails),
98
+ json: Object.assign(Object.assign({}, instanceDataToPassOn), { score, profile_objects: PODetails }),
107
99
  csv,
108
100
  files,
109
101
  a_id: applicationId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "2.2.1",
3
+ "version": "3.0.0",
4
4
  "author": "Raytio",
5
5
  "description": "A helper to decrypt data shared by Raytio users",
6
6
  "main": "dist",
@@ -38,19 +38,19 @@
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": "^16.11.22",
41
+ "@types/node": "^16.11.24",
42
42
  "@types/node-fetch": "^2.5.12",
43
43
  "@types/pdfmake": "^0.1.20",
44
44
  "@types/ramda": "^0.27.64",
45
45
  "dotenv": "^16.0.0",
46
46
  "eslint": "^8.8.0",
47
- "eslint-config-kyle": "^8.1.1",
48
- "jest": "^27.4.7",
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
51
  "pdf-to-img": "^1.2.0",
52
52
  "ts-jest": "^27.1.3",
53
- "ts-node": "^10.4.0",
53
+ "ts-node": "^10.5.0",
54
54
  "typescript": "^4.5.5"
55
55
  },
56
56
  "eslintConfig": {