@raytio/decrypt-helper 5.1.1 → 5.1.3
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 +10 -0
- package/dist/api/authedFetch.d.ts +1 -1
- package/dist/api/authedFetch.js +12 -2
- package/dist/api/getFiles.d.ts +2 -2
- package/dist/api/getFiles.js +4 -3
- package/package.json +17 -16
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
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
|
+
|
|
10
20
|
## 5.1.1 (2022-08-15)
|
|
11
21
|
|
|
12
22
|
- !189 load verifier details faster
|
|
@@ -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>;
|
package/dist/api/authedFetch.js
CHANGED
|
@@ -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
|
-
|
|
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) {
|
|
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}`);
|
|
17
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
|
}
|
package/dist/api/getFiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Instance, ProfileObject } from "@raytio/types";
|
|
1
|
+
import type { Instance, NId, ProfileObject } from "@raytio/types";
|
|
2
2
|
import { ApplicationEncryptorLike } from "../types";
|
|
3
3
|
import { EnvConfig } from "./fetchEnvConfig";
|
|
4
|
-
export declare function getFiles(profileObjects: ProfileObject[], instance: Instance, apiToken: string, envConfig: EnvConfig, applicationDecryptor: ApplicationEncryptorLike): Promise<Record<
|
|
4
|
+
export declare function getFiles(profileObjects: ProfileObject[], instance: Instance, apiToken: string, envConfig: EnvConfig, applicationDecryptor: ApplicationEncryptorLike): Promise<Record<NId, [dataUrl: string, fileExtension: string]>>;
|
package/dist/api/getFiles.js
CHANGED
|
@@ -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;
|
|
@@ -29,7 +29,7 @@ const decryptFile = (encryptedData, encryptedObj, applicationDecryptor, wdek) =>
|
|
|
29
29
|
const cleanApiResponse = (responseBody) => {
|
|
30
30
|
try {
|
|
31
31
|
const realB64 = atob(responseBody);
|
|
32
|
-
if (realB64.
|
|
32
|
+
if (realB64.slice(0, 5) === "data:") {
|
|
33
33
|
return realB64;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -65,6 +65,7 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
|
|
|
65
65
|
const dataUrl = `data:${type};base64,${b64}`;
|
|
66
66
|
return [fileNId, [dataUrl, getFileExtn(dataUrl)]];
|
|
67
67
|
}
|
|
68
|
+
// TODO: should realB64 be renamed to "realDataUrl"?
|
|
68
69
|
const realB64 = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instance.i_id}/profile_object/${fileNId}/content`).then(cleanApiResponse);
|
|
69
70
|
if ((0, core_1.isEncrypted)(urnOrEncrypted)) {
|
|
70
71
|
const wdek = (_b = (_a = instance.keys[PONId]) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.data;
|
|
@@ -75,7 +76,7 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
|
|
|
75
76
|
}
|
|
76
77
|
return [fileNId, [realB64, getFileExtn(realB64)]];
|
|
77
78
|
})));
|
|
78
|
-
return Object.fromEntries(filesBase64.filter(([
|
|
79
|
+
return Object.fromEntries(filesBase64.filter((file) => { var _a; return !!file[1] && ((_a = file[1][0]) === null || _a === void 0 ? void 0 : _a.includes(",")); }));
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
exports.getFiles = getFiles;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytio/decrypt-helper",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"author": "Raytio",
|
|
5
5
|
"description": "A helper to decrypt data shared by Raytio users",
|
|
6
6
|
"main": "dist",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-amplify/auth": "3.4.25",
|
|
25
|
-
"@peculiar/webcrypto": "^1.4.
|
|
25
|
+
"@peculiar/webcrypto": "^1.4.1",
|
|
26
26
|
"@raytio/core": "^10.1.0",
|
|
27
27
|
"@raytio/maxcryptor": "^3.1.0",
|
|
28
28
|
"@raytio/types": "^6.0.2",
|
|
@@ -31,36 +31,37 @@
|
|
|
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.
|
|
34
|
+
"pdfmake": "^0.2.6",
|
|
35
35
|
"ramda": "^0.28.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@raytio/react-intl-manager": "^6.3.0",
|
|
39
|
-
"@types/jest": "^
|
|
39
|
+
"@types/jest": "^29.2.2",
|
|
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": "^
|
|
43
|
+
"@types/node": "^18.11.9",
|
|
44
44
|
"@types/node-fetch": "^2.5.12",
|
|
45
|
-
"@types/pdfmake": "^0.2.
|
|
46
|
-
"@types/ramda": "^0.28.
|
|
45
|
+
"@types/pdfmake": "^0.2.2",
|
|
46
|
+
"@types/ramda": "^0.28.19",
|
|
47
47
|
"babel-preset-react-app": "^10.0.1",
|
|
48
|
-
"dotenv": "^16.0.
|
|
49
|
-
"eslint": "^8.
|
|
50
|
-
"eslint-config-kyle": "^
|
|
51
|
-
"jest": "^
|
|
52
|
-
"jest-image-snapshot": "^
|
|
53
|
-
"jest-junit": "^14.0.
|
|
54
|
-
"pdf-to-img": "^
|
|
55
|
-
"ts-jest": "^
|
|
48
|
+
"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",
|
|
56
56
|
"ts-node": "^10.9.1",
|
|
57
|
-
"typescript": "^4.
|
|
57
|
+
"typescript": "^4.8.4"
|
|
58
58
|
},
|
|
59
59
|
"eslintConfig": {
|
|
60
60
|
"extends": "kyle",
|
|
61
61
|
"rules": {
|
|
62
62
|
"react/react-in-jsx-scope": 0,
|
|
63
63
|
"react/style-prop-object": 0,
|
|
64
|
+
"react/no-unknown-property": 0,
|
|
64
65
|
"@typescript-eslint/no-non-null-assertion": 0,
|
|
65
66
|
"@typescript-eslint/no-unused-vars": [
|
|
66
67
|
2,
|