@raytio/decrypt-helper 2.1.0 → 2.2.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/api/__tests__/fetchEnvConfig.test.js +2 -2
  3. package/dist/api/__tests__/getFiles.test.js +1 -1
  4. package/dist/api/fetchInstanceData.js +3 -1
  5. package/dist/api/getFiles.js +5 -5
  6. package/dist/api/getLookupOption.js +1 -1
  7. package/dist/api/getProfileObject.js +1 -1
  8. package/dist/api/getSchema.js +1 -1
  9. package/dist/api/resolveVerificationDetails.js +1 -1
  10. package/dist/api/signIn.js +1 -1
  11. package/dist/helpers/__tests__/formatOutput.test.js +7 -3
  12. package/dist/helpers/__tests__/lookup.test.js +6 -6
  13. package/dist/helpers/file.js +1 -1
  14. package/dist/helpers/formatOutput.js +14 -7
  15. package/dist/helpers/index.d.ts +1 -0
  16. package/dist/helpers/index.js +1 -0
  17. package/dist/helpers/json2csv.js +7 -7
  18. package/dist/helpers/lookup.d.ts +1 -1
  19. package/dist/helpers/lookup.js +1 -1
  20. package/dist/helpers/setupMaxcryptor.js +2 -2
  21. package/dist/helpers/splitPOAndVers.js +1 -1
  22. package/dist/helpers/types.d.ts +1 -0
  23. package/dist/helpers/types.js +9 -0
  24. package/dist/pdf/components/FieldVerificationBadge.d.ts +2 -2
  25. package/dist/pdf/components/FieldVerificationBadge.js +4 -4
  26. package/dist/pdf/components/Images.d.ts +2 -2
  27. package/dist/pdf/components/Images.js +5 -2
  28. package/dist/pdf/components/InnerTableRows.d.ts +2 -2
  29. package/dist/pdf/components/InnerTableRows.js +7 -5
  30. package/dist/pdf/components/POVerificationBadge.d.ts +2 -2
  31. package/dist/pdf/components/POVerificationBadge.js +4 -4
  32. package/dist/pdf/components/Report.d.ts +2 -2
  33. package/dist/pdf/components/Report.js +5 -5
  34. package/dist/pdf/components/Subheader.d.ts +1 -1
  35. package/dist/pdf/components/Subheader.js +2 -2
  36. package/dist/pdf/components/Table.d.ts +2 -2
  37. package/dist/pdf/components/Table.js +4 -3
  38. package/dist/pdf/components/TableTitle.d.ts +2 -2
  39. package/dist/pdf/components/TableTitle.js +2 -2
  40. package/dist/pdf/components/ValidationDisplay.d.ts +2 -2
  41. package/dist/pdf/components/ValidationDisplay.js +9 -4
  42. package/dist/pdf/helpers/general.js +7 -2
  43. package/dist/pdf/helpers/transform.js +7 -3
  44. package/dist/pdf/style.js +4 -4
  45. package/dist/public-methods/generatePDF.js +1 -1
  46. package/dist/public-methods/processSubmission.js +16 -15
  47. package/dist/public-methods/saveToS3Bucket.js +2 -0
  48. package/dist/test/pdf.js +3 -3
  49. package/package.json +27 -27
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.0 (2022-02-04)
11
+
12
+ - !153 fix rendering of arrays of primitive values
13
+ - !152 Update @raytio/core to v9 to fix a bug with `hashed_n_id`
14
+ - !155, !154, !146, !147, !150, !151 automated dependency updates
15
+
16
+ ## 2.1.3 (2021-10-08)
17
+
18
+ - !134 Add more logging to `saveToS3Bucket`
19
+ - !129, !131, !132, !133 automated dependency updates
20
+
21
+ ## 2.1.2 (2021-09-24)
22
+
23
+ - !129 Update @raytio/core to v8.1.2 to support the new API format for `hashed_n_id`
24
+
25
+ ## 2.1.1 (2021-09-15)
26
+
27
+ - !126 Update @raytio/core to v8.1.1 to fix a bug with `hashed_n_id`
28
+
10
29
  ## 2.1.0 (2021-09-03)
11
30
 
12
31
  - !117 Update @raytio/core to v8
