@raytio/decrypt-helper 6.2.0 → 6.3.1
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 +2 -2
- package/dist/api/authedFetch.js +1 -5
- package/dist/api/fetchAA.d.ts +2 -2
- package/dist/api/fetchAA.js +3 -7
- package/dist/api/fetchEnvConfig.js +2 -6
- package/dist/api/fetchInstanceData.d.ts +3 -3
- package/dist/api/fetchInstanceData.js +3 -8
- package/dist/api/getFiles.d.ts +2 -2
- package/dist/api/getFiles.js +59 -26
- package/dist/api/getLookupOption.d.ts +1 -1
- package/dist/api/getLookupOption.js +3 -7
- package/dist/api/getSchema.d.ts +1 -1
- package/dist/api/getSchema.js +5 -9
- package/dist/api/index.d.ts +9 -9
- package/dist/api/index.js +9 -25
- package/dist/api/resolveVerificationDetails.d.ts +1 -1
- package/dist/api/resolveVerificationDetails.js +2 -7
- package/dist/api/signIn.d.ts +2 -2
- package/dist/api/signIn.js +10 -14
- package/dist/api/updateInstanceData.d.ts +7 -2
- package/dist/api/updateInstanceData.js +7 -7
- package/dist/api/uploadToObjectStore.d.ts +1 -1
- package/dist/api/uploadToObjectStore.js +3 -7
- package/dist/api/videoToImage.d.ts +1 -1
- package/dist/api/videoToImage.js +5 -9
- package/dist/configureEnv.js +17 -28
- package/dist/constants.d.ts +3 -3
- package/dist/constants.js +20 -23
- package/dist/helpers/file.d.ts +5 -1
- package/dist/helpers/file.js +8 -9
- package/dist/helpers/formatOutput.d.ts +2 -2
- package/dist/helpers/formatOutput.js +24 -28
- package/dist/helpers/index.d.ts +6 -6
- package/dist/helpers/index.js +6 -22
- package/dist/helpers/json2csv.js +11 -15
- package/dist/helpers/lookup.d.ts +1 -1
- package/dist/helpers/lookup.js +16 -7
- package/dist/helpers/pathUtils.d.ts +1 -0
- package/dist/helpers/pathUtils.js +6 -0
- package/dist/helpers/setupMaxcryptor.d.ts +3 -3
- package/dist/helpers/setupMaxcryptor.js +9 -12
- package/dist/helpers/splitPOAndVers.js +4 -8
- package/dist/helpers/types.js +1 -5
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -16
- package/dist/locales/index.js +4 -12
- package/dist/pdf/components/FieldVerificationBadge.d.ts +0 -1
- package/dist/pdf/components/FieldVerificationBadge.js +8 -15
- package/dist/pdf/components/Images.d.ts +1 -2
- package/dist/pdf/components/Images.js +7 -14
- package/dist/pdf/components/InnerTableRows.d.ts +2 -3
- package/dist/pdf/components/InnerTableRows.js +19 -26
- package/dist/pdf/components/POVerificationBadge.d.ts +1 -2
- package/dist/pdf/components/POVerificationBadge.js +28 -35
- package/dist/pdf/components/Report.d.ts +3 -4
- package/dist/pdf/components/Report.js +61 -68
- package/dist/pdf/components/Subheader.d.ts +0 -1
- package/dist/pdf/components/Subheader.js +20 -27
- package/dist/pdf/components/Table.d.ts +3 -4
- package/dist/pdf/components/Table.js +21 -28
- package/dist/pdf/components/TableTitle.d.ts +1 -2
- package/dist/pdf/components/TableTitle.js +5 -12
- package/dist/pdf/components/ValidationDisplay.d.ts +1 -2
- package/dist/pdf/components/ValidationDisplay.js +10 -17
- package/dist/pdf/components/VerifyBox.d.ts +0 -1
- package/dist/pdf/components/VerifyBox.js +9 -16
- package/dist/pdf/components/pieChart.js +1 -5
- package/dist/pdf/constants.js +8 -11
- package/dist/pdf/helpers/general.js +12 -18
- package/dist/pdf/helpers/transform.d.ts +1 -1
- package/dist/pdf/helpers/transform.js +11 -15
- package/dist/pdf/style.d.ts +1 -1
- package/dist/pdf/style.js +7 -10
- package/dist/public-methods/generatePDF.d.ts +2 -2
- package/dist/public-methods/generatePDF.js +15 -22
- package/dist/public-methods/getAndValidateConfig.d.ts +1 -1
- package/dist/public-methods/getAndValidateConfig.js +3 -7
- package/dist/public-methods/processSubmission.d.ts +4 -4
- package/dist/public-methods/processSubmission.js +37 -33
- package/dist/public-methods/saveToS3Bucket.d.ts +1 -1
- package/dist/public-methods/saveToS3Bucket.js +6 -13
- package/dist/public-methods/version.js +8 -10
- package/package.json +36 -65
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|

