@raytio/decrypt-helper 3.1.0 → 4.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,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 4.0.0 (2022-07-08)
11
+
12
+ - 💥 BREAKING CHANGE: !170 [json] [csv] changed the format of badges, the fields `$verified` and `$safeHarbour` have been replaced with `$badges`
13
+ - !176 fix field values being unexpectedly transformed
14
+ - !179 update dependencies
15
+ - !182 save the calculated score to the instance
16
+
17
+ ## 3.2.0 (2022-04-21)
18
+
19
+ - !177 do not use `hashPassword` when logging in, and migrate old credentials
20
+
21
+ ## 3.1.1 (2022-04-02)
22
+
23
+ - !175 Fix import issue in v3.1
24
+
10
25
  ## 3.1.0 (2022-03-14)
11
26
 
12
27
  - !168 Support internationalizing the pdf
@@ -1 +1 @@
1
- export declare function authedFetch<T>(apiToken: string, url: string): Promise<T>;
1
+ export declare function authedFetch<T>(apiToken: string, url: string, options?: RequestInit): Promise<T>;
@@ -10,11 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.authedFetch = void 0;
13
- function authedFetch(apiToken, url) {
13
+ function authedFetch(apiToken, url, options) {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
- const apiResp = yield fetch(url, {
16
- headers: { Authorization: `Bearer ${apiToken}` },
17
- }).then((r) => r.json());
15
+ const apiResp = yield fetch(url, Object.assign(Object.assign({}, options), { headers: { Authorization: `Bearer ${apiToken}` } })).then((r) => r.json());
18
16
  if (apiResp.message) {
19
17
  throw new Error(`Failed due to API Error: "${apiResp.message}"`);
20
18
  }
@@ -7,3 +7,4 @@ export * from "./getProfileObject";
7
7
  export * from "./getSchema";
8
8
  export * from "./resolveVerificationDetails";
9
9
  export * from "./signIn";
10
+ export * from "./updateInstanceData";
package/dist/api/index.js CHANGED
@@ -23,3 +23,4 @@ __exportStar(require("./getProfileObject"), exports);
23
23
  __exportStar(require("./getSchema"), exports);
24
24
  __exportStar(require("./resolveVerificationDetails"), exports);
25
25
  __exportStar(require("./signIn"), exports);
26
+ __exportStar(require("./updateInstanceData"), exports);
@@ -4,6 +4,6 @@ export declare type ResolvedVerificationProvider = {
4
4
  verifier_id?: string;
5
5
  verifier_service_id?: string;
6
6
  verifier_source_id?: string;
7
- date: string;
7
+ date?: string;
8
8
  };
9
9
  export declare function resolveVerificationDetails([details]: VerificationProvider[], apiToken: string, envConfig: EnvConfig): Promise<ResolvedVerificationProvider | undefined>;
@@ -12,13 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.resolveVerificationDetails = void 0;
13
13
  const getProfileObject_1 = require("./getProfileObject");
14
14
  function resolveVerificationDetails([details], apiToken, envConfig) {
15
+ var _a;
15
16
  return __awaiter(this, void 0, void 0, function* () {
16
17
  if (!details)
17
18
  return undefined;
18
19
  const maybeGet = (nId) => __awaiter(this, void 0, void 0, function* () {
19
- var _a, _b;
20
+ var _b, _c;
20
21
  return nId
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
+ ? (_c = (_b = (yield (0, getProfileObject_1.getProfileObject)(envConfig, apiToken, nId))) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.provider_name
22
23
  : undefined;
23
24
  });
24
25
  const [verifier_id, verifier_service_id, verifier_source_id] = yield Promise.all([
@@ -30,7 +31,7 @@ function resolveVerificationDetails([details], apiToken, envConfig) {
30
31
  verifier_id,
31
32
  verifier_service_id,
32
33
  verifier_source_id,
33
- date: details.date.toISOString(),
34
+ date: (_a = details.date) === null || _a === void 0 ? void 0 : _a.toISOString(),
34
35
  };
35
36
  });
36
37
  }
@@ -8,31 +8,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.signIn = void 0;
16
- const auth_1 = __importDefault(require("@aws-amplify/auth"));
13
+ const auth_1 = require("@aws-amplify/auth");
17
14
  const core_1 = require("@raytio/core");
15
+ /** see #1252 in the client repo */
16
+ function signInWithPasswordMigration(username, password) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ const userObj = yield auth_1.Auth.signIn(username, password);
20
+ return userObj;
21
+ }
22
+ catch (_a) {
23
+ // if the login fails, try again with their hashed password.
24
+ // if it's successful the second time, we quietly change their password.
25
+ const hashedPassword = yield (0, core_1.hashPassword)(password);
26
+ const userObj = yield auth_1.Auth.signIn(username, hashedPassword);
27
+ // the login was successful. So we need to migrate their account.
28
+ // No changes to the maxcryptor, purely to cognito.
29
+ // we can only migrate their password if there are no login challenges
30
+ if (!userObj.challengeName) {
31
+ console.log("Migrating credentials...");
32
+ yield auth_1.Auth.changePassword(userObj, hashedPassword, password);
33
+ }
34
+ return userObj;
35
+ }
36
+ });
37
+ }
18
38
  function signIn(CONFIG, envConfig) {
19
39
  var _a, _b;
20
40
  return __awaiter(this, void 0, void 0, function* () {
21
- auth_1.default.configure({
41
+ auth_1.Auth.configure({
22
42
  region: envConfig.cognito_region,
23
43
  userPoolId: envConfig.cognito_user_pool_id,
24
44
  userPoolWebClientId: envConfig.cognito_web_client_id,
25
45
  });
26
- const userObj = yield auth_1.default.signIn({
27
- username: CONFIG.RAYTIO_USERNAME,
28
- password: yield (0, core_1.hashPassword)(CONFIG.RAYTIO_PASSWORD),
29
- });
46
+ const userObj = yield signInWithPasswordMigration(CONFIG.RAYTIO_USERNAME, CONFIG.RAYTIO_PASSWORD);
30
47
  if (userObj.challengeName === "SOFTWARE_TOKEN_MFA") {
31
48
  throw new Error(`The configured account (${CONFIG.RAYTIO_USERNAME}) has two factor authentication enabled. You must disable 2FA or use a different account`);
32
49
  }
33
- const user = yield auth_1.default.currentAuthenticatedUser();
50
+ const user = yield auth_1.Auth.currentAuthenticatedUser();
34
51
  const apiToken = (_b = (_a = user.signInUserSession) === null || _a === void 0 ? void 0 : _a.idToken) === null || _b === void 0 ? void 0 : _b.jwtToken;
35
- const cognitoAttributes = yield auth_1.default.userAttributes(user);
52
+ const cognitoAttributes = yield auth_1.Auth.userAttributes(user);
36
53
  return { apiToken, cognitoAttributes };
37
54
  });
38
55
  }
@@ -0,0 +1,2 @@
1
+ import type { Instance } from "@raytio/types";
2
+ export declare function updateInstanceData(apiToken: string, instance: Instance): Promise<void>;
@@ -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.updateInstanceData = void 0;
13
+ const authedFetch_1 = require("./authedFetch");
14
+ function updateInstanceData(apiToken, instance) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ yield (0, authedFetch_1.authedFetch)(apiToken, `share/v2/access_application/instance/${instance.i_id}`, { method: "PUT", body: JSON.stringify(instance) });
17
+ });
18
+ }
19
+ exports.updateInstanceData = updateInstanceData;
@@ -8,7 +8,7 @@ export declare const ATTRIBUTE_MAP: {
8
8
  "custom:ask_public": string[];
9
9
  "custom:ask_private": string[];
10
10
  };
