@raytio/decrypt-helper 5.1.0 → 5.1.2

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,15 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 5.1.2 (2022-11-10)
11
+
12
+ - !195 retry API requests that fail with a 504 error
13
+ - !195 fix crash from corrupted binary files
14
+
15
+ ## 5.1.1 (2022-08-15)
16
+
17
+ - !189 load verifier details faster
18
+ - !187 automated dependency updates
19
+
10
20
  ## 5.1.0 (2022-08-13)
11
21
 
12
- - update raytio/core so that `repairDate` is used on dates
22
+ - !188 update raytio/core so that `repairDate` is used on dates
23
+ - !186 automated dependency updates
13
24
 
14
25
  ## 5.0.0 (2022-07-12)
15
26
 
16
27
  - 💥 BREAKING CHANGE: !185 use `accessToken` instead of `idToken` when communicating with the Raytio API
17
28
  - 💥 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
29
  - !185 embed language into pdf
30
+ - !184 automated dependency updates
19
31
 
20
32
  ## 4.0.0 (2022-07-08)
21
33
 
@@ -1 +1 @@
1
- export declare function authedFetch<T>(apiToken: string, url: string, options?: RequestInit): Promise<T>;
1
+ export declare function authedFetch<T>(apiToken: string, url: string, options?: RequestInit, retrying?: boolean): Promise<T>;
@@ -10,12 +10,22 @@ 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, options) {
13
+ function authedFetch(apiToken, url, options, retrying = false) {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
- const apiResp = yield fetch(url, Object.assign(Object.assign({}, options), { headers: { Authorization: `Bearer ${apiToken}` } })).then((r) => r.json());
15
+ console.log(`[API] ${retrying ? "Retry" : "Start"} ${url}`);
16
+ const startTime = +new Date();
17
+ const req = yield fetch(url, Object.assign(Object.assign({}, options), { headers: { Authorization: `Bearer ${apiToken}` } }));
18
+ const apiResp = yield req.json();
16
19
  if (apiResp.message) {
17
- throw new Error(`Failed due to API Error: "${apiResp.message}"`);
20
+ if (!retrying && req.status === 504) {
21
+ console.log(`[API] Error ${req.status} (will retry) ${url}`);
22
+ return authedFetch(apiToken, url, options, true);
23
+ }
24
+ console.log(`[API] Error ${req.status} (no retry) ${url}`);
25
+ throw new Error(`Failed due to API Error from ${url}: "${apiResp.message}"`);
18
26
  }
27
+ const totalTime = ((+new Date() - startTime) / 1000).toFixed(1);
28
+ console.log(`[API] Finish${retrying ? " after retry" : ""} (${totalTime}s) ${url}`);
19
29
  return apiResp;
20
30
  });
21
31
  }
@@ -1,4 +1,6 @@
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 declare type EnvConfig = Record<typeof PARAMS[number], string> & {
3
+ clientUrl: string;
4
+ };
3
5
  export declare function fetchEnvConfig(clientUrl: string): Promise<EnvConfig>;
4
6
  export {};
@@ -29,7 +29,7 @@ function fetchEnvConfig(clientUrl) {
29
29
  const missing = PARAMS.filter((p) => !(p in envConfig));
30
30
  if (missing.length)
31
31
  throw new Error(`Missing: ${missing.join(", ")}`);
32
- return envConfig;
32
+ return Object.assign(Object.assign({}, envConfig), { clientUrl });
33
33
  }
