@raytio/decrypt-helper 6.4.0 → 6.4.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.
Files changed (96) hide show
  1. package/package.json +1 -1
  2. package/dist/api/authedFetch.d.ts +0 -1
  3. package/dist/api/authedFetch.js +0 -35
  4. package/dist/api/fetchAA.d.ts +0 -3
  5. package/dist/api/fetchAA.js +0 -18
  6. package/dist/api/fetchEnvConfig.d.ts +0 -6
  7. package/dist/api/fetchEnvConfig.js +0 -35
  8. package/dist/api/fetchInstanceData.d.ts +0 -3
  9. package/dist/api/fetchInstanceData.js +0 -16
  10. package/dist/api/getFiles.d.ts +0 -6
  11. package/dist/api/getFiles.js +0 -125
  12. package/dist/api/getLookupOption.d.ts +0 -2
  13. package/dist/api/getLookupOption.js +0 -28
  14. package/dist/api/getSchema.d.ts +0 -3
  15. package/dist/api/getSchema.js +0 -19
  16. package/dist/api/index.d.ts +0 -9
  17. package/dist/api/index.js +0 -9
  18. package/dist/api/resolveVerificationDetails.d.ts +0 -11
  19. package/dist/api/resolveVerificationDetails.js +0 -31
  20. package/dist/api/signIn.d.ts +0 -7
  21. package/dist/api/signIn.js +0 -52
  22. package/dist/api/updateInstanceData.d.ts +0 -7
  23. package/dist/api/updateInstanceData.js +0 -23
  24. package/dist/api/uploadToObjectStore.d.ts +0 -5
  25. package/dist/api/uploadToObjectStore.js +0 -40
  26. package/dist/api/videoToImage.d.ts +0 -3
  27. package/dist/api/videoToImage.js +0 -26
  28. package/dist/configureEnv.d.ts +0 -1
  29. package/dist/configureEnv.js +0 -19
  30. package/dist/constants.d.ts +0 -23
  31. package/dist/constants.js +0 -42
  32. package/dist/helpers/file.d.ts +0 -17
  33. package/dist/helpers/file.js +0 -16
  34. package/dist/helpers/formatOutput.d.ts +0 -28
  35. package/dist/helpers/formatOutput.js +0 -100
  36. package/dist/helpers/index.d.ts +0 -6
  37. package/dist/helpers/index.js +0 -6
  38. package/dist/helpers/json2csv.d.ts +0 -2
  39. package/dist/helpers/json2csv.js +0 -20
  40. package/dist/helpers/jsxPdf.d.ts +0 -6
  41. package/dist/helpers/jsxPdf.js +0 -3
  42. package/dist/helpers/lookup.d.ts +0 -2
  43. package/dist/helpers/lookup.js +0 -31
  44. package/dist/helpers/pathUtils.d.ts +0 -1
  45. package/dist/helpers/pathUtils.js +0 -6
  46. package/dist/helpers/setupMaxcryptor.d.ts +0 -4
  47. package/dist/helpers/setupMaxcryptor.js +0 -25
  48. package/dist/helpers/splitPOAndVers.d.ts +0 -2
  49. package/dist/helpers/splitPOAndVers.js +0 -8
  50. package/dist/helpers/types.d.ts +0 -1
  51. package/dist/helpers/types.js +0 -5
  52. package/dist/index.d.ts +0 -7
  53. package/dist/index.js +0 -9
  54. package/dist/locales/index.d.ts +0 -12
  55. package/dist/locales/index.js +0 -17
  56. package/dist/locales/translations/en.json +0 -33
  57. package/dist/pdf/components/FieldVerificationBadge.d.ts +0 -5
  58. package/dist/pdf/components/FieldVerificationBadge.js +0 -12
  59. package/dist/pdf/components/Images.d.ts +0 -5
  60. package/dist/pdf/components/Images.js +0 -13
  61. package/dist/pdf/components/InnerTableRows.d.ts +0 -10
  62. package/dist/pdf/components/InnerTableRows.js +0 -30
  63. package/dist/pdf/components/POVerificationBadge.d.ts +0 -7
  64. package/dist/pdf/components/POVerificationBadge.js +0 -34
  65. package/dist/pdf/components/Report.d.ts +0 -12
  66. package/dist/pdf/components/Report.js +0 -91
  67. package/dist/pdf/components/Subheader.d.ts +0 -1
  68. package/dist/pdf/components/Subheader.js +0 -21
  69. package/dist/pdf/components/Table.d.ts +0 -8
  70. package/dist/pdf/components/Table.js +0 -40
  71. package/dist/pdf/components/TableTitle.d.ts +0 -4
  72. package/dist/pdf/components/TableTitle.js +0 -10
  73. package/dist/pdf/components/ValidationDisplay.d.ts +0 -4
  74. package/dist/pdf/components/ValidationDisplay.js +0 -22
  75. package/dist/pdf/components/VerifyBox.d.ts +0 -8
  76. package/dist/pdf/components/VerifyBox.js +0 -12
  77. package/dist/pdf/components/pieChart.d.ts +0 -6
  78. package/dist/pdf/components/pieChart.js +0 -23
  79. package/dist/pdf/constants.d.ts +0 -3
  80. package/dist/pdf/constants.js +0 -9
  81. package/dist/pdf/helpers/general.d.ts +0 -8
  82. package/dist/pdf/helpers/general.js +0 -31
  83. package/dist/pdf/helpers/transform.d.ts +0 -4
  84. package/dist/pdf/helpers/transform.js +0 -35
  85. package/dist/pdf/style.d.ts +0 -10
  86. package/dist/pdf/style.js +0 -21
  87. package/dist/public-methods/generatePDF.d.ts +0 -4
  88. package/dist/public-methods/generatePDF.js +0 -54
  89. package/dist/public-methods/getAndValidateConfig.d.ts +0 -8
  90. package/dist/public-methods/getAndValidateConfig.js +0 -16
  91. package/dist/public-methods/processSubmission.d.ts +0 -49
  92. package/dist/public-methods/processSubmission.js +0 -132
  93. package/dist/public-methods/saveToS3Bucket.d.ts +0 -2
  94. package/dist/public-methods/saveToS3Bucket.js +0 -53
  95. package/dist/public-methods/version.d.ts +0 -2
  96. package/dist/public-methods/version.js +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "6.4.0",