11
- export declare const INSTANCE_FIELDS_TO_REMOVE: readonly ["profile_objects", "relationships", "keys"];
11
+ export declare const INSTANCE_FIELDS_TO_REMOVE: readonly ["profile_objects", "relationships", "keys", "score"];
12
12
  export declare const FIELDS_TO_REMOVE: readonly ["n_id", "document"];
13
13
  export declare const ENV_VARIABLES: readonly ["CLIENT_URL", "RAYTIO_USERNAME", "RAYTIO_PASSWORD"];
14
14
  export declare type Config = Record<typeof ENV_VARIABLES[number], string>;
package/dist/constants.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SCHEMA = exports.FIELD_VER_TEXT_MAP = exports.PO_VER_TEXT_MAP = exports.ENV_VARIABLES = exports.FIELDS_TO_REMOVE = exports.INSTANCE_FIELDS_TO_REMOVE = exports.ATTRIBUTE_MAP = void 0;
4
4
  const types_1 = require("@raytio/types");
5
- const locales_1 = require("locales");
5
+ const locales_1 = require("./locales");
6
6
  exports.ATTRIBUTE_MAP = {
7
7
  "custom:kek_derivation": ["kek_derivation_config"],
8
8
  "custom:dek_encryption": ["private_key_encryption_config"],
@@ -15,6 +15,7 @@ exports.INSTANCE_FIELDS_TO_REMOVE = [
15
15
  "profile_objects",
16
16
  "relationships",
17
17
  "keys",
18
+ "score",
18
19
  ];
19
20
  exports.FIELDS_TO_REMOVE = ["n_id", "document"];
20
21
  exports.ENV_VARIABLES = [
@@ -1,7 +1,6 @@
1
1
  import { FieldVerification, NId, POVerification, ProfileObject, RealVer, Schema } from "@raytio/types";
2
2
  import { ResolvedVerificationProvider, EnvConfig } from "../api";
3
3
  export declare type FlatPO = {
4
- $verified: POVerification;
5
4
  $verification_details: ResolvedVerificationProvider | undefined;
6
5
  $shouldBeVerifiedFields: string[] | undefined;
7
6
  $nId: NId;
@@ -11,9 +10,19 @@ export declare type FlatPO = {
11
10
  [fieldName: string]: {
12
11
  title: string;
13
12
  value: unknown;
13
+ formatted_value?: string | number;
14
14
  verification: FieldVerification;
15
15
  };
16
16
  };
17
- $safeHarbour: boolean | "NOT_APPLICABLE";
17
+ $badges: {
18
+ verified: {
19
+ code: POVerification;
20
+ statusText: string;
21
+ };
22
+ safeHarbour?: {
23
+ code: boolean;
24
+ statusText: string;
25
+ };
26
+ };
18
27
  };
19
28
  export declare function formatOutput(profileObjects: ProfileObject[], allSchemas: Schema[], realVers: RealVer[], apiToken: string, envConfig: EnvConfig): Promise<Record<string, FlatPO[]>>;
@@ -13,6 +13,7 @@ exports.formatOutput = void 0;
13
13
  const core_1 = require("@raytio/core");
14
14
  const ramda_1 = require("ramda");
15
15
  const types_1 = require("@raytio/types");
16
+ const locales_1 = require("../locales");
16
17
  const api_1 = require("../api");
17
18
  const constants_1 = require("../constants");
18
19
  const lookup_1 = require("./lookup");
@@ -44,31 +45,44 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig)
44
45
  var _b, _c;
45
46
  const accP = yield acc;
46
47
  (0, types_2.assertSafeProperty)(key);
47
- return Object.assign(Object.assign({}, accP), { [key]: {
48
- title: ((_c = (_b = schema.properties) === null || _b === void 0 ? void 0 : _b[key]) === null || _c === void 0 ? void 0 : _c.title) || key,
49
- value: typeof value === "string"
50
- ? yield (0, lookup_1.maybeAddLookupValue)(schema, key, value, apiToken)
51
- : value,
52
- verification: verDetails.fieldVerifications[key] ||
53
- types_1.FieldVerification.NotVerified,
54
- } });
48
+ const prettyValue = typeof value === "string"
49
+ ? yield (0, lookup_1.maybeGetLookupValue)(schema, key, value, apiToken)
50
+ : undefined;
51
+ const obj = {
52
+ title: ((_c = (_b = schema.properties) === null || _b === void 0 ? void 0 : _b[key]) === null || _c === void 0 ? void 0 : _c.title) || key,
53
+ value,
54
+ verification: verDetails.fieldVerifications[key] || types_1.FieldVerification.NotVerified,
55
+ };
56
+ if (prettyValue)
57
+ obj.formatted_value = prettyValue;
58
+ return Object.assign(Object.assign({}, accP), { [key]: obj });
55
59
  }), Promise.resolve({}));