34
34
  catch (ex) {
35
35
  throw new Error(`The CLIENT_URL you specified is not a valid Raytio client. Are you sure you used the client URL, not the API url? You supplied: "${clientUrl}" (${ex})`);
@@ -19,7 +19,7 @@ const mime_types_1 = require("mime-types");
19
19
  const file_1 = require("../helpers/file");
20
20
  const authedFetch_1 = require("./authedFetch");
21
21
  const TEMP_OBJ_PREFIX = "urn:temp_object:";
22
- const getFileExtn = (b64) => (0, mime_types_1.extension)(b64.split(":")[1].split(";base64,")[0]) || "txt";
22
+ const getFileExtn = (b64) => { var _a; return (0, mime_types_1.extension)(((_a = b64.split(":")[1]) === null || _a === void 0 ? void 0 : _a.split(";base64,")[0]) || "text/plain") || "txt"; };
23
23
  const decryptFile = (encryptedData, encryptedObj, applicationDecryptor, wdek) => __awaiter(void 0, void 0, void 0, function* () {
24
24
  const clonedEncryptedObj = JSON.parse(JSON.stringify(encryptedObj));
25
25
  clonedEncryptedObj.encrypted_data.data = encryptedData;
@@ -3,7 +3,6 @@ export * from "./fetchAA";
3
3
  export * from "./fetchEnvConfig";
4
4
  export * from "./fetchInstanceData";
5
5
  export * from "./getFiles";
6
- export * from "./getProfileObject";
7
6
  export * from "./getSchema";
8
7
  export * from "./resolveVerificationDetails";
9
8
  export * from "./signIn";
package/dist/api/index.js CHANGED
@@ -19,7 +19,6 @@ __exportStar(require("./fetchAA"), exports);
19
19
  __exportStar(require("./fetchEnvConfig"), exports);
20
20
  __exportStar(require("./fetchInstanceData"), exports);
21
21
  __exportStar(require("./getFiles"), exports);
22
- __exportStar(require("./getProfileObject"), exports);
23
22
  __exportStar(require("./getSchema"), exports);
24
23
  __exportStar(require("./resolveVerificationDetails"), exports);
25
24
  __exportStar(require("./signIn"), exports);
@@ -6,4 +6,4 @@ export declare type ResolvedVerificationProvider = {
6
6
  verifier_source_id?: string;
7
7
  date?: string;
8
8
  };
9
- export declare function resolveVerificationDetails([details]: VerificationProvider[], apiToken: string, envConfig: EnvConfig): Promise<ResolvedVerificationProvider | undefined>;
9
+ export declare function resolveVerificationDetails([details]: VerificationProvider[], envConfig: EnvConfig): Promise<ResolvedVerificationProvider | undefined>;
@@ -8,30 +8,27 @@ 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
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.resolveVerificationDetails = void 0;
13
- const getProfileObject_1 = require("./getProfileObject");
14
- function resolveVerificationDetails([details], apiToken, envConfig) {
15
- var _a;
16
+ const node_fetch_1 = __importDefault(require("node-fetch"));
17
+ let verifiersPromise;
18
+ function resolveVerificationDetails([details], envConfig) {
19
+ var _a, _b, _c, _d;
16
20
  return __awaiter(this, void 0, void 0, function* () {
17
21
  if (!details)
18
22
  return undefined;
19
- const maybeGet = (nId) => __awaiter(this, void 0, void 0, function* () {
20
- var _b, _c;
21
- return nId
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
23
- : undefined;
24
- });
25
- const [verifier_id, verifier_service_id, verifier_source_id] = yield Promise.all([
26
- maybeGet(details.dataSourceNId),
27
- maybeGet(details.serviceProviderNId),
28
- maybeGet(details.verifierNId),
29
- ]);
23
+ verifiersPromise || (verifiersPromise = (0, node_fetch_1.default)(`${envConfig.clientUrl}/verifiers.json`)
24
+ .then((r) => r.json())
25
+ .catch(() => ({ verifiers: {} })));
26
+ const { verifiers } = yield verifiersPromise;
30
27
  return {
31
- verifier_id,
32
- verifier_service_id,
33
- verifier_source_id,
34
- date: (_a = details.date) === null || _a === void 0 ? void 0 : _a.toISOString(),
28
+ verifier_id: (_a = verifiers[details.verifierNId]) === null || _a === void 0 ? void 0 : _a.name,
29
+ verifier_service_id: (_b = verifiers[details.serviceProviderNId]) === null || _b === void 0 ? void 0 : _b.name,
30
+ verifier_source_id: (_c = verifiers[details.dataSourceNId]) === null || _c === void 0 ? void 0 : _c.name,
31
+ date: (_d = details.date) === null || _d === void 0 ? void 0 : _d.toISOString(),
35
32
  };
36
33
  });
37
34
  }
@@ -58,7 +58,7 @@ function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig)
58
58
  return Object.assign(Object.assign({}, accP), { [key]: obj });
59
59
  }), Promise.resolve({}));
60
60
  const thisPO = {
61
- $verification_details: yield (0, api_1.resolveVerificationDetails)(verDetails.details.verifiers, apiToken, envConfig),
61
+ $verification_details: yield (0, api_1.resolveVerificationDetails)(verDetails.details.verifiers, envConfig),
62
62
  $shouldBeVerifiedFields: (_a = schema.verified_fields) === null || _a === void 0 ? void 0 : _a.map((x) => typeof x === "string" ? x : x.field),
63
63
  $nId: PO.n_id,
64
64
  $schemaName: schemaName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "author": "Raytio",
5
5
  "description": "A helper to decrypt data shared by Raytio users",
6
6
  "main": "dist",
@@ -40,14 +40,14 @@
40
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.45",
43
+ "@types/node": "^16.11.48",
44
44
  "@types/node-fetch": "^2.5.12",
45
- "@types/pdfmake": "^0.2.0",
45
+ "@types/pdfmake": "^0.2.1",
46
46
  "@types/ramda": "^0.28.15",
47
47
  "babel-preset-react-app": "^10.0.1",
48
48
  "dotenv": "^16.0.1",
49
- "eslint": "^8.20.0",
50
- "eslint-config-kyle": "^8.40.0",
49
+ "eslint": "^8.22.0",
50
+ "eslint-config-kyle": "^8.47.0",
51
51
  "jest": "^28.1.3",
52
52
  "jest-image-snapshot": "^5.1.0",
53
53
  "jest-junit": "^14.0.0",
@@ -1,3 +0,0 @@
1
- import type { NId, ProfileObject } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
3
- export declare function getProfileObject(envConfig: EnvConfig, apiToken: string, nId: NId): Promise<ProfileObject>;
@@ -1,19 +0,0 @@
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.getProfileObject = void 0;
13
- const authedFetch_1 = require("./authedFetch");
14
- function getProfileObject(envConfig, apiToken, nId) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- return (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/graph/v2/profile_object/${nId}`);
17
- });
18
- }
19
- exports.getProfileObject = getProfileObject;