@raytio/decrypt-helper 6.1.0 → 6.1.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/dist/api/authedFetch.d.ts +1 -0
- package/dist/api/authedFetch.js +33 -0
- package/dist/api/fetchAA.d.ts +3 -0
- package/dist/api/fetchAA.js +19 -0
- package/dist/api/fetchEnvConfig.d.ts +6 -0
- package/dist/api/fetchEnvConfig.js +39 -0
- package/dist/api/fetchInstanceData.d.ts +3 -0
- package/dist/api/fetchInstanceData.js +21 -0
- package/dist/api/getFiles.d.ts +6 -0
- package/dist/api/getFiles.js +92 -0
- package/dist/api/getLookupOption.d.ts +2 -0
- package/dist/api/getLookupOption.js +32 -0
- package/dist/api/getSchema.d.ts +3 -0
- package/dist/api/getSchema.js +23 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.js +25 -0
- package/dist/api/resolveVerificationDetails.d.ts +11 -0
- package/dist/api/resolveVerificationDetails.js +36 -0
- package/dist/api/signIn.d.ts +7 -0
- package/dist/api/signIn.js +56 -0
- package/dist/api/updateInstanceData.d.ts +2 -0
- package/dist/api/updateInstanceData.js +19 -0
- package/dist/api/uploadToObjectStore.d.ts +5 -0
- package/dist/api/uploadToObjectStore.js +42 -0
- package/dist/api/videoToImage.d.ts +3 -0
- package/dist/api/videoToImage.js +30 -0
- package/dist/configureEnv.d.ts +1 -0
- package/dist/configureEnv.js +30 -0
- package/dist/constants.d.ts +23 -0
- package/dist/constants.js +45 -0
- package/dist/helpers/file.d.ts +13 -0
- package/dist/helpers/file.js +17 -0
- package/dist/helpers/formatOutput.d.ts +28 -0
- package/dist/helpers/formatOutput.js +93 -0
- package/dist/helpers/index.d.ts +6 -0
- package/dist/helpers/index.js +22 -0
- package/dist/helpers/json2csv.d.ts +2 -0
- package/dist/helpers/json2csv.js +24 -0
- package/dist/helpers/lookup.d.ts +2 -0
- package/dist/helpers/lookup.js +22 -0
- package/dist/helpers/setupMaxcryptor.d.ts +4 -0
- package/dist/helpers/setupMaxcryptor.js +28 -0
- package/dist/helpers/splitPOAndVers.d.ts +2 -0
- package/dist/helpers/splitPOAndVers.js +12 -0
- package/dist/helpers/types.d.ts +1 -0
- package/dist/helpers/types.js +9 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -0
- package/dist/locales/index.d.ts +44 -0
- package/dist/locales/index.js +22 -0
- package/dist/locales/translations/en.json +33 -0
- package/dist/pdf/components/FieldVerificationBadge.d.ts +6 -0
- package/dist/pdf/components/FieldVerificationBadge.js +19 -0
- package/dist/pdf/components/Images.d.ts +6 -0
- package/dist/pdf/components/Images.js +20 -0
- package/dist/pdf/components/InnerTableRows.d.ts +11 -0
- package/dist/pdf/components/InnerTableRows.js +37 -0
- package/dist/pdf/components/POVerificationBadge.d.ts +8 -0
- package/dist/pdf/components/POVerificationBadge.js +41 -0
- package/dist/pdf/components/Report.d.ts +13 -0
- package/dist/pdf/components/Report.js +98 -0
- package/dist/pdf/components/Subheader.d.ts +2 -0
- package/dist/pdf/components/Subheader.js +28 -0
- package/dist/pdf/components/Table.d.ts +9 -0
- package/dist/pdf/components/Table.js +47 -0
- package/dist/pdf/components/TableTitle.d.ts +5 -0
- package/dist/pdf/components/TableTitle.js +17 -0
- package/dist/pdf/components/ValidationDisplay.d.ts +5 -0
- package/dist/pdf/components/ValidationDisplay.js +29 -0
- package/dist/pdf/components/VerifyBox.d.ts +9 -0
- package/dist/pdf/components/VerifyBox.js +19 -0
- package/dist/pdf/components/pieChart.d.ts +6 -0
- package/dist/pdf/components/pieChart.js +27 -0
- package/dist/pdf/constants.d.ts +3 -0
- package/dist/pdf/constants.js +12 -0
- package/dist/pdf/helpers/general.d.ts +8 -0
- package/dist/pdf/helpers/general.js +37 -0
- package/dist/pdf/helpers/transform.d.ts +4 -0
- package/dist/pdf/helpers/transform.js +39 -0
- package/dist/pdf/style.d.ts +10 -0
- package/dist/pdf/style.js +24 -0
- package/dist/public-methods/generatePDF.d.ts +4 -0
- package/dist/public-methods/generatePDF.js +60 -0
- package/dist/public-methods/getAndValidateConfig.d.ts +8 -0
- package/dist/public-methods/getAndValidateConfig.js +20 -0
- package/dist/public-methods/processSubmission.d.ts +49 -0
- package/dist/public-methods/processSubmission.js +128 -0
- package/dist/public-methods/saveToS3Bucket.d.ts +2 -0
- package/dist/public-methods/saveToS3Bucket.js +60 -0
- package/dist/public-methods/version.d.ts +2 -0
- package/dist/public-methods/version.js +15 -0
- package/package.json +7 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function authedFetch<T>(apiToken: string, url: string, options?: RequestInit, retrying?: boolean): Promise<T>;
|
|
@@ -0,0 +1,33 @@
|
|
|
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.authedFetch = void 0;
|
|
13
|
+
function authedFetch(apiToken, url, options, retrying = false) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
console.log(`[API] ${retrying ? "Retry" : "Start"} ${url}`);
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
const response = yield fetch(url, Object.assign(Object.assign({}, options), { headers: { Authorization: `Bearer ${apiToken}` } }));
|
|
18
|
+
const apiResponse = yield response.json();
|
|
19
|
+
const error = apiResponse.message || apiResponse.error;
|
|
20
|
+
if (error) {
|
|
21
|
+
if (!retrying && response.status === 504) {
|
|
22
|
+
console.log(`[API] Error ${response.status} (will retry) ${url}`);
|
|
23
|
+
return authedFetch(apiToken, url, options, true);
|
|
24
|
+
}
|
|
25
|
+
console.log(`[API] Error ${response.status} (no retry) ${url}`);
|
|
26
|
+
throw new Error(`Failed due to API Error from ${url}: "${error}"`);
|
|
27
|
+
}
|
|
28
|
+
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
29
|
+
console.log(`[API] Finish${retrying ? " after retry" : ""} (${totalTime}s) ${url}`);
|
|
30
|
+
return apiResponse;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.authedFetch = authedFetch;
|
|
@@ -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.fetchAA = void 0;
|
|
13
|
+
const authedFetch_1 = require("./authedFetch");
|
|
14
|
+
function fetchAA(apiToken, envConfig, aId) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/${aId}`);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.fetchAA = fetchAA;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const PARAMS: readonly ["cognito_region", "cognito_user_pool_id", "cognito_web_client_id", "api_url", "app_name", "logo_url"];
|
|
2
|
+
export type EnvConfig = Record<(typeof PARAMS)[number], string> & {
|
|
3
|
+
clientUrl: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function fetchEnvConfig(clientUrl: string): Promise<EnvConfig>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
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.fetchEnvConfig = void 0;
|
|
13
|
+
const PARAMS = [
|
|
14
|
+
"cognito_region",
|
|
15
|
+
"cognito_user_pool_id",
|
|
16
|
+
"cognito_web_client_id",
|
|
17
|
+
"api_url",
|
|
18
|
+
"app_name",
|
|
19
|
+
"logo_url", // must be a URL to a png file
|
|
20
|
+
];
|
|
21
|
+
const DEFAULTS = {
|
|
22
|
+
app_name: "Raytio",
|
|
23
|
+
logo_url: undefined,
|
|
24
|
+
};
|
|
25
|
+
function fetchEnvConfig(clientUrl) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
const envConfig = Object.assign(Object.assign({}, DEFAULTS), (yield fetch(`${clientUrl}/client_config.json`).then((r) => r.json())));
|
|
29
|
+
const missing = PARAMS.filter((p) => !(p in envConfig));
|
|
30
|
+
if (missing.length)
|
|
31
|
+
throw new Error(`Missing: ${missing.join(", ")}`);
|
|
32
|
+
return Object.assign(Object.assign({}, envConfig), { clientUrl });
|
|
33
|
+
}
|
|
34
|
+
catch (ex) {
|
|
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})`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.fetchEnvConfig = fetchEnvConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
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.fetchInstanceData = void 0;
|
|
13
|
+
const core_1 = require("@raytio/core");
|
|
14
|
+
const authedFetch_1 = require("./authedFetch");
|
|
15
|
+
function fetchInstanceData(apiToken, envConfig, instanceId) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const instance = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instanceId}`).then(core_1.cleanInstance);
|
|
18
|
+
return instance;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.fetchInstanceData = fetchInstanceData;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Instance, NId, ProfileObject } from "@raytio/types";
|
|
2
|
+
import { ApplicationEncryptorLike } from "../types";
|
|
3
|
+
import { EnvConfig } from "./fetchEnvConfig";
|
|
4
|
+
type FileObject = Record<NId, [dataUrl: string, fileExtension: string]>;
|
|
5
|
+
export declare function getFiles(profileObjects: ProfileObject[], instance: Instance, apiToken: string, envConfig: EnvConfig, applicationDecryptor: ApplicationEncryptorLike): Promise<FileObject>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
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.getFiles = void 0;
|
|
13
|
+
const core_1 = require("@raytio/core");
|
|
14
|
+
const mime_types_1 = require("mime-types");
|
|
15
|
+
const file_1 = require("../helpers/file");
|
|
16
|
+
const authedFetch_1 = require("./authedFetch");
|
|
17
|
+
const videoToImage_1 = require("./videoToImage");
|
|
18
|
+
const TEMP_OBJ_PREFIX = "urn:temp_object:";
|
|
19
|
+
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"; };
|
|
20
|
+
const decryptFile = (encryptedData, encryptedObject, applicationDecryptor, wdek) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const clonedEncryptedObject = JSON.parse(JSON.stringify(encryptedObject));
|
|
22
|
+
clonedEncryptedObject.encrypted_data.data = encryptedData;
|
|
23
|
+
const decrypted = yield applicationDecryptor.decrypt(clonedEncryptedObject, wdek);
|
|
24
|
+
return decrypted;
|
|
25
|
+
});
|
|
26
|
+
const cleanApiResponse = (responseBody) => {
|
|
27
|
+
try {
|
|
28
|
+
const realB64 = Buffer.from(responseBody, "base64").toString("binary");
|
|
29
|
+
if (realB64.slice(0, 5) === "data:") {
|
|
30
|
+
return realB64;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
// for some reason we need to do this...
|
|
35
|
+
}
|
|
36
|
+
return responseBody;
|
|
37
|
+
};
|
|
38
|
+
function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecryptor) {
|
|
39
|
+
var _a;
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
// [nId: NId, fieldName: string, file: RaytFile][]
|
|
42
|
+
const urnOrEncryptedList = profileObjects.flatMap((PO) => {
|
|
43
|
+
return Object.entries(PO.properties)
|
|
44
|
+
.filter((kv) => (0, file_1.isFieldValueFile)(kv[1]))
|
|
45
|
+
.map(([k, v]) => {
|
|
46
|
+
return [
|
|
47
|
+
PO.n_id,
|
|
48
|
+
v.n_id,
|
|
49
|
+
k,
|
|
50
|
+
"content" in v ? v.content : v.Content,
|
|
51
|
+
];
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
const filesBase64 = yield Promise.all(urnOrEncryptedList.map(([PONId, fileNId, fieldName, urnOrEncrypted]) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _b, _c;
|
|
56
|
+
// handle urn:temp_object:
|
|
57
|
+
if (typeof urnOrEncrypted === "string" &&
|
|
58
|
+
urnOrEncrypted.startsWith(TEMP_OBJ_PREFIX)) {
|
|
59
|
+
const url = Buffer.from(urnOrEncrypted.slice(TEMP_OBJ_PREFIX.length), "base64").toString("binary");
|
|
60
|
+
const response = yield fetch(url);
|
|
61
|
+
const base64 = Buffer.from(yield response.arrayBuffer()).toString("base64");
|
|
62
|
+
const type = response.headers.get("content-type") || "text/plain";
|
|
63
|
+
const dataUrl = `data:${type};base64,${base64}`;
|
|
64
|
+
return [fileNId, [dataUrl, getFileExtn(dataUrl)]];
|
|
65
|
+
}
|
|
66
|
+
const realDataUrl = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instance.i_id}/profile_object/${fileNId}/content`).then(cleanApiResponse);
|
|
67
|
+
if ((0, core_1.isEncrypted)(urnOrEncrypted)) {
|
|
68
|
+
const wdek = (_c = (_b = instance.keys[PONId]) === null || _b === void 0 ? void 0 : _b[fieldName]) === null || _c === void 0 ? void 0 : _c.data;
|
|
69
|
+
if (!wdek)
|
|
70
|
+
return [fileNId, undefined];
|
|
71
|
+
const decryptedDataUrl = yield decryptFile(realDataUrl, urnOrEncrypted, applicationDecryptor, wdek);
|
|
72
|
+
return [fileNId, [decryptedDataUrl, getFileExtn(decryptedDataUrl)]];
|
|
73
|
+
}
|
|
74
|
+
return [fileNId, [realDataUrl, getFileExtn(realDataUrl)]];
|
|
75
|
+
})));
|
|
76
|
+
const allDataUrls = Object.fromEntries(filesBase64.filter((file) => { var _a; return !!file[1] && ((_a = file[1][0]) === null || _a === void 0 ? void 0 : _a.includes(",")); }));
|
|
77
|
+
// for all videos, also store a static frame from the video, since we can't embedded a video into the PDF
|
|
78
|
+
for (const nId in allDataUrls) {
|
|
79
|
+
const [dataUrl, fileExtn] = allDataUrls[nId];
|
|
80
|
+
const isVideo = (_a = mime_types_1.types[fileExtn]) === null || _a === void 0 ? void 0 : _a.startsWith("video/");
|
|
81
|
+
if (isVideo) {
|
|
82
|
+
const imageDataUrl = yield (0, videoToImage_1.videoToImage)(apiToken, envConfig, dataUrl);
|
|
83
|
+
allDataUrls[`${nId}_videoFrame`] = [
|
|
84
|
+
imageDataUrl,
|
|
85
|
+
getFileExtn(imageDataUrl),
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return allDataUrls;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
exports.getFiles = getFiles;
|
|
@@ -0,0 +1,32 @@
|
|
|
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.getLookupOption = void 0;
|
|
13
|
+
const authedFetch_1 = require("./authedFetch");
|
|
14
|
+
/**
|
|
15
|
+
* We cache the promise so that only one XHR request is ever sent
|
|
16
|
+
*/
|
|
17
|
+
const cache = new Map();
|
|
18
|
+
function getLookupOption(apiToken, lookup) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const { origin } = new URL(lookup);
|
|
21
|
+
const cached = cache.get(lookup);
|
|
22
|
+
if (cached)
|
|
23
|
+
return cached;
|
|
24
|
+
// if it's a lookup to our own API, then include the IdentityToken
|
|
25
|
+
const promise = origin.endsWith(".rayt.io")
|
|
26
|
+
? (0, authedFetch_1.authedFetch)(apiToken, lookup)
|
|
27
|
+
: fetch(lookup).then((r) => r.json());
|
|
28
|
+
cache.set(lookup, promise);
|
|
29
|
+
return promise;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.getLookupOption = getLookupOption;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.getAllSchema = void 0;
|
|
13
|
+
const core_1 = require("@raytio/core");
|
|
14
|
+
const authedFetch_1 = require("./authedFetch");
|
|
15
|
+
function getAllSchema(envConfig) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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
|
+
]));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.getAllSchema = getAllSchema;
|
|
@@ -0,0 +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";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
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 __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);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VerificationProvider } from "@raytio/types";
|
|
2
|
+
import { EnvConfig } from "./fetchEnvConfig";
|
|
3
|
+
export type ResolvedVerificationProvider = {
|
|
4
|
+
verifier_id?: string;
|
|
5
|
+
verifier_service_id?: string;
|
|
6
|
+
verifier_source_id?: string;
|
|
7
|
+
date?: string;
|
|
8
|
+
};
|
|
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;
|
|
@@ -0,0 +1,36 @@
|
|
|
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.clearCache = exports.resolveVerificationDetails = void 0;
|
|
13
|
+
let verifiersPromise;
|
|
14
|
+
function resolveVerificationDetails([details], envConfig) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (!details)
|
|
18
|
+
return undefined;
|
|
19
|
+
verifiersPromise || (verifiersPromise = fetch(`${envConfig.clientUrl}/verifiers.json`)
|
|
20
|
+
.then((r) => r.json())
|
|
21
|
+
.catch(() => ({ verifiers: {} })));
|
|
22
|
+
const { verifiers } = yield verifiersPromise;
|
|
23
|
+
return {
|
|
24
|
+
verifier_id: (_a = verifiers[details.verifierNId]) === null || _a === void 0 ? void 0 : _a.name,
|
|
25
|
+
verifier_service_id: (_b = verifiers[details.serviceProviderNId]) === null || _b === void 0 ? void 0 : _b.name,
|
|
26
|
+
verifier_source_id: (_c = verifiers[details.dataSourceNId]) === null || _c === void 0 ? void 0 : _c.name,
|
|
27
|
+
date: (_d = details.date) === null || _d === void 0 ? void 0 : _d.toISOString(),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.resolveVerificationDetails = resolveVerificationDetails;
|
|
32
|
+
/** @deprecated - for use in unit tests only */
|
|
33
|
+
const clearCache = () => {
|
|
34
|
+
verifiersPromise = null;
|
|
35
|
+
};
|
|
36
|
+
exports.clearCache = clearCache;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ICognitoUserAttributeData } from "amazon-cognito-identity-js";
|
|
2
|
+
import { Config } from "../constants";
|
|
3
|
+
import { EnvConfig } from "./fetchEnvConfig";
|
|
4
|
+
export declare function signIn(CONFIG: Config, envConfig: EnvConfig): Promise<{
|
|
5
|
+
apiToken: string;
|
|
6
|
+
cognitoAttributes: ICognitoUserAttributeData[];
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
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.signIn = void 0;
|
|
13
|
+
const auth_1 = require("@aws-amplify/auth");
|
|
14
|
+
const core_1 = require("@raytio/core");
|
|
15
|
+
/** see #1252 in the client repo */
|
|
16
|
+
function signInWithPasswordMigration(username, password) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
const userObject = yield auth_1.Auth.signIn(username, password);
|
|
20
|
+
return userObject;
|
|
21
|
+
}
|
|
22
|
+
catch (_a) {
|
|
23
|
+
// if the login fails, try again with their hashed password.
|
|
24
|
+
// if it's successful the second time, we quietly change their password.
|
|
25
|
+
const hashedPassword = yield (0, core_1.hashPassword)(password);
|
|
26
|
+
const userObject = yield auth_1.Auth.signIn(username, hashedPassword);
|
|
27
|
+
// the login was successful. So we need to migrate their account.
|
|
28
|
+
// No changes to the maxcryptor, purely to cognito.
|
|
29
|
+
// we can only migrate their password if there are no login challenges
|
|
30
|
+
if (!userObject.challengeName) {
|
|
31
|
+
console.log("Migrating credentials...");
|
|
32
|
+
yield auth_1.Auth.changePassword(userObject, hashedPassword, password);
|
|
33
|
+
}
|
|
34
|
+
return userObject;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function signIn(CONFIG, envConfig) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
auth_1.Auth.configure({
|
|
42
|
+
region: envConfig.cognito_region,
|
|
43
|
+
userPoolId: envConfig.cognito_user_pool_id,
|
|
44
|
+
userPoolWebClientId: envConfig.cognito_web_client_id,
|
|
45
|
+
});
|
|
46
|
+
const userObject = yield signInWithPasswordMigration(CONFIG.RAYTIO_USERNAME, CONFIG.RAYTIO_PASSWORD);
|
|
47
|
+
if (userObject.challengeName === "SOFTWARE_TOKEN_MFA") {
|
|
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
|
+
}
|
|
50
|
+
const user = yield auth_1.Auth.currentAuthenticatedUser();
|
|
51
|
+
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 auth_1.Auth.userAttributes(user);
|
|
53
|
+
return { apiToken, cognitoAttributes };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.signIn = signIn;
|
|
@@ -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;
|
|
@@ -0,0 +1,42 @@
|
|
|
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.uploadToObjectStore = void 0;
|
|
13
|
+
const authedFetch_1 = require("./authedFetch");
|
|
14
|
+
//
|
|
15
|
+
// this file is mostly copy-pasted from the client repo. If you make
|
|
16
|
+
// a change here, consider making the same change in the client.
|
|
17
|
+
//
|
|
18
|
+
function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const mimeType = dataUrl.split(";")[0].split(":")[1];
|
|
21
|
+
const base64 = dataUrl.split(",")[1];
|
|
22
|
+
// eslint-disable-next-line unicorn/prefer-code-point -- deliberate, this will only ever be ASCII
|
|
23
|
+
const arrayBuffer = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
24
|
+
// this is a weird API that returns a double stringified string
|
|
25
|
+
const temporaryUrl = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/org/v1/object/url${expiryDate ? `?expires=${+expiryDate}` : ""}`);
|
|
26
|
+
const { status, statusText } = yield fetch(temporaryUrl, {
|
|
27
|
+
method: "PUT",
|
|
28
|
+
body: arrayBuffer,
|
|
29
|
+
headers: { "Content-Type": mimeType },
|
|
30
|
+
});
|
|
31
|
+
if (status !== 200) {
|
|
32
|
+
throw new Error(`Status ${status} from object store: ${statusText}`);
|
|
33
|
+
}
|
|
34
|
+
// the v4 API doesn't return the ID
|
|
35
|
+
const { pathname, origin } = new URL(temporaryUrl);
|
|
36
|
+
return {
|
|
37
|
+
objectStoreId: pathname.slice(1),
|
|
38
|
+
retrievalUrl: origin + pathname,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.uploadToObjectStore = uploadToObjectStore;
|
|
@@ -0,0 +1,30 @@
|
|
|
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.videoToImage = void 0;
|
|
13
|
+
const authedFetch_1 = require("./authedFetch");
|
|
14
|
+
const uploadToObjectStore_1 = require("./uploadToObjectStore");
|
|
15
|
+
/** Use the extractor API to get the middle frame from a video */
|
|
16
|
+
function videoToImage(apiToken, envConfig, videoDataUrl) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// the new API can't handle big dataUrls, so we need to store the data in
|
|
19
|
+
// the object store first...
|
|
20
|
+
const in10Mins = new Date();
|
|
21
|
+
in10Mins.setMinutes(in10Mins.getMinutes() + 10);
|
|
22
|
+
const { retrievalUrl: videoUrl } = yield (0, uploadToObjectStore_1.uploadToObjectStore)(apiToken, envConfig, videoDataUrl, in10Mins);
|
|
23
|
+
const extractedImageBase64 = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/face-detect/v1/image-extract-single`,
|
|
24
|
+
// note: inspite of being called "video_urn", the new API actually expects a url, not a urn...
|
|
25
|
+
{ method: "POST", body: JSON.stringify({ video_urn: videoUrl }) });
|
|
26
|
+
// annoyingly the new API doesn't return the data URL prefix, so we have to hardcode it here
|
|
27
|
+
return `data:image/jpeg;base64,${extractedImageBase64}`;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.videoToImage = videoToImage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "localstorage-polyfill";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const crypto = __importStar(require("node:crypto"));
|
|
27
|
+
// for @aws-amplify/auth
|
|
28
|
+
require("localstorage-polyfill");
|
|
29
|
+
// @ts-expect-error it's not a perfect polyfill..
|
|
30
|
+
globalThis.crypto = crypto; // only required because jest-env-node hides globalThis.crypto
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ScoreResult } from "@raytio/core";
|
|
2
|
+
import { FieldVerification, Instance, POVerification } from "@raytio/types";
|
|
3
|
+
export declare const ATTRIBUTE_MAP: {
|
|
4
|
+
"custom:kek_derivation": string[];
|
|
5
|
+
"custom:dek_encryption": string[];
|
|
6
|
+
"custom:aek_public": string[];
|
|
7
|
+
"custom:aek_private": string[];
|
|
8
|
+
"custom:ask_public": string[];
|
|
9
|
+
"custom:ask_private": string[];
|
|
10
|
+
};
|
|
11
|
+
export declare const INSTANCE_FIELDS_TO_REMOVE: readonly ["profile_objects", "relationships", "keys", "score"];
|
|
12
|
+
export declare const FIELDS_TO_REMOVE: readonly ["n_id", "document"];
|
|
13
|
+
export declare const ENV_VARIABLES: readonly ["CLIENT_URL", "RAYTIO_USERNAME", "RAYTIO_PASSWORD"];
|
|
14
|
+
export type Config = Record<(typeof ENV_VARIABLES)[number], string>;
|
|
15
|
+
export type InstanceDataToPassOn = Omit<Instance, (typeof INSTANCE_FIELDS_TO_REMOVE)[number]> & {
|
|
16
|
+
score?: ScoreResult;
|
|
17
|
+
};
|
|
18
|
+
export declare const PO_VER_TEXT_MAP: Record<POVerification, string>;
|
|
19
|
+
export declare const FIELD_VER_TEXT_MAP: Record<FieldVerification, string>;
|
|
20
|
+
export declare const SCHEMA: {
|
|
21
|
+
readonly VERIFICATION: "ss_Verification";
|
|
22
|
+
readonly PERSON: "ss_Person_Name";
|
|
23
|
+
};
|