56
60
  const thisPO = {
57
- $verified: verDetails.status,
58
61
  $verification_details: yield (0, api_1.resolveVerificationDetails)(verDetails.details.verifiers, apiToken, envConfig),
59
62
  $shouldBeVerifiedFields: (_a = schema.verified_fields) === null || _a === void 0 ? void 0 : _a.map((x) => typeof x === "string" ? x : x.field),
60
63
  $nId: PO.n_id,
61
64
  $schemaName: schemaName,
62
65
  $schemaTitle: schema.title,
63
66
  $properties: reducedProperties,
64
- $safeHarbour: schemaName === constants_1.SCHEMA.PERSON
65
- ? (yield (0, core_1.calcSafeHarbourScore)({
66
- person: PO,
67
- getSchema: (name) => (0, api_1.getSchema)(envConfig, name),
68
- profileObjects,
69
- realVers,
70
- })).isSafe
71
- : "NOT_APPLICABLE",
67
+ $badges: {
68
+ verified: {
69
+ code: verDetails.status,
70
+ statusText: constants_1.PO_VER_TEXT_MAP[verDetails.status],
71
+ },
72
+ safeHarbour: schemaName === constants_1.SCHEMA.PERSON
73
+ ? (({ isSafe }) => ({
74
+ code: isSafe,
75
+ statusText: isSafe
76
+ ? (0, locales_1.$$)("POVerificationBadge.safe-harbour-yes")
77
+ : (0, locales_1.$$)("POVerificationBadge.safe-harbour-no"),
78
+ }))(yield (0, core_1.calcSafeHarbourScore)({
79
+ person: PO,
80
+ getSchema: (name) => (0, api_1.getSchema)(envConfig, name),
81
+ profileObjects,
82
+ realVers,
83
+ }))
84
+ : undefined,
85
+ },
72
86
  };