@@ -16,7 +16,7 @@ describe.each `
16
16
  ${"https://app-dev.rayt.io"} | ${"https://api-dev.rayt.io"}
17
17
  `("fetchEnvConfig $clientUrl / $apiUrl", ({ clientUrl, apiUrl }) => {
18
18
  it("works if you pass it a valid client url", () => __awaiter(void 0, void 0, void 0, function* () {
19
- expect(yield fetchEnvConfig_1.fetchEnvConfig(clientUrl)).toStrictEqual({
19
+ expect(yield (0, fetchEnvConfig_1.fetchEnvConfig)(clientUrl)).toStrictEqual({
20
20
  api_url: apiUrl,
21
21
  cognito_region: "us-east-1",
22
22
  cognito_user_pool_id: expect.any(String),
@@ -24,6 +24,6 @@ describe.each `
24
24
  });
25
25
  }));
26
26
  it("throws an error if you pass it an invalid url", () => __awaiter(void 0, void 0, void 0, function* () {
27
- yield expect(() => fetchEnvConfig_1.fetchEnvConfig(apiUrl)).rejects.toThrow(new Error(`The CLIENT_URL you specified is not a valid Raytio client. Are you sure you used the client URL, not the API url? You supplied: "${apiUrl}" (Error: Missing: cognito_region, cognito_user_pool_id, cognito_web_client_id, api_url)`));
27
+ yield expect(() => (0, fetchEnvConfig_1.fetchEnvConfig)(apiUrl)).rejects.toThrow(new Error(`The CLIENT_URL you specified is not a valid Raytio client. Are you sure you used the client URL, not the API url? You supplied: "${apiUrl}" (Error: Missing: cognito_region, cognito_user_pool_id, cognito_web_client_id, api_url)`));
28
28
  }));
29
29
  });
@@ -34,7 +34,7 @@ describe("getFiles", () => {
34
34
  throw new Error("This shouldn't be called");
35
35
  },
36
36
  };
37
- const files = yield getFiles_1.getFiles(profileObjects, instance, "api token", envConfig, applicationDecryptor);
37
+ const files = yield (0, getFiles_1.getFiles)(profileObjects, instance, "api token", envConfig, applicationDecryptor);
38
38
  expect(files).toStrictEqual({
39
39
  my_image: [expect.any(String), "jpeg"],
40
40
  });
@@ -10,10 +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 core_1 = require("@raytio/core");
13
14
  const authedFetch_1 = require("./authedFetch");
14
15
  function fetchInstanceData(apiToken, envConfig, instanceId) {
15
16
  return __awaiter(this, void 0, void 0, function* () {
16
- return authedFetch_1.authedFetch(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instanceId}`);
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;
17
19
  });
18
20
  }
19
21
  exports.fetchInstanceData = fetchInstanceData;
@@ -19,7 +19,7 @@ const mime_types_1 = require("mime-types");
19
19
  const file_1 = require("../helpers/file");
20
20
  const authedFetch_1 = require("./authedFetch");
21
21
  const TEMP_OBJ_PREFIX = "urn:temp_object:";
22
- const getFileExtn = (b64) => mime_types_1.extension(b64.split(":")[1].split(";base64,")[0]) || "txt";
22
+ const getFileExtn = (b64) => (0, mime_types_1.extension)(b64.split(":")[1].split(";base64,")[0]) || "txt";
23
23
  const decryptFile = (encryptedData, encryptedObj, applicationDecryptor, wdek) => __awaiter(void 0, void 0, void 0, function* () {
24
24
  const clonedEncryptedObj = JSON.parse(JSON.stringify(encryptedObj));
25
25
  clonedEncryptedObj.encrypted_data.data = encryptedData;
@@ -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) => file_1.isFile(kv[1]))
46
+ .filter((kv) => (0, file_1.isFile)(kv[1]))
47
47
  .map(([k, v]) => {
48
48
  return [
49
49
  PO.n_id,
@@ -59,14 +59,14 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
59
59
  if (typeof urnOrEncrypted === "string" &&
60
60
  urnOrEncrypted.startsWith(TEMP_OBJ_PREFIX)) {
61
61
  const url = atob(urnOrEncrypted.slice(TEMP_OBJ_PREFIX.length));
62
- const res = yield node_fetch_1.default(url);
62
+ const res = yield (0, node_fetch_1.default)(url);
63
63
  const b64 = (yield res.buffer()).toString("base64");
64
64
  const type = res.headers.get("content-type") || "text/plain";
65
65
  const dataUrl = `data:${type};base64,${b64}`;
66
66
  return [fileNId, [dataUrl, getFileExtn(dataUrl)]];
67
67
  }
68
- const realB64 = yield authedFetch_1.authedFetch(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instance.i_id}/profile_object/${fileNId}/content`).then(cleanApiResponse);
69
- if (core_1.isEncrypted(urnOrEncrypted)) {
68
+ const realB64 = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instance.i_id}/profile_object/${fileNId}/content`).then(cleanApiResponse);
69
+ if ((0, core_1.isEncrypted)(urnOrEncrypted)) {
70
70
  const wdek = (_b = (_a = instance.keys[PONId]) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.data;
71
71
  if (!wdek)
72
72
  return [fileNId, undefined];
@@ -23,7 +23,7 @@ function getLookupOption(apiToken, lookup) {
23
23
  return cached;
24
24
  // if it's a lookup to our own API, then include the IdentityToken
25
25
  const promise = origin.endsWith(".rayt.io")
26
- ? authedFetch_1.authedFetch(apiToken, lookup)
26
+ ? (0, authedFetch_1.authedFetch)(apiToken, lookup)
27
27
  : fetch(lookup).then((r) => r.json());
28
28
  cache.set(lookup, promise);
29
29
  return promise;
@@ -13,7 +13,7 @@ exports.getProfileObject = void 0;
13
13
  const authedFetch_1 = require("./authedFetch");
14
14
  function getProfileObject(envConfig, apiToken, nId) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- return authedFetch_1.authedFetch(apiToken, `${envConfig.api_url}/graph/v2/profile_object/${nId}`);
16
+ return (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/graph/v2/profile_object/${nId}`);
17
17
  });
18
18
  }
19
19
  exports.getProfileObject = getProfileObject;
@@ -15,7 +15,7 @@ const cache = new Map();
15
15
  function $getSchema(envConfig, apiToken, name) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  const [schemaHead, ...schemaTail] = name.split("_");
18
- const schema = yield authedFetch_1.authedFetch(apiToken, `${envConfig.api_url}/graph/v2/schema/${schemaHead}/${schemaTail.join("_")}?expand=true`);
18
+ const schema = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/graph/v2/schema/${schemaHead}/${schemaTail.join("_")}?expand=true`);
19
19
  return Object.assign(Object.assign({}, schema), { name });
20
20
  });
21
21
  }
@@ -18,7 +18,7 @@ function resolveVerificationDetails([details], apiToken, envConfig) {
18
18
  const maybeGet = (nId) => __awaiter(this, void 0, void 0, function* () {
19
19
  var _a, _b;
20
20
  return nId
21
- ? (_b = (_a = (yield getProfileObject_1.getProfileObject(envConfig, apiToken, nId))) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.provider_name
21
+ ? (_b = (_a = (yield (0, getProfileObject_1.getProfileObject)(envConfig, apiToken, nId))) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.provider_name
22
22
  : undefined;
23
23
  });
24
24
  const [verifier_id, verifier_service_id, verifier_source_id] = yield Promise.all([
@@ -25,7 +25,7 @@ function signIn(CONFIG, envConfig) {
25
25
  });
26
26
  const userObj = yield auth_1.default.signIn({
27
27
  username: CONFIG.USERNAME,
28
- password: yield core_1.hashPassword(CONFIG.PASSWORD),
28
+ password: yield (0, core_1.hashPassword)(CONFIG.PASSWORD),
29
29
  });
30
30
  if (userObj.challengeName === "SOFTWARE_TOKEN_MFA") {
31
31
  throw new Error(`The configured account (${CONFIG.USERNAME}) has two factor authentication enabled. You must disable 2FA or use a different account`);
@@ -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 = [];
@@ -49,7 +53,7 @@ describe("formatOutput", () => {
49
53
  m(api_1.resolveVerificationDetails).mockResolvedValue(Symbol.for("VerificationDetails"));
50
54
  });
51
55
  it("uses schema_group to group schema", () => __awaiter(void 0, void 0, void 0, function* () {
52
- const output = yield formatOutput_1.formatOutput(profileObjects, allSchemas, realVers, "[apiToken]",
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
58
  { READABLE_FIELD_NAMES: false }, Symbol.for("envConfig"));
55
59
  expect(output).toStrictEqual({
@@ -135,7 +139,7 @@ describe("formatOutput", () => {
135
139
  });
136
140
  }));
137
141
  it("doesn't use schema_group if READABLE_FIELD_NAMES is true", () => __awaiter(void 0, void 0, void 0, function* () {
138
- const output = yield formatOutput_1.formatOutput(profileObjects, allSchemas, realVers, "[apiToken]",
142
+ const output = yield (0, formatOutput_1.formatOutput)(profileObjects, allSchemas, realVers, "[apiToken]",
139
143
  // @ts-expect-error testing if it works with booleans not stringied bools
140
144
  { READABLE_FIELD_NAMES: true }, Symbol.for("envConfig"));
141
145
  expect(output).toStrictEqual({
@@ -29,8 +29,8 @@ describe("maybeAddLookupValue", () => {
29
29
  },
30
30
  },
31
31
  };
32
- const result = yield lookup_ts_1.maybeAddLookupValue(schema, key, value);
33
- expect(result).toStrictEqual("NZ");
32
+ const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
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(() => [
@@ -51,8 +51,8 @@ describe("maybeAddLookupValue", () => {
51
51
  },
52
52
  },
53
53
  };
54
- const result = yield lookup_ts_1.maybeAddLookupValue(schema, key, value);
55
- expect(result).toStrictEqual("New Zealand");
54
+ const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
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(() => [
@@ -73,7 +73,7 @@ describe("maybeAddLookupValue", () => {
73
73
  },
74
74
  },
75
75
  };
76
- const result = yield lookup_ts_1.maybeAddLookupValue(schema, key, value);
77
- expect(result).toStrictEqual("NZ");
76
+ const result = yield (0, lookup_ts_1.maybeAddLookupValue)(schema, key, value);
77
+ expect(result).toBe("NZ");
78
78
  }));
79
79
  });
@@ -6,7 +6,7 @@ const URN_PREFIX = "urn:";
6
6
  /** @internal */
7
7
  const isObject = (x) => !!x && typeof x === "object";
8
8
  /** @internal */
9
- const isUrnOrEncrypted = (x) => (typeof x === "string" && x.startsWith(URN_PREFIX)) || core_1.isEncrypted(x);
9
+ const isUrnOrEncrypted = (x) => (typeof x === "string" && x.startsWith(URN_PREFIX)) || (0, core_1.isEncrypted)(x);
10
10
  const isFile = (field) => isObject(field) &&
11
11
  (isUrnOrEncrypted(field.content) || isUrnOrEncrypted(field.Content));
12
12
  exports.isFile = isFile;
@@ -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;
@@ -29,34 +32,36 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, CONFIG, en
29
32
  const PODetails = profileObjects.reduce((acPromise, PO) => __awaiter(this, void 0, void 0, function* () {
30
33
  var _a, _b;
31
34
  const ac = yield acPromise;
32
- const schemaName = core_1.findSchemaLabel(PO.labels);
35
+ const schemaName = (0, core_1.findSchemaLabel)(PO.labels);
33
36
  const schema = allSchemas.find((x) => x.name === schemaName);
34
37
  if (!schema)
35
38
  throw new Error(`${schema} is missing!`);
36
- const verDetails = core_1.getPOVerification({ PO, schema, realVers });
37
- const realProps = ramda_1.omit(constants_1.FIELDS_TO_REMOVE, PO.properties);
39
+ const verDetails = (0, core_1.getPOVerification)({ PO, schema, realVers });
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"
47
- ? yield lookup_1.maybeAddLookupValue(schema, key, value, apiToken)
52
+ ? yield (0, lookup_1.maybeAddLookupValue)(schema, key, value, apiToken)
48
53
  : value,
49
54
  verification: verDetails.fieldVerifications[key],
50
55
  } });
51
56
  }), Promise.resolve({}));
52
57
  const thisPO = Object.assign({
53
58
  // these are always included
54
- $verified: verDetails.status, $verification_details: yield 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
- ? (yield core_1.calcSafeHarbourScore({
62
+ ? (yield (0, core_1.calcSafeHarbourScore)({
58
63
  person: PO,
59
- getSchema: (name) => api_1.getSchema(envConfig, apiToken, name),
64
+ getSchema: (name) => (0, api_1.getSchema)(envConfig, apiToken, 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);
@@ -4,18 +4,18 @@ exports.deepJsonToCsv = exports.flattenObj = void 0;
4
4
  const ramda_1 = require("ramda");
5
5
  // copied from raytio-client
6
6
  const flattenObj = (obj) => {
7
- const go = (obj_) => ramda_1.chain(([k, v]) => {
8
- if (ramda_1.type(v) === "Object" || ramda_1.type(v) === "Array") {
9
- return ramda_1.map(([k_, v_]) => [`${k}.${k_}`, v_], go(v));
7
+ const go = (obj_) => (0, ramda_1.chain)(([k, v]) => {
8
+ if ((0, ramda_1.type)(v) === "Object" || (0, ramda_1.type)(v) === "Array") {
9
+ return (0, ramda_1.map)(([k_, v_]) => [`${k}.${k_}`, v_], go(v));
10
10
  }
11
11
  return [[k, v]];
12
- }, ramda_1.toPairs(obj_));
13
- return ramda_1.fromPairs(go(obj));
12
+ }, (0, ramda_1.toPairs)(obj_));
13
+ return (0, ramda_1.fromPairs)(go(obj));
14
14
  };
15
15
  exports.flattenObj = flattenObj;
16
16
  function deepJsonToCsv(json) {
17
- const flatJson = exports.flattenObj(json);
18
- const [headerRow, values] = ramda_1.transpose(Object.entries(flatJson));
17
+ const flatJson = (0, exports.flattenObj)(json);
18
+ const [headerRow, values] = (0, ramda_1.transpose)(Object.entries(flatJson));
19
19
  const toCsvRow = (row) => row
20
20
  .map((field) => typeof field === "string" ? `"${field.replace(/"/g, '\\"')}"` : field)
21
21
  .join(",");
@@ -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>;
@@ -16,7 +16,7 @@ const maybeAddLookupValue = (schema, k, value, apiToken) => __awaiter(void 0, vo
16
16
  const lookupUrl = (_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[k]) === null || _b === void 0 ? void 0 : _b.lookup;
17
17
  if (!lookupUrl)
18
18
  return value;
19
- const lookup = yield getLookupOption_1.getLookupOption(apiToken, lookupUrl);
19
+ const lookup = yield (0, getLookupOption_1.getLookupOption)(apiToken, lookupUrl);
20
20
  return ((_c = lookup.find((l) => l.key === value)) === null || _c === void 0 ? void 0 : _c.value) || value;
21
21
  });
22
22
  exports.maybeAddLookupValue = maybeAddLookupValue;
@@ -19,9 +19,9 @@ function setupMaxcryptor(CONFIG, cognitoAttributes) {
19
19
  const userDoc = cognitoAttributes.reduce((acc, { Name, Value }) => {
20
20
  if (!isMaxcryptorAttr(Name))
21
21
  return acc;
22
- return ramda_1.assocPath(constants_1.ATTRIBUTE_MAP[Name], JSON.parse(Value), acc);
22
+ return (0, ramda_1.assocPath)(constants_1.ATTRIBUTE_MAP[Name], JSON.parse(Value), acc);
23
23
  }, {});
24
- const { encryptor: maxcryptor } = yield maxcryptor_1.encryptorFromExistingUser(userDoc, CONFIG.PASSWORD);
24
+ const { encryptor: maxcryptor } = yield (0, maxcryptor_1.encryptorFromExistingUser)(userDoc, CONFIG.PASSWORD);
25
25
  return maxcryptor;
26
26
  });
27
27
  }
@@ -4,7 +4,7 @@ exports.splitPOAndVers = void 0;
4
4
  const core_1 = require("@raytio/core");
5
5
  const constants_1 = require("../constants");
6
6
  const splitPOAndVers = (list) => list.reduce((ac, PO) => {
7
- const isVer = core_1.findSchemaLabel(PO.labels) === constants_1.VERIFICATION_SCHEMA;
7
+ const isVer = (0, core_1.findSchemaLabel)(PO.labels) === constants_1.VERIFICATION_SCHEMA;
8
8
  ac[+isVer].push(PO);
9
9
  return ac;
10
10
  }, [[], []]);
@@ -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,13 +7,13 @@ 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
- return (jsx_pdf_1.default.createElement("svg", { content: general_1.loadAsset("verified_false_small.svg"), width: width }));
12
+ return (jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)("verified_false_small.svg"), width: width }));
13
13
  }
14
14
  if (status === types_1.FieldVerification.Verified) {
15
- return jsx_pdf_1.default.createElement("svg", { content: general_1.loadAsset("verified_tick_small.svg"), width: width });
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,30 +6,32 @@ 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 &&
16
17
  "breakdown" in value) {
17
18
  return jsx_pdf_1.default.createElement(ValidationDisplay_1.ValidationDisplay, { value: value });
18
19
  }
19
- const text = transform_1.transform(key, value, config, imageFieldNames);
20
+ const text = (0, transform_1.transform)(key, value, config, imageFieldNames);
20
21
  if (typeof text !== "string" && text === transform_1.IS_IMAGE) {
21
22
  return jsx_pdf_1.default.createElement(Images_1.Images, { files: files, nIds: [value.n_id] });
22
23
  }
23
24
  if (typeof text !== "string" && text === transform_1.IS_ARRAY_OF_OBJECTS) {
24
- const headers = [ramda_1.uniq(value.flatMap(Object.keys))];
25
+ const headers = [(0, ramda_1.uniq)(value.flatMap(Object.keys))];
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,26 +18,26 @@ 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];
25
25
  const verifiedBy = $verification_details === null || $verification_details === void 0 ? void 0 : $verification_details.verifier_id;
26
26
  return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
27
27
  $shouldBeVerifiedFields && (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
28
- jsx_pdf_1.default.createElement("svg", { content: general_1.loadAsset(`${exports.FILE_MAP[$verified]}.svg`), width: width }),
28
+ jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$verified]}.svg`), width: width }),
29
29
  jsx_pdf_1.default.createElement("text", { alignment: "center" }, constants_1.PO_VER_TEXT_MAP[$verified]),
30
30
  verifiedBy && jsx_pdf_1.default.createElement("text", { alignment: "center" },
31
31
  "by ",
32
32
  verifiedBy))),
33
33
  typeof $safeHarbour === "boolean" && (jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
34
34
  jsx_pdf_1.default.createElement("column", { width: width / 3 },
35
- jsx_pdf_1.default.createElement("svg", { content: general_1.loadAsset(`${exports.FILE_MAP[$safeHarbour
35
+ jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$safeHarbour
36
36
  ? types_1.POVerification.FullyVerified
37
37
  : types_1.POVerification.VerifiedFalse]}.svg`), width: width / 3 })),
38
38
  jsx_pdf_1.default.createElement("column", { width: "auto" },
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,10 +15,10 @@ 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
- const randomToken = crypto_1.randomBytes(32).toString("base64");
21
+ const randomToken = (0, crypto_1.randomBytes)(32).toString("base64");
22
22
  return (jsx_pdf_1.default.createElement("document", { defaultStyle: { font: "Lato", fontSize: 12 }, info: {
23
23
  title: `Raytio Verification Report - ${data.i_id}`,
24
24
  creator: "Raytio",
@@ -28,7 +28,7 @@ function Report({ data, files, config, aId, clientUrl, version, }) {
28
28
  printing: "highResolution",
29
29
  copying: true, // allow copy/paste
30
30
  }, pageSize: "A4", styles: style_1.classes, images: {
31
- raytioLogo: general_1.asset("logo.png"),
31
+ raytioLogo: (0, general_1.asset)("logo.png"),
32
32
  } },
33
33
  jsx_pdf_1.default.createElement("header", null, (currentPage) => currentPage !== 1 && (jsx_pdf_1.default.createElement("stack", { color: "#333", fontSize: 10 },
34
34
  jsx_pdf_1.default.createElement("text", { margin: 16 },
@@ -40,7 +40,7 @@ function Report({ data, files, config, aId, clientUrl, version, }) {
40
40
  jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
41
41
  jsx_pdf_1.default.createElement("column", { width: "auto" },
42
42
  jsx_pdf_1.default.createElement("text", { style: ["subheader", "marginBottom"] }, Object.entries(constants_1.SUBMISSION_DATA)
43
- .map(([id, label]) => `${label}: ${transform_1.transform(id, data[id], config)}`)
43
+ .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
44
44
  .join("\n")),
45
45
  jsx_pdf_1.default.createElement(Subheader_1.Subheader, { data: data, config: config })),
46
46
  jsx_pdf_1.default.createElement("column", { width: "*" },
@@ -67,5 +67,5 @@ function Report({ data, files, config, aId, clientUrl, version, }) {
67
67
  currentPage,
68
68
  " of ",
69
69
  pageCount))))));
70
- }
70
+ };
71
71
  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,9 +29,10 @@ 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
- const color = general_1.verifyColour(status);
35
+ const color = (0, general_1.verifyColour)(status);
35
36
  // jsx-pdf currently doesn't support fragments, will make a PR at some point
36
37
  return [
37
38
  jsx_pdf_1.default.createElement("cell", null,
@@ -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,20 +6,25 @@ 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
- jsx_pdf_1.default.createElement("svg", { content: pieChart_1.pieChart(colour, value.score * 100), width: 50 }),
18
+ jsx_pdf_1.default.createElement("svg", { content: (0, pieChart_1.pieChart)(colour, value.score * 100), width: 50 }),
18
19
  "Score: ",
19
20
  value.score * 10,
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,9 +4,14 @@ 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) => 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
- const loadAsset = (name) => fs_1.readFileSync(exports.asset(name), { encoding: "utf-8" });
14
+ const loadAsset = (name) => (0, fs_1.readFileSync)((0, exports.asset)(name), { encoding: "utf-8" });
10
15
  exports.loadAsset = loadAsset;
11
16
  // TODO: clean this up
12
17
  /* eslint-disable no-nested-ternary */
@@ -15,15 +15,19 @@ 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
  }
23
27
  switch (key) {
24
28
  case "start_date":
25
29
  case "end_date": {
26
- return general_1.formatDate(new Date(`${value}Z`), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
30
+ return (0, general_1.formatDate)(new Date(`${value}Z`), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
27
31
  }
28
32
  default: {
29
33
  return value;
package/dist/pdf/style.js CHANGED
@@ -16,9 +16,9 @@ exports.classes = {
16
16
  };
17
17
  exports.fonts = {
18
18
  Lato: {
19
- normal: general_1.asset("Lato-Light.ttf"),
20
- bold: general_1.asset("Lato-Bold.ttf"),
21
- italics: general_1.asset("Lato-LightItalic.ttf"),
22
- bolditalics: general_1.asset("Lato-BoldItalic.ttf"),
19
+ normal: (0, general_1.asset)("Lato-Light.ttf"),
20
+ bold: (0, general_1.asset)("Lato-Bold.ttf"),
21
+ italics: (0, general_1.asset)("Lato-LightItalic.ttf"),
22
+ bolditalics: (0, general_1.asset)("Lato-BoldItalic.ttf"),
23
23
  },
24
24
  };
@@ -26,7 +26,7 @@ exports.generatePdfJson = generatePdfJson;
26
26
  const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function* () {
27
27
  console.log("Generating PDF Report...");
28
28
  const { DATE_FORMAT = "en-nz", TIMEZONE = "Pacific/Auckland" } = process.env;
29
- const pkg = JSON.parse(yield fs_1.promises.readFile(path_1.join(__dirname, "../../package.json"), "utf8"));
29
+ const pkg = JSON.parse(yield fs_1.promises.readFile((0, path_1.join)(__dirname, "../../package.json"), "utf8"));
30
30
  const version = `node:${process.version} pkg:${pkg.version}`;
31
31
  return new Promise((resolve) => {
32
32
  const printer = new pdfmake_1.default(style_1.fonts);
@@ -18,13 +18,13 @@ const api_1 = require("../api");
18
18
  function decryptStage(log, config, envConfig, instanceId) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
20
  log("Authenticating...");
21
- const { apiToken, cognitoAttributes } = yield api_1.signIn(config, envConfig);
21
+ const { apiToken, cognitoAttributes } = yield (0, api_1.signIn)(config, envConfig);
22
22
  log("Initializing decryptor...");
23
- const maxcryptor = yield helpers_1.setupMaxcryptor(config, cognitoAttributes);
23
+ const maxcryptor = yield (0, helpers_1.setupMaxcryptor)(config, cognitoAttributes);
24
24
  log("Fetching submission details...");
25
- const apiResp = yield api_1.fetchInstanceData(apiToken, envConfig, instanceId);
25
+ const apiResp = yield (0, api_1.fetchInstanceData)(apiToken, envConfig, instanceId);
26
26
  log("Decrypting submission details...");
27
- const { instance, applicationDecryptor } = yield core_1.decryptSharedData({
27
+ const { instance, applicationDecryptor } = yield (0, core_1.decryptSharedData)({
28
28
  apiToken,
29
29
  apiUrl: envConfig.api_url,
30
30
  instanceData: apiResp,
@@ -39,42 +39,43 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
39
39
  const log = verbose ? console.log : () => undefined;
40
40
  try {
41
41
  log("Fetching config...");
42
- const envConfig = yield api_1.fetchEnvConfig(config.CLIENT_URL);
42
+ const envConfig = yield (0, api_1.fetchEnvConfig)(config.CLIENT_URL);
43
43
  const { instance, apiToken, applicationDecryptor } = _supliedConfig ||
44
44
  (yield decryptStage(log, config, envConfig, instanceId));
45
45
  log("Checking verifications...");
46
- const [profileObjects, verifications] = helpers_1.splitPOAndVers(instance.profile_objects);
47
- const realVers = yield core_1.getRealVerifications({
46
+ const [profileObjects, verifications] = (0, helpers_1.splitPOAndVers)(instance.profile_objects);
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,
51
52
  });
52
53
  log("Fetching relevant schema...");
53
54
  const schemaNames = profileObjects.map((PO) => {
54
- const schemaName = core_1.findSchemaLabel(PO.labels);
55
+ const schemaName = (0, core_1.findSchemaLabel)(PO.labels);
55
56
  if (!schemaName)
56
57
  throw new Error("Submission contains invalid objects");
57
58
  return schemaName;
58
59
  });
59
- const allSchemas = yield Promise.all(ramda_1.uniq(schemaNames).map((name) => api_1.getSchema(envConfig, apiToken, name)));
60
+ const allSchemas = yield Promise.all((0, ramda_1.uniq)(schemaNames).map((name) => (0, api_1.getSchema)(envConfig, apiToken, name)));
60
61
  // TODO: resolve URNs if any fields are URNs
61
62
  log("Fetching verification providers...");
62
- const PODetails = yield helpers_1.formatOutput(profileObjects, allSchemas, realVers, apiToken, config, envConfig);
63
+ const PODetails = yield (0, helpers_1.formatOutput)(profileObjects, allSchemas, realVers, apiToken, config, envConfig);
63
64
  log("Fetching attached files...");
64
- const files = yield api_1.getFiles(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
65
- const instanceDataToPassOn = ramda_1.omit(constants_1.INSTANCE_FIELDS_TO_REMOVE, instance);
65
+ const files = yield (0, api_1.getFiles)(profileObjects, instance, apiToken, envConfig, applicationDecryptor);
66
+ const instanceDataToPassOn = (0, ramda_1.omit)(constants_1.INSTANCE_FIELDS_TO_REMOVE, instance);
66
67
  // final outputs
67
- const csv = helpers_1.deepJsonToCsv(Object.assign(Object.assign({}, ramda_1.omit(["a_id", "aa_name"], instanceDataToPassOn)), ramda_1.mapObjIndexed(
68
+ 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
69
  // TODO: (semver breaking) we omit these fields because it would a breaking change for the csv format.
69
70
  (v) => v.map((a) => {
70
71
  // TODO: (semver breaking) map the verification enums to the text to prevent a breaking change
71
- const b = Object.assign(Object.assign({}, ramda_1.omit([
72
+ const b = Object.assign(Object.assign({}, (0, ramda_1.omit)([
72
73
  "$nId",
73
74
  "$schemaName",
74
75
  "$properties",
75
76
  "$shouldBeVerifiedFields",
76
77
  ], a)), { $verified: constants_1.PO_VER_TEXT_MAP[a.$verified] });
77
- return ramda_1.mapObjIndexed((fieldVal, fieldName) => {
78
+ return (0, ramda_1.mapObjIndexed)((fieldVal, fieldName) => {
78
79
  if (fieldName.endsWith(" Verification") ||
79
80
  fieldName.endsWith(".verification")) {
80
81
  return constants_1.FIELD_VER_TEXT_MAP[+fieldVal];
@@ -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/dist/test/pdf.js CHANGED
@@ -14,7 +14,7 @@ const Report_1 = require("../pdf/components/Report");
14
14
  const style_1 = require("../pdf/style");
15
15
  let json;
16
16
  try {
17
- json = JSON.parse(fs_1.readFileSync(path_1.join(__dirname, "../../out.json"), { encoding: "utf-8" }));
17
+ json = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, "../../out.json"), { encoding: "utf-8" }));
18
18
  }
19
19
  catch (_a) {
20
20
  console.error("You need to save some data into out.json beforing using this test script");
@@ -22,7 +22,7 @@ catch (_a) {
22
22
  }
23
23
  let files = {};
24
24
  try {
25
- files = JSON.parse(fs_1.readFileSync(path_1.join(__dirname, "../../out-otherfiles.json"), {
25
+ files = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, "../../out-otherfiles.json"), {
26
26
  encoding: "utf-8",
27
27
  }));
28
28
  }
@@ -31,5 +31,5 @@ catch (_b) {
31
31
  }
32
32
  const printer = new pdfmake_1.default(style_1.fonts);
33
33
  const pdfDoc = printer.createPdfKitDocument(jsx_pdf_1.default.renderPdf(jsx_pdf_1.default.createElement(Report_1.Report, { data: json, files: files, aId: "my_a_id", clientUrl: "https://example.com", config: { DATE_FORMAT: "fr-FR", TIMEZONE: "Atlantic/Azores" }, version: "\u2764\uFE0F\u200D\uD83D\uDD25" })));
34
- pdfDoc.pipe(fs_1.createWriteStream("out.pdf"));
34
+ pdfDoc.pipe((0, fs_1.createWriteStream)("out.pdf"));
35
35
  pdfDoc.end();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
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.0",
26
- "@raytio/maxcryptor": "^3.0.1",
27
- "@raytio/types": "^5.2.0",
24
+ "@peculiar/webcrypto": "^1.2.3",
25
+ "@raytio/core": "^9.0.0",
26
+ "@raytio/maxcryptor": "^3.1.0",
27
+ "@raytio/types": "^5.2.1",
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.31",
32
- "node-fetch": "^2.6.1",
33
- "pdfmake": "^0.1.71",
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": "^26.0.23",
38
- "@types/jest-image-snapshot": "^4.3.0",
39
- "@types/jsx-pdf": "^2.2.1",
40
- "@types/mime-types": "^2.1.0",
41
- "@types/node": "^14.17.4",
42
- "@types/node-fetch": "^2.5.10",
43
- "@types/pdfmake": "^0.1.17",
44
- "@types/ramda": "^0.27.41",
45
- "dotenv": "^10.0.0",
46
- "eslint": "^7.29.0",
47
- "eslint-config-kyle": "^2.49.0",
48
- "jest": "^27.0.5",
49
- "jest-image-snapshot": "^4.5.0",
50
- "jest-junit": "^12.2.0",
51
- "pdf-to-img": "^1.1.0",
52
- "ts-jest": "^27.0.3",
53
- "ts-node": "^10.0.0",
54
- "typescript": "^4.3.4"
37
+ "@types/jest": "^27.4.0",
38
+ "@types/jest-image-snapshot": "^4.3.1",
39
+ "@types/jsx-pdf": "^2.2.2",
40
+ "@types/mime-types": "^2.1.1",
41
+ "@types/node": "^16.11.22",
42
+ "@types/node-fetch": "^2.5.12",
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
+ "jest-image-snapshot": "^4.5.1",
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",