@raytio/decrypt-helper 6.1.1 → 6.3.0

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 (78) hide show
  1. package/README.md +2 -2
  2. package/dist/api/authedFetch.js +1 -5
  3. package/dist/api/fetchAA.d.ts +2 -2
  4. package/dist/api/fetchAA.js +6 -7
  5. package/dist/api/fetchEnvConfig.js +2 -6
  6. package/dist/api/fetchInstanceData.d.ts +3 -3
  7. package/dist/api/fetchInstanceData.js +3 -8
  8. package/dist/api/getFiles.d.ts +2 -2
  9. package/dist/api/getFiles.js +59 -26
  10. package/dist/api/getLookupOption.d.ts +1 -1
  11. package/dist/api/getLookupOption.js +3 -7
  12. package/dist/api/getSchema.d.ts +1 -1
  13. package/dist/api/getSchema.js +5 -9
  14. package/dist/api/index.js +9 -25
  15. package/dist/api/resolveVerificationDetails.d.ts +1 -1
  16. package/dist/api/resolveVerificationDetails.js +2 -7
  17. package/dist/api/signIn.d.ts +2 -2
  18. package/dist/api/signIn.js +10 -14
  19. package/dist/api/updateInstanceData.d.ts +7 -2
  20. package/dist/api/updateInstanceData.js +7 -7
  21. package/dist/api/uploadToObjectStore.d.ts +1 -1
  22. package/dist/api/uploadToObjectStore.js +3 -7
  23. package/dist/api/videoToImage.d.ts +1 -1
  24. package/dist/api/videoToImage.js +5 -9
  25. package/dist/configureEnv.js +3 -29
  26. package/dist/constants.d.ts +2 -2
  27. package/dist/constants.js +20 -23
  28. package/dist/helpers/file.d.ts +4 -0
  29. package/dist/helpers/file.js +8 -9
  30. package/dist/helpers/formatOutput.d.ts +2 -2
  31. package/dist/helpers/formatOutput.js +24 -28
  32. package/dist/helpers/index.js +6 -22
  33. package/dist/helpers/json2csv.js +11 -15
  34. package/dist/helpers/lookup.d.ts +1 -1
  35. package/dist/helpers/lookup.js +3 -7
  36. package/dist/helpers/setupMaxcryptor.d.ts +2 -2
  37. package/dist/helpers/setupMaxcryptor.js +7 -11
  38. package/dist/helpers/splitPOAndVers.js +4 -8
  39. package/dist/helpers/types.js +1 -5
  40. package/dist/index.js +7 -16
  41. package/dist/locales/index.js +4 -12
  42. package/dist/pdf/components/FieldVerificationBadge.d.ts +0 -1
  43. package/dist/pdf/components/FieldVerificationBadge.js +8 -15
  44. package/dist/pdf/components/Images.d.ts +1 -2
  45. package/dist/pdf/components/Images.js +7 -14
  46. package/dist/pdf/components/InnerTableRows.d.ts +2 -3
  47. package/dist/pdf/components/InnerTableRows.js +19 -26
  48. package/dist/pdf/components/POVerificationBadge.d.ts +1 -2
  49. package/dist/pdf/components/POVerificationBadge.js +28 -35
  50. package/dist/pdf/components/Report.d.ts +3 -4
  51. package/dist/pdf/components/Report.js +61 -68
  52. package/dist/pdf/components/Subheader.d.ts +0 -1
  53. package/dist/pdf/components/Subheader.js +20 -27
  54. package/dist/pdf/components/Table.d.ts +3 -4
  55. package/dist/pdf/components/Table.js +21 -28
  56. package/dist/pdf/components/TableTitle.d.ts +1 -2
  57. package/dist/pdf/components/TableTitle.js +5 -12
  58. package/dist/pdf/components/ValidationDisplay.d.ts +1 -2
  59. package/dist/pdf/components/ValidationDisplay.js +10 -17
  60. package/dist/pdf/components/VerifyBox.d.ts +0 -1
  61. package/dist/pdf/components/VerifyBox.js +9 -16
  62. package/dist/pdf/components/pieChart.js +1 -5
  63. package/dist/pdf/constants.js +8 -11
  64. package/dist/pdf/helpers/general.js +11 -18
  65. package/dist/pdf/helpers/transform.d.ts +1 -1
  66. package/dist/pdf/helpers/transform.js +11 -15
  67. package/dist/pdf/style.d.ts +1 -1
  68. package/dist/pdf/style.js +7 -10
  69. package/dist/public-methods/generatePDF.d.ts +2 -2
  70. package/dist/public-methods/generatePDF.js +14 -22
  71. package/dist/public-methods/getAndValidateConfig.d.ts +1 -1
  72. package/dist/public-methods/getAndValidateConfig.js +3 -7
  73. package/dist/public-methods/processSubmission.d.ts +4 -4
  74. package/dist/public-methods/processSubmission.js +37 -33
  75. package/dist/public-methods/saveToS3Bucket.d.ts +1 -1
  76. package/dist/public-methods/saveToS3Bucket.js +6 -13
  77. package/dist/public-methods/version.js +7 -10
  78. package/package.json +33 -63
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ![npm version](https://img.shields.io/npm/v/@raytio/decrypt-helper?color=%234c1&style=flat-square)
6
6
  [![install size](https://packagephobia.com/badge?p=@raytio/decrypt-helper)](https://packagephobia.com/result?p=@raytio/decrypt-helper)
7
7
 
8
- ## Intsall
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 evironment variables in `.env` for integration tests.
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
 
@@ -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
- Object.defineProperty(exports, "__esModule", { value: true });
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;
@@ -1,3 +1,3 @@
1
- import type { AId, AA } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
1
+ import type { AA, AId } from "@raytio/types";
2
+ import type { EnvConfig } from "./fetchEnvConfig";
3
3
  export declare function fetchAA(apiToken: string, envConfig: EnvConfig, aId: AId): Promise<AA>;
@@ -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,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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fetchAA = void 0;
13
- const authedFetch_1 = require("./authedFetch");
14
- function fetchAA(apiToken, envConfig, aId) {
10
+ import { authedFetch } from "./authedFetch";
11
+ export function fetchAA(apiToken, envConfig, aId) {
15
12
  return __awaiter(this, void 0, void 0, function* () {
16
- return (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/${aId}`);
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
17
  });
18
18
  }
19
- 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, Instance } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
3
- export declare function fetchInstanceData(apiToken: string, envConfig: EnvConfig, instanceId: IId): Promise<Instance>;
1
+ import type { IId, InstanceWithoutData } from "@raytio/types";
2
+ import type { EnvConfig } from "./fetchEnvConfig";
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
- 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) {
10
+ import { authedFetch } from "./authedFetch";
11
+ export function fetchInstanceData(apiToken, envConfig, instanceId) {
16
12
  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);
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;
@@ -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";
3
+ import type { EnvConfig } from "./fetchEnvConfig";
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 {};
@@ -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
- 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");
10
+ import { getNidFromUrn, isEncrypted } from "@raytio/core";
11
+ import { extension, types } from "mime-types";
12
+ import { isFieldValueFile, isTruthy, isUrn } from "../helpers/file";
13
+ import { authedFetch } from "./authedFetch";
14
+ import { videoToImage } from "./videoToImage";
18
15
  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"; };
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 getFiles(profileObjects, instance, apiToken, envConfig, applicationDecryptor) {
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
- // [nId: NId, fieldName: string, file: RaytFile][]
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
- return [
47
- PO.n_id,
48
- v.n_id,
49
- k,
50
- "content" in v ? v.content : v.Content,
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(([PONId, fileNId, fieldName, urnOrEncrypted]) => __awaiter(this, void 0, void 0, function* () {
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 (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;
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 = mime_types_1.types[fileExtn]) === null || _a === void 0 ? void 0 : _a.startsWith("video/");
114
+ const isVideo = (_a = types[fileExtn]) === null || _a === void 0 ? void 0 : _a.startsWith("video/");
81
115
  if (isVideo) {
82
- const imageDataUrl = yield (0, videoToImage_1.videoToImage)(apiToken, envConfig, dataUrl);
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getLookupOption = void 0;
13
- const authedFetch_1 = require("./authedFetch");
10
+ import { authedFetch } from "./authedFetch";
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
- ? (0, authedFetch_1.authedFetch)(apiToken, lookup)
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;
@@ -1,3 +1,3 @@
1
1
  import type { Schema } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
2
+ import type { EnvConfig } from "./fetchEnvConfig";
3
3
  export declare function getAllSchema(envConfig: EnvConfig): Promise<Schema[]>;
@@ -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
- 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) {
10
+ import { expandSchema } from "@raytio/core";
11
+ import { authedFetch } from "./authedFetch";
12
+ export function getAllSchema(envConfig) {
16
13
  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, [
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.js CHANGED
@@ -1,25 +1,9 @@
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);
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,5 +1,5 @@
1
1
  import type { VerificationProvider } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
2
+ import type { EnvConfig } from "./fetchEnvConfig";
3
3
  export type ResolvedVerificationProvider = {
4
4
  verifier_id?: string;
5
5
  verifier_service_id?: 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,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;
@@ -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";
3
+ import type { EnvConfig } from "./fetchEnvConfig";
4
4
  export declare function signIn(CONFIG: Config, envConfig: EnvConfig): Promise<{
5
5
  apiToken: string;
6
6
  cognitoAttributes: ICognitoUserAttributeData[];
@@ -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
- 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");
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 auth_1.Auth.signIn(username, password);
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 (0, core_1.hashPassword)(password);
26
- const userObject = yield auth_1.Auth.signIn(username, hashedPassword);
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 auth_1.Auth.changePassword(userObject, hashedPassword, password);
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
- auth_1.Auth.configure({
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 auth_1.Auth.currentAuthenticatedUser();
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 auth_1.Auth.userAttributes(user);
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 { Instance } from "@raytio/types";
2
- export declare function updateInstanceData(apiToken: string, instance: Instance): Promise<void>;
1
+ import type { IId, InstanceWithoutData } from "@raytio/types";
2
+ import type { EnvConfig } from "./fetchEnvConfig";
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.updateInstanceData = void 0;
13
- const authedFetch_1 = require("./authedFetch");
14
- function updateInstanceData(apiToken, instance) {
10
+ import { authedFetch } from "./authedFetch";
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 (0, authedFetch_1.authedFetch)(apiToken, `share/v2/access_application/instance/${instance.i_id}`, { method: "PUT", body: JSON.stringify(instance) });
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";
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.uploadToObjectStore = void 0;
13
- const authedFetch_1 = require("./authedFetch");
10
+ import { authedFetch } from "./authedFetch";
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 (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/org/v1/object/url${expiryDate ? `?expires=${+expiryDate}` : ""}`);
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";
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>;
@@ -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,23 +7,20 @@ 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.videoToImage = void 0;
13
- const authedFetch_1 = require("./authedFetch");
14
- const uploadToObjectStore_1 = require("./uploadToObjectStore");
10
+ import { authedFetch } from "./authedFetch";
11
+ import { uploadToObjectStore } from "./uploadToObjectStore";
15
12
  /** Use the extractor API to get the middle frame from a video */
16
- function videoToImage(apiToken, envConfig, videoDataUrl) {
13
+ export function videoToImage(apiToken, envConfig, videoDataUrl) {
17
14
  return __awaiter(this, void 0, void 0, function* () {
18
15
  // the new API can't handle big dataUrls, so we need to store the data in
19
16
  // the object store first...
20
17
  const in10Mins = new Date();
21
18
  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`,
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`,
24
21
  // note: inspite of being called "video_urn", the new API actually expects a url, not a urn...
25
22
  { method: "POST", body: JSON.stringify({ video_urn: videoUrl }) });
26
23
  // annoyingly the new API doesn't return the data URL prefix, so we have to hardcode it here
27
24
  return `data:image/jpeg;base64,${extractedImageBase64}`;
28
25
  });
29
26
  }
30
- exports.videoToImage = videoToImage;