73
87
  return Object.assign(Object.assign({}, ac), { [schemaName]: [...existing, thisPO] });
74
88
  }), Promise.resolve({}));
@@ -1,2 +1,2 @@
1
1
  import { Schema } from "@raytio/types";
2
- export declare const maybeAddLookupValue: <T>(schema: Schema, k: string, value: T, apiToken: string) => Promise<string | number | T>;
2
+ export declare const maybeGetLookupValue: <T>(schema: Schema, k: string, value: T, apiToken: string) => Promise<string | number | T | undefined>;
@@ -9,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.maybeAddLookupValue = void 0;
12
+ exports.maybeGetLookupValue = void 0;
13
13
  const getLookupOption_1 = require("../api/getLookupOption");
14
- const maybeAddLookupValue = (schema, k, value, apiToken) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const maybeGetLookupValue = (schema, k, value, apiToken) => __awaiter(void 0, void 0, void 0, function* () {
15
15
  var _a, _b, _c;
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
- return value;
18
+ return undefined;
19
19
  const lookup = yield (0, getLookupOption_1.getLookupOption)(apiToken, lookupUrl);
20
- return ((_c = lookup.find((l) => l.key === value)) === null || _c === void 0 ? void 0 : _c.value) || value;
20
+ return (_c = lookup.find((l) => l.key === value)) === null || _c === void 0 ? void 0 : _c.value;
21
21
  });
22
- exports.maybeAddLookupValue = maybeAddLookupValue;
22
+ exports.maybeGetLookupValue = maybeGetLookupValue;
@@ -40,5 +40,5 @@ declare global {
40
40
  var lang: I18nLang;
41
41
  }
42
42
  export declare const isValidLocale: (lang: string) => lang is "en";
43
- export declare const $$: (key: I18nKey, variables?: Record<string, string | number> | undefined) => string;
43
+ export declare const $$: (key: I18nKey, variables?: Record<string, string | number>) => string;
44
44
  export {};
@@ -5,7 +5,7 @@ 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
- const locales_1 = require("locales");
8
+ const locales_1 = require("../../locales");
9
9
  const helpers_1 = require("../../helpers");
