@raytio/decrypt-helper 3.2.0 → 5.1.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,13 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 5.1.0 (2022-08-13)
11
+
12
+ - update raytio/core so that `repairDate` is used on dates
13
+
14
+ ## 5.0.0 (2022-07-12)
15
+
16
+ - 💥 BREAKING CHANGE: !185 use `accessToken` instead of `idToken` when communicating with the Raytio API
17
+ - 💥 BREAKING CHANGE: !185 Improve how quotes (`"`) are escaped in the csv format to be compliant with [RFC-4180](https://datatracker.ietf.org/doc/html/rfc4180#section-2)
18
+ - !185 embed language into pdf
19
+
20
+ ## 4.0.0 (2022-07-08)
21
+
22
+ - 💥 BREAKING CHANGE: !170 [json] [csv] changed the format of badges, the fields `$verified` and `$safeHarbour` have been replaced with `$badges`
23
+ - !176 fix field values being unexpectedly transformed
24
+ - !179 update dependencies
25
+ - !182 save the calculated score to the instance
26
+
10
27
  ## 3.2.0 (2022-04-21)
11
28
 
12
29
  - !177 do not use `hashPassword` when logging in, and migrate old credentials
13
30
 
14
31
  ## 3.1.1 (2022-04-02)
15
32
 
16
- - !168 Fix import issue in v3.1
33
+ - !175 Fix import issue in v3.1
17
34
 
18
35
  ## 3.1.0 (2022-03-14)
19
36
 
@@ -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
  }
@@ -48,7 +48,7 @@ function signIn(CONFIG, envConfig) {
48
48
  throw new Error(`The configured account (${CONFIG.RAYTIO_USERNAME}) has two factor authentication enabled. You must disable 2FA or use a different account`);
49
49
  }
50
50
  const user = yield auth_1.Auth.currentAuthenticatedUser();
51
- const apiToken = (_b = (_a = user.signInUserSession) === null || _a === void 0 ? void 0 : _a.idToken) === null || _b === void 0 ? void 0 : _b.jwtToken;
51
+ const apiToken = (_b = (_a = user.signInUserSession) === null || _a === void 0 ? void 0 : _a.accessToken) === null || _b === void 0 ? void 0 : _b.jwtToken;
52
52
  const cognitoAttributes = yield auth_1.Auth.userAttributes(user);
53
53
  return { apiToken, cognitoAttributes };
54
54
  });
@@ -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
@@ -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({}));
@@ -17,7 +17,7 @@ function deepJsonToCsv(json) {
17
17
  const flatJson = (0, exports.flattenObj)(json);
18
18
  const [headerRow, values] = (0, ramda_1.transpose)(Object.entries(flatJson));
19
19
  const toCsvRow = (row) => row
20
- .map((field) => typeof field === "string" ? `"${field.replace(/"/g, '\\"')}"` : field)
20
+ .map((field) => typeof field === "string" ? `"${field.replace(/"/g, '""')}"` : field)
21
21
  .join(",");
22
22
  return `${toCsvRow(headerRow)}\n${toCsvRow(values)}`;
23
23
  }
@@ -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 {};
@@ -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,6 +6,7 @@ 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 core_1 = require("@raytio/core");
9
10
  const locales_1 = require("../../locales");
10
11
  const POVerificationBadge_1 = require("./POVerificationBadge");
11
12
  const Subheader_1 = require("./Subheader");
@@ -33,7 +34,9 @@ const Report = ({ data, files, config, aId, clientUrl, envConfig, version, }) =>
33
34
  creator: appName,
34
35
  producer: "Raytio",
35
36
  subject: version,
36
- }, ownerPassword: randomToken, permissions: {
37
+ },
38
+ // @ts-expect-error -- waiting on bpampuch/pdfmake#2453
39
+ lang: global.lang, ownerPassword: randomToken, permissions: {
37
40
  printing: "highResolution",
38
41
  copying: true, // allow copy/paste
39
42
  }, pageSize: "A4", styles: style_1.classes, images: {
@@ -56,7 +59,7 @@ const Report = ({ data, files, config, aId, clientUrl, envConfig, version, }) =>
56
59
  Object.entries(constants_1.SUBMISSION_DATA)
57
60
  .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
58
61
  .join("\n"),
59
- data.score
62
+ (0, core_1.isScoreResultValid)(data.score)
60
63
  ? [
61
64
  "",
62
65
  `${(0, locales_1.$$)("constants.score")}: ${data.score.score}`,
@@ -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
  })));
@@ -1,6 +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 core_1 = require("@raytio/core");
4
5
  const locales_1 = require("../../locales");
5
6
  const general_1 = require("./general");
6
7
  exports.IS_IMAGE = Symbol.for("image");
@@ -28,7 +29,7 @@ function transform(key, value, pdfConfig, imageFieldNames) {
28
29
  switch (key) {
29
30
  case "start_date":
30
31
  case "end_date": {
31
- return (0, general_1.formatDate)(new Date(`${value}Z`), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
32
+ return (0, general_1.formatDate)((0, core_1.repairDate)(value), pdfConfig.DATE_FORMAT, pdfConfig.TIMEZONE);
32
33
  }
33
34
  default: {
34
35
  return value;
@@ -29,7 +29,6 @@ const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function*
29
29
  console.log("Generating PDF Report...");
30
30
  const { DATE_FORMAT = "en-nz", TIMEZONE = "Pacific/Auckland" } = process.env;
31
31
  const pkg = JSON.parse(yield fs_1.promises.readFile((0, path_1.join)(__dirname, "../../package.json"), "utf8"));
32
- const version = `node:${process.version} pkg:${pkg.version}`;
33
32
  if (data.envConfig.logo_url) {
34
33
  // there is a white labelling URL, so fetch it and write it to disk, overriding the default logo
35
34
  const arrayBuf = yield (0, node_fetch_1.default)(data.envConfig.logo_url).then((r) => r.arrayBuffer());
@@ -44,9 +43,10 @@ const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function*
44
43
  console.warn(`The specified PDF_LANGUAGE is language is invalid (${customLang})`);
45
44
  }
46
45
  }
46
+ const subject = `node:${process.version} pkg:${pkg.version} lang:${global.lang}`;
47
47
  return new Promise((resolve) => {
48
48
  const printer = new pdfmake_1.default(style_1.fonts);
49
- const pdfDoc = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE, version));
49
+ const pdfDoc = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE, subject));
50
50
  const chunks = [];
51
51
  pdfDoc.on("data", (chunk) => chunks.push(chunk));
52
52
  pdfDoc.on("end", () => {
@@ -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.2.0",
3
+ "version": "5.1.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.1.0",
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
38
  "@raytio/react-intl-manager": "^6.3.0",
39
- "@types/jest": "^27.4.1",
40
- "@types/jest-image-snapshot": "^4.3.1",
39
+ "@types/jest": "^28.1.6",
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.45",
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.15",
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.20.0",
50
+ "eslint-config-kyle": "^8.40.0",
51
+ "jest": "^28.1.3",
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.7",
56
+ "ts-node": "^10.9.1",
57
+ "typescript": "^4.7.4"
58
58
  },
59
59
  "eslintConfig": {
60
60
  "extends": "kyle",