|
|
6
6
|
[](https://packagephobia.com/result?p=@raytio/decrypt-helper)
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Install
|
|
9
9
|
|
|
10
10
|
This SDK is designed to run on nodejs >=18.
|
|
11
11
|
|
|
@@ -84,7 +84,7 @@ To test the PDF generation, run `yarn dev-pdf`
|
|
|
84
84
|
|
|
85
85
|
We use jest for unit tests, snapshot tests of the PDF, and integration tests for whole process. See the [tests](./tests) folder.
|
|
86
86
|
|
|
87
|
-
To run tests, use `yarn test`. To run and update snapshots, use `yarn test -u`. You will need to configure the
|
|
87
|
+
To run tests, use `yarn test`. To run and update snapshots, use `yarn test -u`. You will need to configure the environment 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
90
|
|
package/dist/api/authedFetch.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,9 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
exports.authedFetch = void 0;
|
|
13
|
-
function authedFetch(apiToken, url, options, retrying = false) {
|
|
10
|
+
export function authedFetch(apiToken, url, options, retrying = false) {
|
|
14
11
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
12
|
console.log(`[API] ${retrying ? "Retry" : "Start"} ${url}`);
|
|
16
13
|
const startTime = Date.now();
|
|
@@ -30,4 +27,3 @@ function authedFetch(apiToken, url, options, retrying = false) {
|
|
|
30
27
|
return apiResponse;
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
|
-
exports.authedFetch = authedFetch;
|
package/dist/api/fetchAA.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { EnvConfig } from "./fetchEnvConfig";
|
|
1
|
+
import type { AA, AId } from "@raytio/types";
|
|
2
|
+
import type { EnvConfig } from "./fetchEnvConfig.js";
|
|
3
3
|
export declare function fetchAA(apiToken: string, envConfig: EnvConfig, aId: AId): Promise<AA>;
|
package/dist/api/fetchAA.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,15 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const authedFetch_1 = require("./authedFetch");
|
|
14
|
-
function fetchAA(apiToken, envConfig, aId) {
|
|
10
|
+
import { authedFetch } from "./authedFetch.js";
|
|
11
|
+
export function fetchAA(apiToken, envConfig, aId) {
|
|
15
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const [AA] = yield
|
|
13
|
+
const [AA] = yield authedFetch(apiToken, `${envConfig.api_url}/db/v1/dsm_access_applications?id=eq.${aId}`);
|
|
17
14
|
if (!AA)
|
|
18
15
|
throw new Error("AA not found");
|
|
19
16
|
return Object.assign(Object.assign({}, AA), { a_id: AA.id });
|
|
20
17
|
});
|
|
21
18
|
}
|
|
22
|
-
exports.fetchAA = fetchAA;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,21 +7,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.fetchEnvConfig = void 0;
|
|
13
10
|
const PARAMS = [
|
|
14
11
|
"cognito_region",
|
|
15
12
|
"cognito_user_pool_id",
|
|
16
13
|
"cognito_web_client_id",
|
|
17
14
|
"api_url",
|
|
18
|
-
"app_name",
|
|
15
|
+
"app_name", // whitelabelling name
|
|
19
16
|
"logo_url", // must be a URL to a png file
|
|
20
17
|
];
|
|
21
18
|
const DEFAULTS = {
|
|
22
19
|
app_name: "Raytio",
|
|
23
20
|
logo_url: undefined,
|
|
24
21
|
};
|
|
25
|
-
function fetchEnvConfig(clientUrl) {
|
|
22
|
+
export function fetchEnvConfig(clientUrl) {
|
|
26
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
24
|
try {
|
|
28
25
|
const envConfig = Object.assign(Object.assign({}, DEFAULTS), (yield fetch(`${clientUrl}/client_config.json`).then((r) => r.json())));
|
|
@@ -36,4 +33,3 @@ function fetchEnvConfig(clientUrl) {
|
|
|
36
33
|
}
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
|
-
exports.fetchEnvConfig = fetchEnvConfig;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { IId,
|
|
2
|
-
import { EnvConfig } from "./fetchEnvConfig";
|
|
3
|
-
export declare function fetchInstanceData(apiToken: string, envConfig: EnvConfig, instanceId: IId): Promise<
|
|
1
|
+
import type { IId, InstanceWithoutData } from "@raytio/types";
|
|
2
|
+
import type { EnvConfig } from "./fetchEnvConfig.js";
|
|
3
|
+
export declare function fetchInstanceData(apiToken: string, envConfig: EnvConfig, instanceId: IId): Promise<InstanceWithoutData>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,14 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const core_1 = require("@raytio/core");
|
|
14
|
-
const authedFetch_1 = require("./authedFetch");
|
|
15
|
-
function fetchInstanceData(apiToken, envConfig, instanceId) {
|
|
10
|
+
import { authedFetch } from "./authedFetch.js";
|
|
11
|
+
export function fetchInstanceData(apiToken, envConfig, instanceId) {
|
|
16
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const instance = yield
|
|
13
|
+
const [instance] = yield authedFetch(apiToken, `${envConfig.api_url}/db/v1/dsm_access_application_instances?id=eq.${instanceId}`);
|
|
18
14
|
return instance;
|
|
19
15
|
});
|
|
20
16
|
}
|
|
21
|
-
exports.fetchInstanceData = fetchInstanceData;
|
package/dist/api/getFiles.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Instance, NId, ProfileObject } from "@raytio/types";
|
|
2
|
-
import { ApplicationEncryptorLike } from "../types";
|
|
3
|
-
import { EnvConfig } from "./fetchEnvConfig";
|
|
2
|
+
import type { ApplicationEncryptorLike } from "../types.js";
|
|
3
|
+
import type { EnvConfig } from "./fetchEnvConfig.js";
|
|
4
4
|
type FileObject = Record<NId, [dataUrl: string, fileExtension: string]>;
|
|
5
5
|
export declare function getFiles(profileObjects: ProfileObject[], instance: Instance, apiToken: string, envConfig: EnvConfig, applicationDecryptor: ApplicationEncryptorLike): Promise<FileObject>;
|
|
6
6
|
export {};
|
package/dist/api/getFiles.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,15 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const authedFetch_1 = require("./authedFetch");
|
|
17
|
-
const videoToImage_1 = require("./videoToImage");
|
|
10
|
+
import { getNidFromUrn, isEncrypted } from "@raytio/core";
|
|
11
|
+
import { extension, types } from "mime-types";
|
|
12
|
+
import { isFieldValueFile, isTruthy, isUrn } from "../helpers/file.js";
|
|
13
|
+
import { authedFetch } from "./authedFetch.js";
|
|
14
|
+
import { videoToImage } from "./videoToImage.js";
|
|
18
15
|
const TEMP_OBJ_PREFIX = "urn:temp_object:";
|
|
19
|
-
const getFileExtn = (b64) => { var _a; return
|
|
16
|
+
const getFileExtn = (b64) => { var _a; return extension(((_a = b64.split(":")[1]) === null || _a === void 0 ? void 0 : _a.split(";base64,")[0]) || "text/plain") || "txt"; };
|
|
20
17
|
const decryptFile = (encryptedData, encryptedObject, applicationDecryptor, wdek) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
18
|
const clonedEncryptedObject = JSON.parse(JSON.stringify(encryptedObject));
|
|
22
19
|
clonedEncryptedObject.encrypted_data.data = encryptedData;
|
|
@@ -35,23 +32,60 @@ const cleanApiResponse = (responseBody) => {
|
|
|
35
32
|
}
|
|
36
33
|
return responseBody;
|
|
37
34
|
};
|
|
38
|
-
function
|
|
35
|
+
function tryGetFallbackUrn(urnOrEncrypted) {
|
|
36
|
+
const urn = isEncrypted(urnOrEncrypted)
|
|
37
|
+
? urnOrEncrypted.encrypted_data.data // no nessesaily a Urn
|
|
38
|
+
: urnOrEncrypted;
|
|
39
|
+
return isUrn(urn) ? getNidFromUrn(urn) : undefined;
|
|
40
|
+
}
|
|
41
|
+
export function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecryptor) {
|
|
39
42
|
var _a;
|
|
40
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
// [
|
|
44
|
+
// [nId2: NId2, fieldName: string, file: Urn | Encrypted<Urn>][]
|
|
42
45
|
const urnOrEncryptedList = profileObjects.flatMap((PO) => {
|
|
43
46
|
return Object.entries(PO.properties)
|
|
44
|
-
.filter((kv) => (0, file_1.isFieldValueFile)(kv[1]))
|
|
45
47
|
.map(([k, v]) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
// this value is not a file, so abort
|
|
49
|
+
if (!isFieldValueFile(v))
|
|
50
|
+
return undefined;
|
|
51
|
+
const urnOrEncrypted = "content" in v ? v.content : v.Content;
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* // pre-2021 data structure:
|
|
56
|
+
* [
|
|
57
|
+
* { n_id: 1, properties: { field1: File }
|
|
58
|
+
* ]
|
|
59
|
+
*
|
|
60
|
+
* // post-2021 data structure:
|
|
61
|
+
* [
|
|
62
|
+
* { n_id: 1, properties: { field1: { $ref: 2 } } },
|
|
63
|
+
* { n_id: 2, properties: File }
|
|
64
|
+
* ]
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* In 2023, the API was changed so that properties (in this
|
|
68
|
+
* case field1) so longer include the n_id. For the pre-2021
|
|
69
|
+
* example, this means we have no official way of getting the
|
|
70
|
+
* n_id of the file content.
|
|
71
|
+
*
|
|
72
|
+
* To continue supporting the legacy data, we have an escape
|
|
73
|
+
* hatch: {@link tryGetFallbackUrn} to look at the internal
|
|
74
|
+
* structure of the File object and (try) to get the Urn.
|
|
75
|
+
*
|
|
76
|
+
* This won't work for extremely old files (pre 2020), since
|
|
77
|
+
* we used to store the entire data url in the PO, there were
|
|
78
|
+
* no Urns or refs at that point.
|
|
79
|
+
*/
|
|
80
|
+
const fileNId = v.n_id || tryGetFallbackUrn(urnOrEncrypted);
|
|
81
|
+
// if we couldn't figure out the file content's nId, abort.
|
|
82
|
+
if (!fileNId)
|
|
83
|
+
return undefined;
|
|
84
|
+
return [PO.id, fileNId, k, urnOrEncrypted];
|
|
85
|
+
})
|
|
86
|
+
.filter(isTruthy);
|
|
53
87
|
});
|
|
54
|
-
const filesBase64 = yield Promise.all(urnOrEncryptedList.map(([
|
|
88
|
+
const filesBase64 = yield Promise.all(urnOrEncryptedList.map(([PONId2, fileNId, fieldName, urnOrEncrypted]) => __awaiter(this, void 0, void 0, function* () {
|
|
55
89
|
var _b, _c;
|
|
56
90
|
// handle urn:temp_object:
|
|
57
91
|
if (typeof urnOrEncrypted === "string" &&
|
|
@@ -63,9 +97,9 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
|
|
|
63
97
|
const dataUrl = `data:${type};base64,${base64}`;
|
|
64
98
|
return [fileNId, [dataUrl, getFileExtn(dataUrl)]];
|
|
65
99
|
}
|
|
66
|
-
const realDataUrl = yield
|
|
67
|
-
if (
|
|
68
|
-
const wdek = (_c = (_b = instance.keys[
|
|
100
|
+
const realDataUrl = yield authedFetch(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instance.id}/profile_object/${fileNId}/content`).then(cleanApiResponse);
|
|
101
|
+
if (isEncrypted(urnOrEncrypted)) {
|
|
102
|
+
const wdek = (_c = (_b = instance.keys[PONId2]) === null || _b === void 0 ? void 0 : _b[fieldName]) === null || _c === void 0 ? void 0 : _c.data;
|
|
69
103
|
if (!wdek)
|
|
70
104
|
return [fileNId, undefined];
|
|
71
105
|
const decryptedDataUrl = yield decryptFile(realDataUrl, urnOrEncrypted, applicationDecryptor, wdek);
|
|
@@ -77,9 +111,9 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
|
|
|
77
111
|
// for all videos, also store a static frame from the video, since we can't embedded a video into the PDF
|
|
78
112
|
for (const nId in allDataUrls) {
|
|
79
113
|
const [dataUrl, fileExtn] = allDataUrls[nId];
|
|
80
|
-
const isVideo = (_a =
|
|
114
|
+
const isVideo = (_a = types[fileExtn]) === null || _a === void 0 ? void 0 : _a.startsWith("video/");
|
|
81
115
|
if (isVideo) {
|
|
82
|
-
const imageDataUrl = yield
|
|
116
|
+
const imageDataUrl = yield videoToImage(apiToken, envConfig, dataUrl);
|
|
83
117
|
allDataUrls[`${nId}_videoFrame`] = [
|
|
84
118
|
imageDataUrl,
|
|
85
119
|
getFileExtn(imageDataUrl),
|
|
@@ -89,4 +123,3 @@ function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecr
|
|
|
89
123
|
return allDataUrls;
|
|
90
124
|
});
|
|
91
125
|
}
|
|
92
|
-
exports.getFiles = getFiles;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Lookup } from "@raytio/types";
|
|
1
|
+
import type { Lookup } from "@raytio/types";
|
|
2
2
|
export declare function getLookupOption(apiToken: string, lookup: string): Promise<Lookup[]>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,14 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
exports.getLookupOption = void 0;
|
|
13
|
-
const authedFetch_1 = require("./authedFetch");
|
|
10
|
+
import { authedFetch } from "./authedFetch.js";
|
|
14
11
|
/**
|
|
15
12
|
* We cache the promise so that only one XHR request is ever sent
|
|
16
13
|
*/
|
|
17
14
|
const cache = new Map();
|
|
18
|
-
function getLookupOption(apiToken, lookup) {
|
|
15
|
+
export function getLookupOption(apiToken, lookup) {
|
|
19
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
17
|
const { origin } = new URL(lookup);
|
|
21
18
|
const cached = cache.get(lookup);
|
|
@@ -23,10 +20,9 @@ function getLookupOption(apiToken, lookup) {
|
|
|
23
20
|
return cached;
|
|
24
21
|
// if it's a lookup to our own API, then include the IdentityToken
|
|
25
22
|
const promise = origin.endsWith(".rayt.io")
|
|
26
|
-
?
|
|
23
|
+
? authedFetch(apiToken, lookup)
|
|
27
24
|
: fetch(lookup).then((r) => r.json());
|
|
28
25
|
cache.set(lookup, promise);
|
|
29
26
|
return promise;
|
|
30
27
|
});
|
|
31
28
|
}
|
|
32
|
-
exports.getLookupOption = getLookupOption;
|
package/dist/api/getSchema.d.ts
CHANGED
package/dist/api/getSchema.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,16 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const authedFetch_1 = require("./authedFetch");
|
|
15
|
-
function getAllSchema(envConfig) {
|
|
10
|
+
import { expandSchema } from "@raytio/core";
|
|
11
|
+
import { authedFetch } from "./authedFetch.js";
|
|
12
|
+
export function getAllSchema(envConfig) {
|
|
16
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const list = yield
|
|
18
|
-
return list.map((wrappedSchema) =>
|
|
14
|
+
const list = yield authedFetch("", `${envConfig.api_url}/db/v1/dsm_schema?version_current=eq.true`);
|
|
15
|
+
return list.map((wrappedSchema) => expandSchema(wrappedSchema, list, [
|
|
19
16
|
process.env.PDF_LANGUAGE || process.env.DATE_FORMAT || "en-NZ",
|
|
20
17
|
]));
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
|
-
exports.getAllSchema = getAllSchema;
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from "./authedFetch";
|
|
2
|
-
export * from "./fetchAA";
|
|
3
|
-
export * from "./fetchEnvConfig";
|
|
4
|
-
export * from "./fetchInstanceData";
|
|
5
|
-
export * from "./getFiles";
|
|
6
|
-
export * from "./getSchema";
|
|
7
|
-
export * from "./resolveVerificationDetails";
|
|
8
|
-
export * from "./signIn";
|
|
9
|
-
export * from "./updateInstanceData";
|
|
1
|
+
export * from "./authedFetch.js";
|
|
2
|
+
export * from "./fetchAA.js";
|
|
3
|
+
export * from "./fetchEnvConfig.js";
|
|
4
|
+
export * from "./fetchInstanceData.js";
|
|
5
|
+
export * from "./getFiles.js";
|
|
6
|
+
export * from "./getSchema.js";
|
|
7
|
+
export * from "./resolveVerificationDetails.js";
|
|
8
|
+
export * from "./signIn.js";
|
|
9
|
+
export * from "./updateInstanceData.js";
|
package/dist/api/index.js
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./authedFetch"), exports);
|
|
18
|
-
__exportStar(require("./fetchAA"), exports);
|
|
19
|
-
__exportStar(require("./fetchEnvConfig"), exports);
|
|
20
|
-
__exportStar(require("./fetchInstanceData"), exports);
|
|
21
|
-
__exportStar(require("./getFiles"), exports);
|
|
22
|
-
__exportStar(require("./getSchema"), exports);
|
|
23
|
-
__exportStar(require("./resolveVerificationDetails"), exports);
|
|
24
|
-
__exportStar(require("./signIn"), exports);
|
|
25
|
-
__exportStar(require("./updateInstanceData"), exports);
|
|
1
|
+
export * from "./authedFetch.js";
|
|
2
|
+
export * from "./fetchAA.js";
|
|
3
|
+
export * from "./fetchEnvConfig.js";
|
|
4
|
+
export * from "./fetchInstanceData.js";
|
|
5
|
+
export * from "./getFiles.js";
|
|
6
|
+
export * from "./getSchema.js";
|
|
7
|
+
export * from "./resolveVerificationDetails.js";
|
|
8
|
+
export * from "./signIn.js";
|
|
9
|
+
export * from "./updateInstanceData.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,10 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.clearCache = exports.resolveVerificationDetails = void 0;
|
|
13
10
|
let verifiersPromise;
|
|
14
|
-
function resolveVerificationDetails([details], envConfig) {
|
|
11
|
+
export function resolveVerificationDetails([details], envConfig) {
|
|
15
12
|
var _a, _b, _c, _d;
|
|
16
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
14
|
if (!details)
|
|
@@ -28,9 +25,7 @@ function resolveVerificationDetails([details], envConfig) {
|
|
|
28
25
|
};
|
|
29
26
|
});
|
|
30
27
|
}
|
|
31
|
-
exports.resolveVerificationDetails = resolveVerificationDetails;
|
|
32
28
|
/** @deprecated - for use in unit tests only */
|
|
33
|
-
const clearCache = () => {
|
|
29
|
+
export const clearCache = () => {
|
|
34
30
|
verifiersPromise = null;
|
|
35
31
|
};
|
|
36
|
-
exports.clearCache = clearCache;
|
package/dist/api/signIn.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ICognitoUserAttributeData } from "amazon-cognito-identity-js";
|
|
2
|
-
import { Config } from "../constants";
|
|
3
|
-
import { EnvConfig } from "./fetchEnvConfig";
|
|
2
|
+
import type { Config } from "../constants.js";
|
|
3
|
+
import type { EnvConfig } from "./fetchEnvConfig.js";
|
|
4
4
|
export declare function signIn(CONFIG: Config, envConfig: EnvConfig): Promise<{
|
|
5
5
|
apiToken: string;
|
|
6
6
|
cognitoAttributes: ICognitoUserAttributeData[];
|
package/dist/api/signIn.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,37 +7,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const auth_1 = require("@aws-amplify/auth");
|
|
14
|
-
const core_1 = require("@raytio/core");
|
|
10
|
+
import { Auth } from "@aws-amplify/auth";
|
|
11
|
+
import { hashPassword } from "@raytio/core";
|
|
15
12
|
/** see #1252 in the client repo */
|
|
16
13
|
function signInWithPasswordMigration(username, password) {
|
|
17
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
15
|
try {
|
|
19
|
-
const userObject = yield
|
|
16
|
+
const userObject = yield Auth.signIn(username, password);
|
|
20
17
|
return userObject;
|
|
21
18
|
}
|
|
22
19
|
catch (_a) {
|
|
23
20
|
// if the login fails, try again with their hashed password.
|
|
24
21
|
// if it's successful the second time, we quietly change their password.
|
|
25
|
-
const hashedPassword = yield
|
|
26
|
-
const userObject = yield
|
|
22
|
+
const hashedPassword = yield hashPassword(password);
|
|
23
|
+
const userObject = yield Auth.signIn(username, hashedPassword);
|
|
27
24
|
// the login was successful. So we need to migrate their account.
|
|
28
25
|
// No changes to the maxcryptor, purely to cognito.
|
|
29
26
|
// we can only migrate their password if there are no login challenges
|
|
30
27
|
if (!userObject.challengeName) {
|
|
31
28
|
console.log("Migrating credentials...");
|
|
32
|
-
yield
|
|
29
|
+
yield Auth.changePassword(userObject, hashedPassword, password);
|
|
33
30
|
}
|
|
34
31
|
return userObject;
|
|
35
32
|
}
|
|
36
33
|
});
|
|
37
34
|
}
|
|
38
|
-
function signIn(CONFIG, envConfig) {
|
|
35
|
+
export function signIn(CONFIG, envConfig) {
|
|
39
36
|
var _a, _b;
|
|
40
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
|
|
38
|
+
Auth.configure({
|
|
42
39
|
region: envConfig.cognito_region,
|
|
43
40
|
userPoolId: envConfig.cognito_user_pool_id,
|
|
44
41
|
userPoolWebClientId: envConfig.cognito_web_client_id,
|
|
@@ -47,10 +44,9 @@ function signIn(CONFIG, envConfig) {
|
|
|
47
44
|
if (userObject.challengeName === "SOFTWARE_TOKEN_MFA") {
|
|
48
45
|
throw new Error(`The configured account (${CONFIG.RAYTIO_USERNAME}) has two factor authentication enabled. You must disable 2FA or use a different account`);
|
|
49
46
|
}
|
|
50
|
-
const user = yield
|
|
47
|
+
const user = yield Auth.currentAuthenticatedUser();
|
|
51
48
|
const apiToken = (_b = (_a = user.signInUserSession) === null || _a === void 0 ? void 0 : _a.accessToken) === null || _b === void 0 ? void 0 : _b.jwtToken;
|
|
52
|
-
const cognitoAttributes = yield
|
|
49
|
+
const cognitoAttributes = yield Auth.userAttributes(user);
|
|
53
50
|
return { apiToken, cognitoAttributes };
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
|
-
exports.signIn = signIn;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { IId, InstanceWithoutData } from "@raytio/types";
|
|
2
|
+
import type { EnvConfig } from "./fetchEnvConfig.js";
|
|
3
|
+
/**
|
|
4
|
+
* only specific fields can be updated, passing the entire
|
|
5
|
+
* instance object to the v3 API will cause an error.
|
|
6
|
+
*/
|
|
7
|
+
export declare function updateInstanceData(apiToken: string, envConfig: EnvConfig, iId: IId, instance: Partial<Pick<InstanceWithoutData, "state" | "score" | "metadata">>): Promise<void>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,12 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
import { authedFetch } from "./authedFetch.js";
|
|
11
|
+
/**
|
|
12
|
+
* only specific fields can be updated, passing the entire
|
|
13
|
+
* instance object to the v3 API will cause an error.
|
|
14
|
+
*/
|
|
15
|
+
export function updateInstanceData(apiToken, envConfig, iId, instance) {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
yield
|
|
17
|
+
yield authedFetch(apiToken, `${envConfig.api_url}/db/v1/dsm_access_application_instances_u?id=eq.${iId}`, { method: "PATCH", body: JSON.stringify(instance) });
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
|
-
exports.updateInstanceData = updateInstanceData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvConfig } from "./fetchEnvConfig";
|
|
1
|
+
import type { EnvConfig } from "./fetchEnvConfig.js";
|
|
2
2
|
export declare function uploadToObjectStore(apiToken: string, envConfig: EnvConfig, dataUrl: string, expiryDate?: Date): Promise<{
|
|
3
3
|
objectStoreId: string;
|
|
4
4
|
retrievalUrl: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,21 +7,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
exports.uploadToObjectStore = void 0;
|
|
13
|
-
const authedFetch_1 = require("./authedFetch");
|
|
10
|
+
import { authedFetch } from "./authedFetch.js";
|
|
14
11
|
//
|
|
15
12
|
// this file is mostly copy-pasted from the client repo. If you make
|
|
16
13
|
// a change here, consider making the same change in the client.
|
|
17
14
|
//
|
|
18
|
-
function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate) {
|
|
15
|
+
export function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate) {
|
|
19
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
17
|
const mimeType = dataUrl.split(";")[0].split(":")[1];
|
|
21
18
|
const base64 = dataUrl.split(",")[1];
|
|
22
19
|
// eslint-disable-next-line unicorn/prefer-code-point -- deliberate, this will only ever be ASCII
|
|
23
20
|
const arrayBuffer = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
24
21
|
// this is a weird API that returns a double stringified string
|
|
25
|
-
const temporaryUrl = yield
|
|
22
|
+
const temporaryUrl = yield authedFetch(apiToken, `${envConfig.api_url}/org/v1/object/url${expiryDate ? `?expires=${+expiryDate}` : ""}`);
|
|
26
23
|
const { status, statusText } = yield fetch(temporaryUrl, {
|
|
27
24
|
method: "PUT",
|
|
28
25
|
body: arrayBuffer,
|
|
@@ -39,4 +36,3 @@ function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate) {
|
|
|
39
36
|
};
|
|
40
37
|
});
|
|
41
38
|
}
|
|
42
|
-
exports.uploadToObjectStore = uploadToObjectStore;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { EnvConfig } from "./fetchEnvConfig";
|
|
1
|
+
import type { EnvConfig } from "./fetchEnvConfig.js";
|
|
2
2
|
/** Use the extractor API to get the middle frame from a video */
|
|
3
3
|
export declare function videoToImage(apiToken: string, envConfig: EnvConfig, videoDataUrl: string): Promise<string>;
|