10
10
  const Images = ({ nIds, files, }) => {
11
11
  return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null, nIds.map((nId) => {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.POVerificationBadge = exports.FILE_MAP = void 0;
7
7
  const types_1 = require("@raytio/types");
8
8
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
9
- const locales_1 = require("locales");
9
+ const locales_1 = require("../../locales");
10
10
  const general_1 = require("../helpers/general");
11
11
  const constants_1 = require("../../constants");
12
12
  exports.FILE_MAP = {
@@ -21,20 +21,20 @@ exports.FILE_MAP = {
21
21
  };
22
22
  const POVerificationBadge = ({ width, POs, }) => {
23
23
  // TODO: this won't work if multiple POs of the same schema are shared
24
- const { $verified, $verification_details, $shouldBeVerifiedFields, $safeHarbour, } = POs[0];
24
+ const { $badges, $verification_details, $shouldBeVerifiedFields } = POs[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: (0, general_1.loadAsset)(`${exports.FILE_MAP[$verified]}.svg`), width: width }),
29
- jsx_pdf_1.default.createElement("text", { alignment: "center" }, constants_1.PO_VER_TEXT_MAP[$verified]),
28
+ jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$badges.verified.code]}.svg`), width: width }),
29
+ jsx_pdf_1.default.createElement("text", { alignment: "center" }, constants_1.PO_VER_TEXT_MAP[$badges.verified.code]),
30
30
  verifiedBy && (jsx_pdf_1.default.createElement("text", { alignment: "center" }, (0, locales_1.$$)("POVerificationBadge.verified-by", { verifiedBy }))))),
31
- typeof $safeHarbour === "boolean" && (jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
31
+ $badges.safeHarbour && (jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
32
32
  jsx_pdf_1.default.createElement("column", { width: width / 3 },
33
- jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$safeHarbour
33
+ jsx_pdf_1.default.createElement("svg", { content: (0, general_1.loadAsset)(`${exports.FILE_MAP[$badges.safeHarbour.code
34
34
  ? types_1.POVerification.FullyVerified
35
35
  : types_1.POVerification.VerifiedFalse]}.svg`), width: width / 3 })),
36
36
  jsx_pdf_1.default.createElement("column", { width: "auto" },
37
- jsx_pdf_1.default.createElement("text", { alignment: "center" }, $safeHarbour
37
+ jsx_pdf_1.default.createElement("text", { alignment: "center" }, $badges.safeHarbour.code
38
38
  ? (0, locales_1.$$)("POVerificationBadge.safe-harbour-yes")
39
39
  : (0, locales_1.$$)("POVerificationBadge.safe-harbour-no")))))));
40
40
  };
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Report = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
8
  const crypto_1 = require("crypto");
9
- const locales_1 = require("locales");
9
+ const core_1 = require("@raytio/core");
10
+ const locales_1 = require("../../locales");
10
11
  const POVerificationBadge_1 = require("./POVerificationBadge");
11
12
  const Subheader_1 = require("./Subheader");
12
13
  const TableTitle_1 = require("./TableTitle");
@@ -56,7 +57,7 @@ const Report = ({ data, files, config, aId, clientUrl, envConfig, version, }) =>
56
57
  Object.entries(constants_1.SUBMISSION_DATA)
57
58
  .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
58
59
  .join("\n"),
59
- data.score
60
+ (0, core_1.isScoreResultValid)(data.score)
60
61
  ? [
61
62
  "",
62
63
  `${(0, locales_1.$$)("constants.score")}: ${data.score.score}`,
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Subheader = void 0;
7
7
  const types_1 = require("@raytio/types");
8
8
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
9
- const locales_1 = require("locales");
9
+ const locales_1 = require("../../locales");
10
10
  const FieldVerificationBadge_1 = require("./FieldVerificationBadge");
11
11
  const Subheader = () => {
12
12
  return (jsx_pdf_1.default.createElement(jsx_pdf_1.default.Fragment, null,
@@ -32,14 +32,14 @@ const Table = ({ POs, files, config, }) => {
32
32
  if (!PO.$properties[fieldName]) {
33
33
  return [jsx_pdf_1.default.createElement("cell", null, " "), jsx_pdf_1.default.createElement("cell", null, " ")];
34
34
  }
35
- const { value, verification } = PO.$properties[fieldName];
35
+ const { value, formatted_value, verification } = PO.$properties[fieldName];
36
36
  const color = (0, general_1.verifyColour)(verification);
37
37
  // jsx-pdf currently doesn't support fragments, will make a PR at some point
38
38
  return [
39
39
  jsx_pdf_1.default.createElement("cell", null,
40
40
  jsx_pdf_1.default.createElement(FieldVerificationBadge_1.FieldVerificationBadge, { width: 10, status: verification })),
41
41
  jsx_pdf_1.default.createElement("cell", null,
42
- jsx_pdf_1.default.createElement(InnerTableRows_1.InnerTableRows, { key: fieldName, value: value, files: files, config: config, color: color, imageFieldNames: imageFieldNames })),
42
+ jsx_pdf_1.default.createElement(InnerTableRows_1.InnerTableRows, { key: fieldName, value: formatted_value || value, files: files, config: config, color: color, imageFieldNames: imageFieldNames })),
43
43
  ];
44
44
  })));
45
45
  })));
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ValidationDisplay = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
- const locales_1 = require("locales");
8
+ const locales_1 = require("../../locales");
9
9
  const pieChart_1 = require("./pieChart");
10
10
  const helpers_1 = require("../../helpers");
11
11
  const SEVERITY_COLOURS = {
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.VerifyBox = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
- const locales_1 = require("locales");
8
+ const locales_1 = require("../../locales");
9
9
  const VerifyBox = ({ aId, iId, clientUrl }) => {
10
10
  const url = `${clientUrl}/apps/s/${aId}/i/${iId}`;
11
11
  return (jsx_pdf_1.default.createElement("stack", { alignment: "center" },
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SUBMISSION_DATA = void 0;
4
- const locales_1 = require("locales");
4
+ const locales_1 = require("../locales");
5
5
  exports.SUBMISSION_DATA = {
6
6
  confirmation_code: (0, locales_1.$$)("constants.confirmation_code"),
7
7
  i_id: (0, locales_1.$$)("constants.i_id"),
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transform = exports.IS_ARRAY_OF_OBJECTS = exports.IS_IMAGE = void 0;
4
- const locales_1 = require("locales");
4
+ const locales_1 = require("../../locales");
5
5
  const general_1 = require("./general");
6
6
  exports.IS_IMAGE = Symbol.for("image");
7
7
  exports.IS_ARRAY_OF_OBJECTS = Symbol.for("ArrayOfObjects");
@@ -18,7 +18,7 @@ const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
18
18
  const node_fetch_1 = __importDefault(require("node-fetch"));
19
19
  const fs_1 = require("fs");
20
20
  const path_1 = require("path");
21
- const locales_1 = require("locales");
21
+ const locales_1 = require("../locales");
22
22
  const Report_1 = require("../pdf/components/Report");
23
23
  const style_1 = require("../pdf/style");
24
24
  function generatePdfJson(data, DATE_FORMAT, TIMEZONE, version) {
@@ -6,6 +6,7 @@ import { ApplicationEncryptorLike } from "../types";
6
6
  declare type DecryptData = {
7
7
  apiToken: string;
8
8
  instance: Instance;
9
+ encryptedInstance: Instance;
9
10
  applicationDecryptor: ApplicationEncryptorLike;
10
11
  };
11
12
  export interface ProcessSubmissionInput {
@@ -31,7 +31,12 @@ function decryptStage(log, config, envConfig, instanceId) {
31
31
  maxcryptor,
32
32
  onCorruptedData: () => "🔒 Corrupted Data 🔒",
33
33
  });
34
- return { apiToken, instance, applicationDecryptor };
34
+ return {
35
+ apiToken,
36
+ instance,
37
+ applicationDecryptor,
38
+ encryptedInstance: apiResp,
39
+ };
35
40
  });
36
41
  }
37
42
  function processSubmission({ applicationId, instanceId, verbose, config, _supliedConfig, }) {
@@ -40,7 +45,7 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
40
45
  try {
41
46
  log("Fetching config...");
42
47
  const envConfig = yield (0, api_1.fetchEnvConfig)(config.CLIENT_URL);
43
- const { instance, apiToken, applicationDecryptor } = _supliedConfig ||
48
+ const { instance, apiToken, applicationDecryptor, encryptedInstance } = _supliedConfig ||
44
49
  (yield decryptStage(log, config, envConfig, instanceId));
45
50
  log("Checking verifications...");
46
51
  const [profileObjects, verifications] = (0, helpers_1.splitPOAndVers)(instance.profile_objects);
@@ -61,13 +66,20 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
61
66
  log("Fetching access application...");
62
67
  const AA = yield (0, api_1.fetchAA)(apiToken, envConfig, instance.a_id);
63
68
  let score;
64
- if (AA.ruleset &&
65
- typeof AA.ruleset === "object" &&
66
- Object.keys(AA.ruleset).length) {
69
+ if ((0, core_1.isScoreConfigValid)(AA.ruleset)) {
67
70
  const ruleInputData = yield (0, core_1.convertInstanceToRuleInput)(instance, realVers, (schemaName) => (0, api_1.getSchema)(envConfig, schemaName));
68
71
  try {
72
+ // decrypt helper never uses a stored score. We always re-calculate it.
69
73
  log("Calculating score...");
70
- score = (0, core_1.calculateScore)(AA.ruleset, ruleInputData);
74
+ score = yield (0, core_1.calculateScore)(AA.ruleset, ruleInputData);
75
+ if (!(0, ramda_1.equals)(instance.score, score)) {
76
+ // the score we calculated is different to the one that's saved on the instance.
77
+ // So we save the new score.
78
+ log("Saving score to instance...");
79
+ // this can happen silently in the background, but we await it since so that we
80
+ // abort if this fails.
81
+ yield (0, api_1.updateInstanceData)(apiToken, Object.assign(Object.assign({}, encryptedInstance), { score }));
82
+ }
71
83
  }
72
84
  catch (ex) {
73
85
  log(`Score calculation failed (${ex})`);
@@ -91,7 +103,7 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
91
103
  constants_1.FIELD_VER_TEXT_MAP[field.verification],
92
104
  ],
93
105
  ]);
94
- return Object.assign(Object.assign(Object.assign({}, flatPO), { $verified: constants_1.PO_VER_TEXT_MAP[flatPO.$verified] }), Object.fromEntries(obj));
106
+ return Object.assign(Object.assign({}, flatPO), Object.fromEntries(obj));
95
107
  }), PODetails)));
96
108
  log("Success!");
97
109
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "author": "Raytio",
5
5
  "description": "A helper to decrypt data shared by Raytio users",
6
6
  "main": "dist",
@@ -22,39 +22,39 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@aws-amplify/auth": "3.4.25",
25
- "@peculiar/webcrypto": "^1.3.2",
26
- "@raytio/core": "^9.0.3",
25
+ "@peculiar/webcrypto": "^1.4.0",
26
+ "@raytio/core": "^10.0.1",
27
27
  "@raytio/maxcryptor": "^3.1.0",
28
- "@raytio/types": "^6.0.0",
28
+ "@raytio/types": "^6.0.2",
29
29
  "aws-sdk": "^2.754.0",
30
30
  "jsx-pdf": "^2.3.0",
31
31
  "localstorage-polyfill": "^1.0.1",
32
32
  "mime-types": "^2.1.35",
33
33
  "node-fetch": "^2.6.7",
34
- "pdfmake": "^0.2.4",
34
+ "pdfmake": "^0.2.5",
35
35
  "ramda": "^0.28.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@raytio/react-intl-manager": "^6.2.0",
39
- "@types/jest": "^27.4.1",
40
- "@types/jest-image-snapshot": "^4.3.1",
38
+ "@raytio/react-intl-manager": "^6.3.0",
39
+ "@types/jest": "^28.1.4",
40
+ "@types/jest-image-snapshot": "^5.1.0",
41
41
  "@types/jsx-pdf": "^2.2.2",
42
42
  "@types/mime-types": "^2.1.1",
43
- "@types/node": "^16.11.26",
43
+ "@types/node": "^16.11.43",
44
44
  "@types/node-fetch": "^2.5.12",
45
- "@types/pdfmake": "^0.1.20",
46
- "@types/ramda": "^0.28.1",
45
+ "@types/pdfmake": "^0.2.0",
46
+ "@types/ramda": "^0.28.14",
47
47
  "babel-preset-react-app": "^10.0.1",
48
- "dotenv": "^16.0.0",
49
- "eslint": "^8.11.0",
50
- "eslint-config-kyle": "^8.13.0",
51
- "jest": "^27.5.1",
52
- "jest-image-snapshot": "^4.5.1",
53
- "jest-junit": "^13.0.0",
48
+ "dotenv": "^16.0.1",
49
+ "eslint": "^8.19.0",
50
+ "eslint-config-kyle": "^8.38.0",
51
+ "jest": "^28.1.2",
52
+ "jest-image-snapshot": "^5.1.0",
53
+ "jest-junit": "^14.0.0",
54
54
  "pdf-to-img": "^1.2.0",
55
- "ts-jest": "^27.1.3",
56
- "ts-node": "^10.7.0",
57
- "typescript": "^4.6.2"
55
+ "ts-jest": "^28.0.5",
56
+ "ts-node": "^10.8.2",
57
+ "typescript": "^4.7.4"
58
58
  },
59
59
  "eslintConfig": {
60
60
  "extends": "kyle",
@@ -119,6 +119,6 @@
119
119
  "localeDir": "src/locales/translations",
120
120
  "messagesDir": "tmp/.messages",
121
121
  "codeQualityReport": "tmp/codequality.json",
122
- "moduleSourceName": "locales"
122
+ "moduleSourceName": false
123
123
  }
124
124
  }