@raytio/decrypt-helper 5.1.3 → 6.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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Intsall
9
9
 
10
- This SDK is designed to run on nodejs >=14.
10
+ This SDK is designed to run on nodejs >=18.
11
11
 
12
12
  ```sh
13
13
  npm install --save @raytio/decrypt-helper
@@ -87,3 +87,7 @@ We use jest for unit tests, snapshot tests of the PDF, and integration tests for
87
87
  To run tests, use `yarn test`. To run and update snapshots, use `yarn test -u`. You will need to configure the evironment variables in `.env` for integration tests.
88
88
 
89
89
  If jest apears to be stuck running the end-to-end tests, run `yarn jest --clearCache`.
90
+
91
+ ### Manual testing
92
+
93
+ You can also test changes to this code using serverless-offline, [see here for more info](https://gitlab.com/raytio/common/pdf-generate/-/tree/main/packages/pdf-generate#testing).
@@ -1,5 +1,5 @@
1
1
  declare const PARAMS: readonly ["cognito_region", "cognito_user_pool_id", "cognito_web_client_id", "api_url", "app_name", "logo_url"];
2
- export declare type EnvConfig = Record<typeof PARAMS[number], string> & {
2
+ export type EnvConfig = Record<(typeof PARAMS)[number], string> & {
3
3
  clientUrl: string;
4
4
  };
5
5
  export declare function fetchEnvConfig(clientUrl: string): Promise<EnvConfig>;
@@ -8,13 +8,9 @@ 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.getFiles = void 0;
16
13
  const core_1 = require("@raytio/core");
17
- const node_fetch_1 = __importDefault(require("node-fetch"));
18
14
  const mime_types_1 = require("mime-types");
19
15
  const file_1 = require("../helpers/file");
20
16
  const authedFetch_1 = require("./authedFetch");
@@ -28,7 +24,7 @@ const decryptFile = (encryptedData, encryptedObj, applicationDecryptor, wdek) =>
28
24
  });
29
25
  const cleanApiResponse = (responseBody) => {
30
26
  try {
31
- const realB64 = atob(responseBody);
27
+ const realB64 = Buffer.from(responseBody, "base64").toString("binary");
32
28
  if (realB64.slice(0, 5) === "data:") {
33
29
  return realB64;
34
30
  }
@@ -58,9 +54,9 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
58
54
  // handle urn:temp_object:
59
55
  if (typeof urnOrEncrypted === "string" &&
60
56
  urnOrEncrypted.startsWith(TEMP_OBJ_PREFIX)) {
61
- const url = atob(urnOrEncrypted.slice(TEMP_OBJ_PREFIX.length));
62
- const res = yield (0, node_fetch_1.default)(url);
63
- const b64 = (yield res.buffer()).toString("base64");
57
+ const url = Buffer.from(urnOrEncrypted.slice(TEMP_OBJ_PREFIX.length), "base64").toString("binary");
58
+ const res = yield fetch(url);
59
+ const b64 = new TextDecoder().decode(yield res.arrayBuffer());
64
60
  const type = res.headers.get("content-type") || "text/plain";
65
61
  const dataUrl = `data:${type};base64,${b64}`;
66
62
  return [fileNId, [dataUrl, getFileExtn(dataUrl)]];
@@ -1,3 +1,3 @@
1
1
  import type { Schema } from "@raytio/types";
2
2
  import { EnvConfig } from "./fetchEnvConfig";
3
- export declare function getSchema(envConfig: EnvConfig, name: string): Promise<Schema>;
3
+ export declare function getAllSchema(envConfig: EnvConfig): Promise<Schema[]>;
@@ -9,23 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getSchema = void 0;
12
+ exports.getAllSchema = void 0;
13
+ const core_1 = require("@raytio/core");
13
14
  const authedFetch_1 = require("./authedFetch");
14
- const cache = new Map();
15
- function $getSchema(envConfig, name) {
15
+ function getAllSchema(envConfig) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
- const [schemaHead, ...schemaTail] = name.split("_");
18
- const schema = yield (0, authedFetch_1.authedFetch)("", `${envConfig.api_url}/graph/v2/schema_public/${schemaHead}/${schemaTail.join("_")}?expand=true`);
19
- return Object.assign(Object.assign({}, schema), { name });
17
+ const list = yield (0, authedFetch_1.authedFetch)("", `${envConfig.api_url}/db/v1/schema?version_current=eq.true`);
18
+ return list.map((wrappedSchema) => (0, core_1.expandSchema)(wrappedSchema, list, [
19
+ process.env.PDF_LANGUAGE || process.env.DATE_FORMAT || "en-NZ",
20
+ ]));
20
21
  });
21
22
  }
22
- function getSchema(envConfig, name) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- if (cache.has(name))
25
- return cache.get(name);
26
- const promise = $getSchema(envConfig, name);
27
- cache.set(name, promise);
28
- return promise;
29
- });
30
- }
31
- exports.getSchema = getSchema;
23
+ exports.getAllSchema = getAllSchema;
@@ -1,9 +1,11 @@
1
1
  import type { VerificationProvider } from "@raytio/types";
2
2
  import { EnvConfig } from "./fetchEnvConfig";
3
- export declare type ResolvedVerificationProvider = {
3
+ export type ResolvedVerificationProvider = {
4
4
  verifier_id?: string;
5
5
  verifier_service_id?: string;
6
6
  verifier_source_id?: string;
7
7
  date?: string;
8
8
  };
9
9
  export declare function resolveVerificationDetails([details]: VerificationProvider[], envConfig: EnvConfig): Promise<ResolvedVerificationProvider | undefined>;
10
+ /** @deprecated - for use in unit tests only */
11
+ export declare const clearCache: () => void;
@@ -8,19 +8,15 @@ 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
- exports.resolveVerificationDetails = void 0;
16
- const node_fetch_1 = __importDefault(require("node-fetch"));
12
+ exports.clearCache = exports.resolveVerificationDetails = void 0;
17
13
  let verifiersPromise;
18
14
  function resolveVerificationDetails([details], envConfig) {
19
15
  var _a, _b, _c, _d;
20
16
  return __awaiter(this, void 0, void 0, function* () {
21
17
  if (!details)
22
18
  return undefined;
23
- verifiersPromise || (verifiersPromise = (0, node_fetch_1.default)(`${envConfig.clientUrl}/verifiers.json`)
19
+ verifiersPromise || (verifiersPromise = fetch(`${envConfig.clientUrl}/verifiers.json`)
24
20
  .then((r) => r.json())
25
21
  .catch(() => ({ verifiers: {} })));
26
22
  const { verifiers } = yield verifiersPromise;
@@ -33,3 +29,8 @@ function resolveVerificationDetails([details], envConfig) {
33
29
  });
34
30
  }
35
31
  exports.resolveVerificationDetails = resolveVerificationDetails;
32
+ /** @deprecated - for use in unit tests only */
33
+ const clearCache = () => {
34
+ verifiersPromise = null;
35
+ };
36
+ exports.clearCache = clearCache;
@@ -1,16 +1,30 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- // https://github.com/nodejs/webcrypto isn't stable enough.
7
- const webcrypto_1 = require("@peculiar/webcrypto");
26
+ const crypto = __importStar(require("node:crypto"));
8
27
  // for @aws-amplify/auth
9
28
  require("localstorage-polyfill");
10
- const node_fetch_1 = __importDefault(require("node-fetch"));
11
29
  // @ts-expect-error it's not a perfect polyfill..
12
- globalThis.fetch = node_fetch_1.default;
13
- globalThis.crypto = new webcrypto_1.Crypto();
14
- // polyfill btoa & atob for node. NOTE: Must specify "binary", or there will be obscure crypto bugs
15
- globalThis.btoa = (text) => Buffer.from(text, "binary").toString("base64");
16
- globalThis.atob = (b64) => Buffer.from(b64, "base64").toString("binary");
30
+ globalThis.crypto = crypto; // only required because jest-env-node hides globalThis.crypto
@@ -11,8 +11,8 @@ export declare const ATTRIBUTE_MAP: {
11
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
- export declare type Config = Record<typeof ENV_VARIABLES[number], string>;
15
- export declare type InstanceDataToPassOn = Omit<Instance, typeof INSTANCE_FIELDS_TO_REMOVE[number]> & {
14
+ export type Config = Record<(typeof ENV_VARIABLES)[number], string>;
15
+ export type InstanceDataToPassOn = Omit<Instance, (typeof INSTANCE_FIELDS_TO_REMOVE)[number]> & {
16
16
  score?: ScoreResult;
17
17
  };
18
18
  export declare const PO_VER_TEXT_MAP: Record<POVerification, string>;
@@ -1,6 +1,6 @@
1
1
  import type { Encrypted, NId, Urn } from "@raytio/types";
2
2
  import type { FlatPO } from "./formatOutput";
3
- export declare type RaytFile = {
3
+ export type RaytFile = {
4
4
  n_id: NId;
5
5
  content: Urn | Encrypted;
6
6
  } | {
@@ -1,6 +1,6 @@
1
1
  import { FieldVerification, NId, POVerification, ProfileObject, RealVer, Schema } from "@raytio/types";
2
2
  import { ResolvedVerificationProvider, EnvConfig } from "../api";
3
- export declare type FlatPO = {
3
+ export type FlatPO = {
4
4
  $verification_details: ResolvedVerificationProvider | undefined;
5
5
  $shouldBeVerifiedFields: string[] | undefined;
6
6
  $nId: NId;
@@ -77,7 +77,7 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig)
77
77
  : (0, locales_1.$$)("POVerificationBadge.safe-harbour-no"),
78
78
  }))(yield (0, core_1.calcSafeHarbourScore)({
79
79
  person: PO,
80
- getSchema: (name) => (0, api_1.getSchema)(envConfig, name),
80
+ getSchema: (name) => __awaiter(this, void 0, void 0, function* () { return allSchemas.find((x) => x.name === name); }),
81
81
  profileObjects,
82
82
  realVers,
83
83
  }))
package/dist/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export { generatePDF } from "./public-methods/generatePDF";
4
4
  export { processSubmission } from "./public-methods/processSubmission";
5
5
  export { getAndValidateConfig } from "./public-methods/getAndValidateConfig";
6
6
  export { saveToS3Bucket } from "./public-methods/saveToS3Bucket";
7
+ export { version } from "./public-methods/version";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.saveToS3Bucket = exports.getAndValidateConfig = exports.processSubmission = exports.generatePDF = exports.fetchEnvConfig = void 0;
3
+ exports.version = exports.saveToS3Bucket = exports.getAndValidateConfig = exports.processSubmission = exports.generatePDF = exports.fetchEnvConfig = void 0;
4
4
  // do this first
5
5
  require("./configureEnv");
6
6
  /* this is what consumers of the package have access to */
@@ -14,3 +14,5 @@ var getAndValidateConfig_1 = require("./public-methods/getAndValidateConfig");
14
14
  Object.defineProperty(exports, "getAndValidateConfig", { enumerable: true, get: function () { return getAndValidateConfig_1.getAndValidateConfig; } });
15
15
  var saveToS3Bucket_1 = require("./public-methods/saveToS3Bucket");
16
16
  Object.defineProperty(exports, "saveToS3Bucket", { enumerable: true, get: function () { return saveToS3Bucket_1.saveToS3Bucket; } });
17
+ var version_1 = require("./public-methods/version");
18
+ Object.defineProperty(exports, "version", { enumerable: true, get: function () { return version_1.version; } });
@@ -34,8 +34,8 @@ declare const locales: {
34
34
  "field.undefined": string;
35
35
  };
36
36
  };
37
- export declare type I18nKey = keyof typeof en;
38
- export declare type I18nLang = keyof typeof locales;
37
+ export type I18nKey = keyof typeof en;
38
+ export type I18nLang = keyof typeof locales;
39
39
  declare global {
40
40
  var lang: I18nLang;
41
41
  }
@@ -12,8 +12,9 @@ const $$ = (key, variables) => {
12
12
  const strings = locales[global.lang || "en"];
13
13
  const replaceWithVariable = (_, varName) => {
14
14
  const value = variables === null || variables === void 0 ? void 0 : variables[varName];
15
- if (!value)
15
+ if (typeof value === "undefined") {
16
16
  throw new Error(`[i18n] variable '${varName}' not defined`);
17
+ }
17
18
  return `${value}`;
18
19
  };
19
20
  return strings[key].replace(/{([^}]+)}/g, replaceWithVariable);
@@ -3,12 +3,11 @@ import type { AId } from "@raytio/types";
3
3
  import { PdfConfig } from "../types";
4
4
  import { EnvConfig } from "../../api";
5
5
  import { ProcessSubmissionOutput } from "../../public-methods/processSubmission";
6
- export declare const Report: ({ data, files, config, aId, clientUrl, envConfig, version, }: {
6
+ export declare const Report: ({ data, files, config, aId, clientUrl, envConfig, }: {
7
7
  data: ProcessSubmissionOutput["json"];
8
8
  files: ProcessSubmissionOutput["files"];
9
9
  config: PdfConfig;
10
10
  aId: AId;
11
11
  clientUrl: string;
12
12
  envConfig: EnvConfig;
13
- version: string;
14
13
  }) => JSX.Element;
@@ -18,7 +18,8 @@ const VerifyBox_1 = require("./VerifyBox");
18
18
  const constants_1 = require("../constants");
19
19
  const transform_1 = require("../helpers/transform");
20
20
  const constants_2 = require("../../constants");
21
- const Report = ({ data, files, config, aId, clientUrl, envConfig, version, }) => {
21
+ const version_1 = require("../../public-methods/version");
22
+ const Report = ({ data, files, config, aId, clientUrl, envConfig, }) => {
22
23
  // The PDF is read only; there's no reason why anyone would ever need to unlock it.
23
24
  const randomToken = (0, crypto_1.randomBytes)(32).toString("base64");
24
25
  const schemas = Object.values(data.profile_objects).sort(
@@ -29,11 +30,12 @@ const Report = ({ data, files, config, aId, clientUrl, envConfig, version, }) =>
29
30
  +(((_b = a[0]) === null || _b === void 0 ? void 0 : _b.$schemaName) === constants_2.SCHEMA.PERSON);
30
31
  });
31
32
  const appName = envConfig.app_name;
33
+ const iId = data.i_id === constants_1.NULL_I_ID ? "" : data.i_id;
32
34
  return (jsx_pdf_1.default.createElement("document", { defaultStyle: { font: "Lato", fontSize: 12 }, info: {
33
- title: (0, locales_1.$$)("Report.meta.title", { appName, iId: data.i_id }),
35
+ title: (0, locales_1.$$)("Report.meta.title", { appName, iId }),
34
36
  creator: appName,
35
37
  producer: "Raytio",
36
- subject: version,
38
+ subject: version_1.version,
37
39
  },
38
40
  // @ts-expect-error -- waiting on bpampuch/pdfmake#2453
39
41
  lang: global.lang, ownerPassword: randomToken, permissions: {
@@ -49,16 +51,17 @@ const Report = ({ data, files, config, aId, clientUrl, envConfig, version, }) =>
49
51
  jsx_pdf_1.default.createElement("text", { bold: true },
50
52
  (0, locales_1.$$)("Report.header", { appName }),
51
53
  " - "),
52
- jsx_pdf_1.default.createElement("text", null, data.i_id))))),
54
+ jsx_pdf_1.default.createElement("text", null, iId))))),
53
55
  jsx_pdf_1.default.createElement("content", null,
54
56
  jsx_pdf_1.default.createElement("image", { src: "raytioLogo", width: 150, alignment: "center" }),
55
57
  jsx_pdf_1.default.createElement("text", { style: ["header", "marginBottom"], alignment: "center" }, (0, locales_1.$$)("Report.header", { appName })),
56
58
  jsx_pdf_1.default.createElement("columns", { columnGap: 10 },
57
59
  jsx_pdf_1.default.createElement("column", { width: "auto" },
58
60
  jsx_pdf_1.default.createElement("text", { style: ["subheader", "marginBottom"] },
59
- Object.entries(constants_1.SUBMISSION_DATA)
60
- .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
61
- .join("\n"),
61
+ iId &&
62
+ Object.entries(constants_1.SUBMISSION_DATA)
63
+ .map(([id, label]) => `${label}: ${(0, transform_1.transform)(id, data[id], config)}`)
64
+ .join("\n"),
62
65
  (0, core_1.isScoreResultValid)(data.score)
63
66
  ? [
64
67
  "",
@@ -1,9 +1,9 @@
1
1
  /// <reference types="jsx-pdf" />
2
2
  import type { AId, IId } from "@raytio/types";
3
- declare type Props = {
3
+ type Props = {
4
4
  aId: AId;
5
5
  iId: IId;
6
6
  clientUrl: string;
7
7
  };
8
- export declare const VerifyBox: ({ aId, iId, clientUrl }: Props) => JSX.Element;
8
+ export declare const VerifyBox: ({ aId, iId, clientUrl }: Props) => JSX.Element | null;
9
9
  export {};
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.VerifyBox = void 0;
7
7
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
8
8
  const locales_1 = require("../../locales");
9
+ const constants_1 = require("../constants");
9
10
  const VerifyBox = ({ aId, iId, clientUrl }) => {
11
+ if (iId === constants_1.NULL_I_ID)
12
+ return null;
10
13
  const url = `${clientUrl}/apps/s/${aId}/i/${iId}`;
11
14
  return (jsx_pdf_1.default.createElement("stack", { alignment: "center" },
12
15
  jsx_pdf_1.default.createElement("text", { link: url }, (0, locales_1.$$)("VerifyBox.text")),
@@ -1,2 +1,3 @@
1
- import type { Instance } from "@raytio/types";
1
+ import type { IId, Instance } from "@raytio/types";
2
+ export declare const NULL_I_ID: IId;
2
3
  export declare const SUBMISSION_DATA: Partial<Record<keyof Instance, string>>;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUBMISSION_DATA = void 0;
3
+ exports.SUBMISSION_DATA = exports.NULL_I_ID = void 0;
4
4
  const locales_1 = require("../locales");
5
+ exports.NULL_I_ID = "00000000-0000-0000-0000-000000000000";
5
6
  exports.SUBMISSION_DATA = {
6
7
  confirmation_code: (0, locales_1.$$)("constants.confirmation_code"),
7
8
  i_id: (0, locales_1.$$)("constants.i_id"),
@@ -1,4 +1,4 @@
1
1
  import { TDocumentDefinitions } from "pdfmake/interfaces";
2
2
  import { ProcessSubmissionOutput } from "./processSubmission";
3
- export declare function generatePdfJson(data: ProcessSubmissionOutput, DATE_FORMAT: string, TIMEZONE: string, version: string): TDocumentDefinitions;
3
+ export declare function generatePdfJson(data: ProcessSubmissionOutput, DATE_FORMAT: string, TIMEZONE: string): TDocumentDefinitions;
4
4
  export declare const generatePDF: () => (data: ProcessSubmissionOutput) => Promise<ProcessSubmissionOutput>;
@@ -15,23 +15,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.generatePDF = exports.generatePdfJson = void 0;
16
16
  const pdfmake_1 = __importDefault(require("pdfmake"));
17
17
  const jsx_pdf_1 = __importDefault(require("jsx-pdf"));
18
- const node_fetch_1 = __importDefault(require("node-fetch"));
19
18
  const fs_1 = require("fs");
20
19
  const path_1 = require("path");
21
20
  const locales_1 = require("../locales");
22
21
  const Report_1 = require("../pdf/components/Report");
23
22
  const style_1 = require("../pdf/style");
24
- function generatePdfJson(data, DATE_FORMAT, TIMEZONE, version) {
25
- return jsx_pdf_1.default.renderPdf(jsx_pdf_1.default.createElement(Report_1.Report, { data: data.json, files: data.files, aId: data.a_id, clientUrl: data.client_url, envConfig: data.envConfig, config: { DATE_FORMAT, TIMEZONE }, version: version }));
23
+ function generatePdfJson(data, DATE_FORMAT, TIMEZONE) {
24
+ return jsx_pdf_1.default.renderPdf(jsx_pdf_1.default.createElement(Report_1.Report, { data: data.json, files: data.files, aId: data.a_id, clientUrl: data.client_url, envConfig: data.envConfig, config: { DATE_FORMAT, TIMEZONE } }));
26
25
  }
27
26
  exports.generatePdfJson = generatePdfJson;
28
27
  const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function* () {
29
28
  console.log("Generating PDF Report...");
30
29
  const { DATE_FORMAT = "en-nz", TIMEZONE = "Pacific/Auckland" } = process.env;
31
- const pkg = JSON.parse(yield fs_1.promises.readFile((0, path_1.join)(__dirname, "../../package.json"), "utf8"));
32
30
  if (data.envConfig.logo_url) {
33
31
  // there is a white labelling URL, so fetch it and write it to disk, overriding the default logo
34
- const arrayBuf = yield (0, node_fetch_1.default)(data.envConfig.logo_url).then((r) => r.arrayBuffer());
32
+ const arrayBuf = yield fetch(data.envConfig.logo_url).then((r) => r.arrayBuffer());
35
33
  yield fs_1.promises.writeFile((0, path_1.join)(__dirname, "../../assets/custom-logo.png"), Buffer.from(arrayBuf));
36
34
  }
37
35
  const customLang = process.env.PDF_LANGUAGE;
@@ -43,10 +41,9 @@ const generatePDF = () => (data) => __awaiter(void 0, void 0, void 0, function*
43
41
  console.warn(`The specified PDF_LANGUAGE is language is invalid (${customLang})`);
44
42
  }
45
43
  }
46
- const subject = `node:${process.version} pkg:${pkg.version} lang:${global.lang}`;
47
44
  return new Promise((resolve) => {
48
45
  const printer = new pdfmake_1.default(style_1.fonts);
49
- const pdfDoc = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE, subject));
46
+ const pdfDoc = printer.createPdfKitDocument(generatePdfJson(data, DATE_FORMAT, TIMEZONE));
50
47
  const chunks = [];
51
48
  pdfDoc.on("data", (chunk) => chunks.push(chunk));
52
49
  pdfDoc.on("end", () => {
@@ -1,13 +1,14 @@
1
- import type { AId, IId, Instance } from "@raytio/types";
1
+ import type { AId, IId, Instance, RealVer } from "@raytio/types";
2
2
  import { Config, InstanceDataToPassOn } from "../constants";
3
3
  import { FlatPO } from "../helpers";
4
4
  import { EnvConfig } from "../api";
5
5
  import { ApplicationEncryptorLike } from "../types";
6
- declare type DecryptData = {
6
+ type DecryptData = {
7
7
  apiToken: string;
8
8
  instance: Instance;
9
9
  encryptedInstance: Instance;
10
10
  applicationDecryptor: ApplicationEncryptorLike;
11
+ realVers?: RealVer[];
11
12
  };
12
13
  export interface ProcessSubmissionInput {
13
14
  /** The a_id of the application */
@@ -15,6 +15,7 @@ const core_1 = require("@raytio/core");
15
15
  const constants_1 = require("../constants");
16
16
  const helpers_1 = require("../helpers");
17
17
  const api_1 = require("../api");
18
+ const constants_2 = require("../pdf/constants");
18
19
  function decryptStage(log, config, envConfig, instanceId) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
20
21
  log("Authenticating...");
@@ -49,25 +50,28 @@ function processSubmission({ applicationId, instanceId, verbose, config, _suplie
49
50
  (yield decryptStage(log, config, envConfig, instanceId));
50
51
  log("Checking verifications...");
51
52
  const [profileObjects, verifications] = (0, helpers_1.splitPOAndVers)(instance.profile_objects);
52
- const realVers = yield (0, core_1.getSomeoneElsesRealVerifications)({
53
- aId: instance.a_id,
54
- apiUrl: envConfig.api_url,
55
- profileObjects,
56
- verifications,
57
- });
53
+ const realVers = (_supliedConfig === null || _supliedConfig === void 0 ? void 0 : _supliedConfig.realVers) ||
54
+ (yield (0, core_1.getSomeoneElsesRealVerifications)({
55
+ aId: instance.a_id,
56
+ apiUrl: envConfig.api_url,
57
+ profileObjects,
58
+ verifications,
59
+ }));
58
60
  log("Fetching relevant schema...");
59
- const schemaNames = profileObjects.map((PO) => {
60
- const schemaName = (0, core_1.findSchemaLabel)(PO.labels);
61
- if (!schemaName)
62
- throw new Error("Submission contains invalid objects");
63
- return schemaName;
64
- });
65
- const allSchemas = yield Promise.all((0, ramda_1.uniq)(schemaNames).map((name) => (0, api_1.getSchema)(envConfig, name)));
61
+ const allSchemas = yield (0, api_1.getAllSchema)(envConfig);
66
62
  log("Fetching access application...");
67
- const AA = yield (0, api_1.fetchAA)(apiToken, envConfig, instance.a_id);
63
+ const AA = instance.i_id === constants_2.NULL_I_ID
64
+ ? undefined
65
+ : yield (0, api_1.fetchAA)(apiToken, envConfig, instance.a_id);
68
66
  let score;
69
- if ((0, core_1.isScoreConfigValid)(AA.ruleset)) {
70
- const ruleInputData = yield (0, core_1.convertInstanceToRuleInput)(instance, realVers, (schemaName) => (0, api_1.getSchema)(envConfig, schemaName));
67
+ if (AA && (0, core_1.isScoreConfigValid)(AA.ruleset)) {
68
+ const ruleInputData = yield (0, core_1.convertInstanceToRuleInput)(instance.profile_objects, realVers, (schemaName) => __awaiter(this, void 0, void 0, function* () {
69
+ const schema = allSchemas.find((x) => x.name === schemaName);
70
+ if (!schema) {
71
+ throw new Error(`Could not find schema “${schemaName}”`);
72
+ }
73
+ return schema;
74
+ }));
71
75
  try {
72
76
  // decrypt helper never uses a stored score. We always re-calculate it.
73
77
  log("Calculating score...");
@@ -0,0 +1,2 @@
1
+ export declare const packageDotJson: any;
2
+ export declare const version: string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = exports.packageDotJson = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ exports.packageDotJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, "../../package.json"), "utf8"));
7
+ exports.version = Object.entries({
8
+ LANG: process.env.PDF_LANGUAGE || "default",
9
+ N: process.version.slice(1),
10
+ DH: exports.packageDotJson.version,
11
+ C: exports.packageDotJson.dependencies["@raytio/core"].slice(1),
12
+ T: exports.packageDotJson.dependencies["@raytio/types"].slice(1),
13
+ })
14
+ .map((kv) => kv.join("="))
15
+ .join(" ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "5.1.3",
3
+ "version": "6.0.0",
4
4
  "author": "Raytio",
5
5
  "description": "A helper to decrypt data shared by Raytio users",
6
6
  "main": "dist",
@@ -22,43 +22,42 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@aws-amplify/auth": "3.4.25",
25
- "@peculiar/webcrypto": "^1.4.1",
26
- "@raytio/core": "^10.1.0",
25
+ "@raytio/core": "^11.1.0",
27
26
  "@raytio/maxcryptor": "^3.1.0",
28
- "@raytio/types": "^6.0.2",
27
+ "@raytio/types": "^7.1.0",
29
28
  "aws-sdk": "^2.754.0",
30
29
  "jsx-pdf": "^2.3.0",
31
30
  "localstorage-polyfill": "^1.0.1",
32
31
  "mime-types": "^2.1.35",
33
- "node-fetch": "^2.6.7",
34
- "pdfmake": "^0.2.6",
35
- "ramda": "^0.28.0"
32
+ "pdfmake": "^0.2.7",
33
+ "ramda": "^0.29.0"
36
34
  },
37
35
  "devDependencies": {
38
- "@raytio/react-intl-manager": "^6.3.0",
39
- "@types/jest": "^29.2.2",
40
- "@types/jest-image-snapshot": "^5.1.0",
36
+ "@raytio/react-intl-manager": "^6.3.1",
37
+ "@types/jest": "^29.5.1",
38
+ "@types/jest-image-snapshot": "^6.1.0",
41
39
  "@types/jsx-pdf": "^2.2.2",
42
40
  "@types/mime-types": "^2.1.1",
43
- "@types/node": "^18.11.9",
44
- "@types/node-fetch": "^2.5.12",
41
+ "@types/node": "^18.15.12",
45
42
  "@types/pdfmake": "^0.2.2",
46
- "@types/ramda": "^0.28.19",
43
+ "@types/ramda": "^0.29.0",
47
44
  "babel-preset-react-app": "^10.0.1",
48
45
  "dotenv": "^16.0.3",
49
- "eslint": "^8.27.0",
50
- "eslint-config-kyle": "^9.12.1",
51
- "jest": "^29.3.1",
52
- "jest-image-snapshot": "^6.0.0",
53
- "jest-junit": "^14.0.1",
54
- "pdf-to-img": "^2.0.0",
55
- "ts-jest": "^29.0.3",
46
+ "eslint": "^8.38.0",
47
+ "eslint-config-kyle": "^11.7.0",
48
+ "jest": "^29.5.0",
49
+ "jest-image-snapshot": "^6.1.0",
50
+ "jest-junit": "^16.0.0",
51
+ "pdf-to-img": "^2.1.1",
52
+ "ts-jest": "^29.1.0",
56
53
  "ts-node": "^10.9.1",
57
- "typescript": "^4.8.4"
54
+ "typescript": "^5.0.4"
58
55
  },
59
56
  "eslintConfig": {
60
57
  "extends": "kyle",
61
58
  "rules": {
59
+ "import/extensions": 0,
60
+ "react/jsx-key": 0,
62
61
  "react/react-in-jsx-scope": 0,
63
62
  "react/style-prop-object": 0,
64
63
  "react/no-unknown-property": 0,
@@ -73,6 +72,7 @@
73
72
  "camelcase": 0
74
73
  }
75
74
  },
75
+ "prettier": {},
76
76
  "jest": {
77
77
  "testMatch": [
78
78
  "**/__tests__/?(*.)+(spec|test).[jt]s?(x)"
@@ -114,7 +114,7 @@
114
114
  "outputDirectory": "tmp"
115
115
  },
116
116
  "engines": {
117
- "node": ">=14"
117
+ "node": ">=18"
118
118
  },
119
119
  "i18n": {
120
120
  "localeDir": "src/locales/translations",
package/CHANGELOG.md DELETED
@@ -1,221 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- ## 5.1.3 (2022-11-11)
11
-
12
- - !196 fix more issues caused by corrupted images
13
- - !192, !194 automated dependency updates
14
-
15
- ## 5.1.2 (2022-11-10)
16
-
17
- - !195 retry API requests that fail with a 504 error
18
- - !195 fix crash from corrupted binary files
19
-
20
- ## 5.1.1 (2022-08-15)
21
-
22
- - !189 load verifier details faster
23
- - !187 automated dependency updates
24
-
25
- ## 5.1.0 (2022-08-13)
26
-
27
- - !188 update raytio/core so that `repairDate` is used on dates
28
- - !186 automated dependency updates
29
-
30
- ## 5.0.0 (2022-07-12)
31
-
32
- - 💥 BREAKING CHANGE: !185 use `accessToken` instead of `idToken` when communicating with the Raytio API
33
- - 💥 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)
34
- - !185 embed language into pdf
35
- - !184 automated dependency updates
36
-
37
- ## 4.0.0 (2022-07-08)
38
-
39
- - 💥 BREAKING CHANGE: !170 [json] [csv] changed the format of badges, the fields `$verified` and `$safeHarbour` have been replaced with `$badges`
40
- - !176 fix field values being unexpectedly transformed
41
- - !179 update dependencies
42
- - !182 save the calculated score to the instance
43
-
44
- ## 3.2.0 (2022-04-21)
45
-
46
- - !177 do not use `hashPassword` when logging in, and migrate old credentials
47
-
48
- ## 3.1.1 (2022-04-02)
49
-
50
- - !175 Fix import issue in v3.1
51
-
52
- ## 3.1.0 (2022-03-14)
53
-
54
- - !168 Support internationalizing the pdf
55
- - !167 Support while labelling the pdf
56
- - !166 List the person schema first in the PDF
57
- - !163, !165, !169, !171, !172 automated dependency updates
58
-
59
- ## 3.0.2 (2022-02-16)
60
-
61
- - !164 fix PDF bug for multiple POs from the same schema
62
- - !164 remove legacy internal property called `$source`
63
- - !164 fix field verification status being `undefined` instead of `NotVerified`/`60002`
64
- - 💥 BREAKING CHANGE: we no longer use `schema_group` to group schema in the json, csv, and pdf
65
-
66
- ## 3.0.1 (2022-02-15)
67
-
68
- - !162 fix bug with PDF generation
69
-
70
- ## 3.0.0 (2022-02-04)
71
-
72
- - 💥 BREAKING CHANGE: renamed the `USERNAME` & `PASSWORD` environment variables to `RAYTIO_USERNAME` & `RAYTIO_PASSWORD`
73
- - 💥 BREAKING CHANGE: removed the `READABLE_FIELD_NAMES` option
74
- - 💥 BREAKING CHANGE: [csv] added new columns, shifted other columns
75
- - 💥 BREAKING CHANGE: [json] removed some duplicate legacy fields, see #33
76
- - !156: various internal refactoring
77
-
78
- ## 2.2.1 (2022-02-09)
79
-
80
- - !158 include the submission score in the json and pdf
81
-
82
- ## 2.2.0 (2022-02-04)
83
-
84
- - !153 fix rendering of arrays of primitive values
85
- - !152 Update @raytio/core to v9 to fix a bug with `hashed_n_id`
86
- - !155, !154, !146, !147, !150, !151 automated dependency updates
87
-
88
- ## 2.1.3 (2021-10-08)
89
-
90
- - !134 Add more logging to `saveToS3Bucket`
91
- - !129, !131, !132, !133 automated dependency updates
92
-
93
- ## 2.1.2 (2021-09-24)
94
-
95
- - !129 Update @raytio/core to v8.1.2 to support the new API format for `hashed_n_id`
96
-
97
- ## 2.1.1 (2021-09-15)
98
-
99
- - !126 Update @raytio/core to v8.1.1 to fix a bug with `hashed_n_id`
100
-
101
- ## 2.1.0 (2021-09-03)
102
-
103
- - !117 Update @raytio/core to v8
104
- - !120 Render document validation score
105
-
106
- ## 2.0.0 (2021-06-28)
107
-
108
- - 💥 BREAKING CHANGE: requires nodejs v14 or newer
109
- - 💥 BREAKING CHANGE: dates in the PDF will now use the `DATE_FORMAT` and `TIMEZONE` environment variables, which were previously required, but not used due to a bug in node v12.
110
- - removed various polyfills for node12, which reduced the install size by 26MB
111
-
112
- ## 1.4.1 (2021-05-21)
113
-
114
- - !103 embed decrypt-helper version into PDF metadata
115
- - !101, !100, !99, !98, !97, !96, !94, !93, !87 automated dependency updates
116
-
117
- ## 1.4.0 (2021-04-27)
118
-
119
- - !95 release
120
- - !92 remove base64 of encrypted images from json output
121
- - !91 use schema lookups in the pdf report
122
- - !90 only show verification badges in the pdf report if the the data is verifiable
123
- - !89 automated dependency updates
124
-
125
- ## 1.3.4 (2021-04-15)
126
-
127
- - !86 Fix first row of table being simulating table header on page break when table header isn't specified.
128
- - !85 update maxcryptor
129
- - !75 refresh lockfile
130
-
131
- ## 1.3.3 (2021-04-14)
132
-
133
- - !84 minor refactoring
134
-
135
- ## 1.3.2 (2021-04-13)
136
-
137
- - !80 update raytio packages
138
- - !77, !78, !82 automated dependency updates
139
-
140
- ## 1.3.1 (2021-03-21)
141
-
142
- - !73 fixes a bug introduced in `1.3.0` where the content type of images from `urn:temp_object:` was wrong
143
-
144
- ## 1.3.0 (2021-03-21)
145
-
146
- - !72 handle images from `urn:temp_object:`
147
- - !71 automated dependency updates
148
-
149
- ## 1.2.1 (2021-03-17)
150
-
151
- - !70 improve fetchEnvConfig debugging
152
- - !68 tweak renovate config
153
- - !64, !69 automated dependency updates
154
-
155
- ## 1.2.0 (2021-03-10)
156
-
157
- - !67 support encrypted images
158
- - !60, !66 automated dependency updates
159
-
160
- # 1.1.1 (2021-03-03)
161
-
162
- - !63 upgrade raytio packages
163
- - !61, !62 automated dependency updates
164
-
165
- ## 1.1.0 (2021-02-26)
166
-
167
- - !57 release
168
- - !55 fix bug
169
- - !51 support arrays of objects in PDF
170
- - !32 add screenshot tests for PDF generation
171
- - !20, !21, !22, !23, !24, !25, !27, !28, !29, !30, !33, !36, !38, !39, !41, !43, !45, !46, !49, !50, !54 automated dependency updates
172
- - !19, !53 set up automated dependency updates
173
-
174
- ## 1.0.1 (2021-01-27)
175
-
176
- - !18 fix: fix bug in PDF generation
177
-
178
- ## 1.0.0 (2021-01-21)
179
-
180
- - versioning now follow semver. This update in itself is not a breaking change
181
- - !16 fix: handle corrupted submission data
182
-
183
- ## 0.0.10 (2021-01-21)
184
-
185
- - !15 chore: enable more logging if processing a submission fails
186
- - !15 chore: update raytio packages
187
-
188
- ## 0.0.9 (2021-01-09)
189
-
190
- - !14 fix: show a nicer error if an invalid clientUrl is supplied
191
-
192
- ## 0.0.8 (2021-01-08)
193
-
194
- - !12 feat(pdf): add Safe Harbour badge to pdf
195
- - !12 feat(json): add more details to json data (`$nId`, `$schemaName`, `$properties`)
196
-
197
- ## 0.0.7 (2021-01-07)
198
-
199
- - !13 feat: export the `fetchEnvConfig` function
200
-
201
- ## 0.0.6 (2020-12-16)
202
-
203
- - !11 fix: update @raytio/core to fix verification bugs
204
-
205
- ## 0.0.5 (2020-11-20)
206
-
207
- - !10 fix: update @raytio/core to fix bug
208
- - !9 feat: use schema groups
209
-
210
- ## 0.0.4 (2020-11-13)
211
-
212
- - !8 fix(pdf): change hard to read green text
213
- - !8 chore: update dependencies
214
-
215
- ## 0.0.3 (2020-10-16)
216
-
217
- - !7 feat(`saveToS3Bucket`): store data in folder based on `i_id`.
218
-
219
- ## 0.0.2 (2020-10-09)
220
-
221
- First stable release