3
+ "version": "6.4.2",
4
4
  "author": "Raytio",
5
5
  "type": "module",
6
6
  "description": "A helper to decrypt data shared by Raytio users",
@@ -1 +0,0 @@
1
- export declare function authedFetch<T>(apiToken: string | null | undefined, url: string, options?: RequestInit, retrying?: boolean): Promise<T>;
@@ -1,35 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export function authedFetch(apiToken, url, options, retrying = false) {
11
- return __awaiter(this, void 0, void 0, function* () {
12
- console.log(`[API] ${retrying ? "Retry" : "Start"} ${url}`);
13
- const startTime = Date.now();
14
- const headers = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), (apiToken ? { Authorization: `Bearer ${apiToken}` } : {}));
15
- const response = yield fetch(url, Object.assign(Object.assign({}, options), { headers }));
16
- let apiResponse = null;
17
- const contentType = response.headers.get("content-type");
18
- if (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("application/json")) {
19
- const responseText = yield response.text();
20
- apiResponse = responseText ? JSON.parse(responseText) : null;
21
- }
22
- if (!response.ok) {
23
- if (!retrying && response.status === 504) {
24
- console.log(`[API] Error ${response.status} (will retry) ${url}`);
25
- return authedFetch(apiToken, url, options, true);
26
- }
27
- const error = (apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.message) || (apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.error) || "No error message provided";
28
- console.log(`[API] Error ${response.status} (no retry) ${url}`);
29
- throw new Error(`Failed due to API Error from ${url}: "${error}"`);
30
- }
31
- const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
32
- console.log(`[API] Finish${retrying ? " after retry" : ""} (${totalTime}s) ${url}`);
33
- return apiResponse;
34
- });
35
- }
@@ -1,3 +0,0 @@
1
- import type { AA, AId } from "@raytio/types";
2
- import type { EnvConfig } from "./fetchEnvConfig.js";
3
- export declare function fetchAA(apiToken: string, envConfig: EnvConfig, aId: AId): Promise<AA>;
@@ -1,18 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { authedFetch } from "./authedFetch.js";
11
- export function fetchAA(apiToken, envConfig, aId) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- const [AA] = yield authedFetch(apiToken, `${envConfig.api_url}/db/v1/dsm_access_applications?id=eq.${aId}`);
14
- if (!AA)
15
- throw new Error("AA not found");
16
- return Object.assign(Object.assign({}, AA), { a_id: AA.id });
17
- });
18
- }
@@ -1,6 +0,0 @@
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 {};
@@ -1,35 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- const PARAMS = [
11
- "cognito_region",
12
- "cognito_user_pool_id",
13
- "cognito_web_client_id",
14
- "api_url",
15
- "app_name", // whitelabelling name
16
- "logo_url", // must be a URL to a png file
17
- ];
18
- const DEFAULTS = {
19
- app_name: "Raytio",
20
- logo_url: undefined,
21
- };
22
- export function fetchEnvConfig(clientUrl) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- try {
25
- const envConfig = Object.assign(Object.assign({}, DEFAULTS), (yield fetch(`${clientUrl}/client_config.json`).then((r) => r.json())));
26
- const missing = PARAMS.filter((p) => !(p in envConfig));
27
- if (missing.length)
28
- throw new Error(`Missing: ${missing.join(", ")}`);
29
- return Object.assign(Object.assign({}, envConfig), { clientUrl });
30
- }
31
- catch (ex) {
32
- 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})`);
33
- }
34
- });
35
- }
@@ -1,3 +0,0 @@
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,16 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { authedFetch } from "./authedFetch.js";
11
- export function fetchInstanceData(apiToken, envConfig, instanceId) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- const [instance] = yield authedFetch(apiToken, `${envConfig.api_url}/db/v1/dsm_access_application_instances?id=eq.${instanceId}`);
14
- return instance;
15
- });
16
- }
@@ -1,6 +0,0 @@
1
- import type { Instance, NId, ProfileObject } from "@raytio/types";
2
- import type { ApplicationEncryptorLike } from "../types.js";
3
- import type { EnvConfig } from "./fetchEnvConfig.js";
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 {};
@@ -1,125 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
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";
15
- const TEMP_OBJ_PREFIX = "urn:temp_object:";
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"; };
17
- const decryptFile = (encryptedData, encryptedObject, applicationDecryptor, wdek) => __awaiter(void 0, void 0, void 0, function* () {
18
- const clonedEncryptedObject = JSON.parse(JSON.stringify(encryptedObject));
19
- clonedEncryptedObject.encrypted_data.data = encryptedData;
20
- const decrypted = yield applicationDecryptor.decrypt(clonedEncryptedObject, wdek);
21
- return decrypted;
22
- });
23
- const cleanApiResponse = (responseBody) => {
24
- try {
25
- const realB64 = Buffer.from(responseBody, "base64").toString("binary");
26
- if (realB64.slice(0, 5) === "data:") {
27
- return realB64;
28
- }
29
- }
30
- catch (_a) {
31
- // for some reason we need to do this...
32
- }
33
- return responseBody;
34
- };
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) {
42
- var _a;
43
- return __awaiter(this, void 0, void 0, function* () {
44
- // [nId2: NId2, fieldName: string, file: Urn | Encrypted<Urn>][]
45
- const urnOrEncryptedList = profileObjects.flatMap((PO) => {
46
- return Object.entries(PO.properties)
47
- .map(([k, v]) => {
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);
87
- });
88
- const filesBase64 = yield Promise.all(urnOrEncryptedList.map(([PONId2, fileNId, fieldName, urnOrEncrypted]) => __awaiter(this, void 0, void 0, function* () {
89
- var _b, _c;
90
- // handle urn:temp_object:
91
- if (typeof urnOrEncrypted === "string" &&
92
- urnOrEncrypted.startsWith(TEMP_OBJ_PREFIX)) {
93
- const url = Buffer.from(urnOrEncrypted.slice(TEMP_OBJ_PREFIX.length), "base64").toString("binary");
94
- const response = yield fetch(url);
95
- const base64 = Buffer.from(yield response.arrayBuffer()).toString("base64");
96
- const type = response.headers.get("content-type") || "text/plain";
97
- const dataUrl = `data:${type};base64,${base64}`;
98
- return [fileNId, [dataUrl, getFileExtn(dataUrl)]];
99
- }
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;
103
- if (!wdek)
104
- return [fileNId, undefined];
105
- const decryptedDataUrl = yield decryptFile(realDataUrl, urnOrEncrypted, applicationDecryptor, wdek);
106
- return [fileNId, [decryptedDataUrl, getFileExtn(decryptedDataUrl)]];
107
- }
108
- return [fileNId, [realDataUrl, getFileExtn(realDataUrl)]];
109
- })));
110
- const allDataUrls = Object.fromEntries(filesBase64.filter((file) => { var _a; return !!file[1] && ((_a = file[1][0]) === null || _a === void 0 ? void 0 : _a.includes(",")); }));
111
- // for all videos, also store a static frame from the video, since we can't embedded a video into the PDF
112
- for (const nId in allDataUrls) {
113
- const [dataUrl, fileExtn] = allDataUrls[nId];
114
- const isVideo = (_a = types[fileExtn]) === null || _a === void 0 ? void 0 : _a.startsWith("video/");
115
- if (isVideo) {
116
- const imageDataUrl = yield videoToImage(apiToken, envConfig, dataUrl);
117
- allDataUrls[`${nId}_videoFrame`] = [
118
- imageDataUrl,
119
- getFileExtn(imageDataUrl),
120
- ];
121
- }
122
- }
123
- return allDataUrls;
124
- });
125
- }
@@ -1,2 +0,0 @@
1
- import type { Lookup } from "@raytio/types";
2
- export declare function getLookupOption(apiToken: string, lookup: string): Promise<Lookup[]>;
@@ -1,28 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { authedFetch } from "./authedFetch.js";
11
- /**
12
- * We cache the promise so that only one XHR request is ever sent
13
- */
14
- const cache = new Map();
15
- export function getLookupOption(apiToken, lookup) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { origin } = new URL(lookup);
18
- const cached = cache.get(lookup);
19
- if (cached)
20
- return cached;
21
- // if it's a lookup to our own API, then include the IdentityToken
22
- const promise = origin.endsWith(".rayt.io")
23
- ? authedFetch(apiToken, lookup)
24
- : fetch(lookup).then((r) => r.json());
25
- cache.set(lookup, promise);
26
- return promise;
27
- });
28
- }
@@ -1,3 +0,0 @@
1
- import type { Schema } from "@raytio/types";
2
- import type { EnvConfig } from "./fetchEnvConfig.js";
3
- export declare function getAllSchema(envConfig: EnvConfig): Promise<Schema[]>;
@@ -1,19 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { expandSchema } from "@raytio/core";
11
- import { authedFetch } from "./authedFetch.js";
12
- export function getAllSchema(envConfig) {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- const list = yield authedFetch("", `${envConfig.api_url}/db/v1/dsm_schema?version_current=eq.true`);
15
- return list.map((wrappedSchema) => expandSchema(wrappedSchema, list, [
16
- process.env.PDF_LANGUAGE || process.env.DATE_FORMAT || "en-NZ",
17
- ]));
18
- });
19
- }
@@ -1,9 +0,0 @@
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 DELETED
@@ -1,9 +0,0 @@
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,11 +0,0 @@
1
- import type { VerificationProvider } from "@raytio/types";
2
- import type { EnvConfig } from "./fetchEnvConfig.js";
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;
@@ -1,31 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- let verifiersPromise;
11
- export function resolveVerificationDetails([details], envConfig) {
12
- var _a, _b, _c;
13
- return __awaiter(this, void 0, void 0, function* () {
14
- if (!details)
15
- return undefined;
16
- verifiersPromise || (verifiersPromise = fetch(`${envConfig.clientUrl}/verifiers.json`)
17
- .then((r) => r.json())
18
- .catch(() => ({ verifiers: {} })));
19
- const { verifiers } = yield verifiersPromise;
20
- return {
21
- verifier_id: (_a = verifiers[details.verifierNId]) === null || _a === void 0 ? void 0 : _a.name,
22
- verifier_service_id: (_b = verifiers[details.serviceProviderNId]) === null || _b === void 0 ? void 0 : _b.name,
23
- verifier_source_id: (_c = verifiers[details.dataSourceNId]) === null || _c === void 0 ? void 0 : _c.name,
24
- date: details.date ? new Date(details.date).toISOString() : undefined,
25
- };
26
- });
27
- }
28
- /** @deprecated - for use in unit tests only */
29
- export const clearCache = () => {
30
- verifiersPromise = null;
31
- };
@@ -1,7 +0,0 @@
1
- import type { ICognitoUserAttributeData } from "amazon-cognito-identity-js";
2
- import type { Config } from "../constants.js";
3
- import type { EnvConfig } from "./fetchEnvConfig.js";
4
- export declare function signIn(CONFIG: Config, envConfig: EnvConfig): Promise<{
5
- apiToken: string;
6
- cognitoAttributes: ICognitoUserAttributeData[];
7
- }>;
@@ -1,52 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Auth } from "@aws-amplify/auth";
11
- import { hashPassword } from "@raytio/core";
12
- /** see #1252 in the client repo */
13
- function signInWithPasswordMigration(username, password) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- try {
16
- const userObject = yield Auth.signIn(username, password);
17
- return userObject;
18
- }
19
- catch (_a) {
20
- // if the login fails, try again with their hashed password.
21
- // if it's successful the second time, we quietly change their password.
22
- const hashedPassword = yield hashPassword(password);
23
- const userObject = yield Auth.signIn(username, hashedPassword);
24
- // the login was successful. So we need to migrate their account.
25
- // No changes to the maxcryptor, purely to cognito.
26
- // we can only migrate their password if there are no login challenges
27
- if (!userObject.challengeName) {
28
- console.log("Migrating credentials...");
29
- yield Auth.changePassword(userObject, hashedPassword, password);
30
- }
31
- return userObject;
32
- }
33
- });
34
- }
35
- export function signIn(CONFIG, envConfig) {
36
- var _a, _b;
37
- return __awaiter(this, void 0, void 0, function* () {
38
- Auth.configure({
39
- region: envConfig.cognito_region,
40
- userPoolId: envConfig.cognito_user_pool_id,
41
- userPoolWebClientId: envConfig.cognito_web_client_id,
42
- });
43
- const userObject = yield signInWithPasswordMigration(CONFIG.RAYTIO_USERNAME, CONFIG.RAYTIO_PASSWORD);
44
- if (userObject.challengeName === "SOFTWARE_TOKEN_MFA") {
45
- throw new Error(`The configured account (${CONFIG.RAYTIO_USERNAME}) has two factor authentication enabled. You must disable 2FA or use a different account`);
46
- }
47
- const user = yield Auth.currentAuthenticatedUser();
48
- const apiToken = (_b = (_a = user.signInUserSession) === null || _a === void 0 ? void 0 : _a.accessToken) === null || _b === void 0 ? void 0 : _b.jwtToken;
49
- const cognitoAttributes = yield Auth.userAttributes(user);
50
- return { apiToken, cognitoAttributes };
51
- });
52
- }
@@ -1,7 +0,0 @@
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,23 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
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) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- yield authedFetch(apiToken, `${envConfig.api_url}/db/v1/dsm_access_application_instances_u?id=eq.${iId}`, {
18
- method: "PATCH",
19
- headers: { "Content-Type": "application/json" },
20
- body: JSON.stringify(instance),
21
- });
22
- });
23
- }
@@ -1,5 +0,0 @@
1
- import type { EnvConfig } from "./fetchEnvConfig.js";
2
- export declare function uploadToObjectStore(apiToken: string, envConfig: EnvConfig, dataUrl: string, expiryDate?: Date, storePermanently?: boolean): Promise<{
3
- objectStoreId: string;
4
- retrievalUrl: string;
5
- }>;
@@ -1,40 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { authedFetch } from "./authedFetch.js";
11
- //
12
- // this file is mostly copy-pasted from the client repo. If you make
13
- // a change here, consider making the same change in the client.
14
- //
15
- export function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate, storePermanently) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const mimeType = dataUrl.split(";")[0].split(":")[1];
18
- const base64 = dataUrl.split(",")[1];
19
- // eslint-disable-next-line unicorn/prefer-code-point -- deliberate, this will only ever be ASCII
20
- const arrayBuffer = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
21
- // this is a weird API that returns a double stringified string
22
- const { presigned_url } = yield authedFetch(apiToken, expiryDate
23
- ? `${envConfig.api_url}/persist/v2/generate-presigned-url?expires=${+expiryDate}${storePermanently ? "&store_permanently=true" : ""}`
24
- : `${envConfig.api_url}/persist/v2/generate-presigned-url${storePermanently ? "?store_permanently=true" : ""}`);
25
- const { status, statusText } = yield fetch(presigned_url, {
26
- method: "PUT",
27
- body: arrayBuffer,
28
- headers: { "Content-Type": mimeType },
29
- });
30
- if (status !== 200) {
31
- throw new Error(`Status ${status} from object store: ${statusText}`);
32
- }
33
- // the v4 API doesn't return the ID
34
- const { pathname, origin } = new URL(presigned_url);
35
- return {
36
- objectStoreId: pathname.slice(1),
37
- retrievalUrl: origin + pathname,
38
- };
39
- });
40
- }
@@ -1,3 +0,0 @@
1
- import type { EnvConfig } from "./fetchEnvConfig.js";
2
- /** Use the extractor API to get the middle frame from a video */
3
- export declare function videoToImage(apiToken: string, envConfig: EnvConfig, videoDataUrl: string): Promise<string>;
@@ -1,26 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { authedFetch } from "./authedFetch.js";
11
- import { uploadToObjectStore } from "./uploadToObjectStore.js";
12
- /** Use the extractor API to get the middle frame from a video */
13
- export function videoToImage(apiToken, envConfig, videoDataUrl) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- // the new API can't handle big dataUrls, so we need to store the data in
16
- // the object store first...
17
- const in10Mins = new Date();
18
- in10Mins.setMinutes(in10Mins.getMinutes() + 10);
19
- const { retrievalUrl: videoUrl } = yield uploadToObjectStore(apiToken, envConfig, videoDataUrl, in10Mins);
20
- const extractedImageBase64 = yield authedFetch(apiToken, `${envConfig.api_url}/face-detect/v1/image-extract-single`,
21
- // note: inspite of being called "video_urn", the new API actually expects a url, not a urn...
22
- { method: "POST", body: JSON.stringify({ video_urn: videoUrl }) });
23
- // annoyingly the new API doesn't return the data URL prefix, so we have to hardcode it here
24
- return `data:image/jpeg;base64,${extractedImageBase64}`;
25
- });
26
- }
@@ -1 +0,0 @@
1
- import "localstorage-polyfill";
@@ -1,19 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- // for @aws-amplify/auth
11
- import "localstorage-polyfill";
12
- // Polyfill crypto for node ≤18.
13
- if (!globalThis.crypto) {
14
- (() => __awaiter(void 0, void 0, void 0, function* () {
15
- const { webcrypto } = yield import("node:crypto");
16
- // @ts-expect-error fix
17
- globalThis.crypto = webcrypto;
18
- }))();
19
- }
@@ -1,23 +0,0 @@
1
- import * as RaytioCore from "@raytio/core";
2
- import { FieldVerification, type 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?: RaytioCore.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
- };