@raytio/decrypt-helper 6.3.4 → 6.4.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.
@@ -1 +1 @@
1
- export declare function authedFetch<T>(apiToken: string, url: string, options?: RequestInit, retrying?: boolean): Promise<T>;
1
+ export declare function authedFetch<T>(apiToken: string | null | undefined, url: string, options?: RequestInit, retrying?: boolean): Promise<T>;
@@ -11,14 +11,20 @@ export function authedFetch(apiToken, url, options, retrying = false) {
11
11
  return __awaiter(this, void 0, void 0, function* () {
12
12
  console.log(`[API] ${retrying ? "Retry" : "Start"} ${url}`);
13
13
  const startTime = Date.now();
14
- const response = yield fetch(url, Object.assign(Object.assign({}, options), { headers: { Authorization: `Bearer ${apiToken}` } }));
15
- const apiResponse = yield response.json();
16
- const error = apiResponse.message || apiResponse.error;
17
- if (error) {
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) {
18
23
  if (!retrying && response.status === 504) {
19
24
  console.log(`[API] Error ${response.status} (will retry) ${url}`);
20
25
  return authedFetch(apiToken, url, options, true);
21
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";
22
28
  console.log(`[API] Error ${response.status} (no retry) ${url}`);
23
29
  throw new Error(`Failed due to API Error from ${url}: "${error}"`);
24
30
  }
@@ -14,6 +14,10 @@ import { authedFetch } from "./authedFetch.js";
14
14
  */
15
15
  export function updateInstanceData(apiToken, envConfig, iId, instance) {
16
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}`, { method: "PATCH", body: JSON.stringify(instance) });
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
+ });
18
22
  });
19
23
  }
@@ -1,5 +1,5 @@
1
1
  import type { EnvConfig } from "./fetchEnvConfig.js";
2
- export declare function uploadToObjectStore(apiToken: string, envConfig: EnvConfig, dataUrl: string, expiryDate?: Date): Promise<{
2
+ export declare function uploadToObjectStore(apiToken: string, envConfig: EnvConfig, dataUrl: string, expiryDate?: Date, storePermanently?: boolean): Promise<{
3
3
  objectStoreId: string;
4
4
  retrievalUrl: string;
5
5
  }>;
@@ -12,15 +12,17 @@ import { authedFetch } from "./authedFetch.js";
12
12
  // this file is mostly copy-pasted from the client repo. If you make
13
13
  // a change here, consider making the same change in the client.
14
14
  //
15
- export function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate) {
15
+ export function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate, storePermanently) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  const mimeType = dataUrl.split(";")[0].split(":")[1];
18
18
  const base64 = dataUrl.split(",")[1];
19
19
  // eslint-disable-next-line unicorn/prefer-code-point -- deliberate, this will only ever be ASCII
20
20
  const arrayBuffer = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
21
21
  // this is a weird API that returns a double stringified string
22
- const temporaryUrl = yield authedFetch(apiToken, `${envConfig.api_url}/org/v1/object/url${expiryDate ? `?expires=${+expiryDate}` : ""}`);
23
- const { status, statusText } = yield fetch(temporaryUrl, {
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, {
24
26
  method: "PUT",
25
27
  body: arrayBuffer,
26
28
  headers: { "Content-Type": mimeType },
@@ -29,7 +31,7 @@ export function uploadToObjectStore(apiToken, envConfig, dataUrl, expiryDate) {
29
31
  throw new Error(`Status ${status} from object store: ${statusText}`);
30
32
  }
31
33
  // the v4 API doesn't return the ID
32
- const { pathname, origin } = new URL(temporaryUrl);
34
+ const { pathname, origin } = new URL(presigned_url);
33
35
  return {
34
36
  objectStoreId: pathname.slice(1),
35
37
  retrievalUrl: origin + pathname,
@@ -27,7 +27,16 @@ const byPriority = (schema) => ([a], [b]) => {
27
27
  export function formatOutput(profileObjects, allSchemas, realVers, apiToken, envConfig) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
29
  const locale = process.env.PDF_LANGUAGE || process.env.DATE_FORMAT || "en-NZ";
30
- const PODetails = profileObjects.reduce((accumulatorPromiseOuter, PO) => __awaiter(this, void 0, void 0, function* () {
30
+ const tagsToHide = [
31
+ "type:client_only",
32
+ "type:globally_unique_field",
33
+ ];
34
+ const filteredPOs = profileObjects.filter((PO) => {
35
+ const schemaName = findSchemaLabel(PO.labels);
36
+ return (schemaName &&
37
+ !tagsToHide.some((tag) => { var _a, _b; return (_b = (_a = allSchemas.find((s) => s.name === schemaName)) === null || _a === void 0 ? void 0 : _a.tags) === null || _b === void 0 ? void 0 : _b.includes(tag); }));
38
+ });
39
+ const PODetails = filteredPOs.reduce((accumulatorPromiseOuter, PO) => __awaiter(this, void 0, void 0, function* () {
31
40
  var _a;
32
41
  const accumulatorOuter = yield accumulatorPromiseOuter;
33
42
  const schemaName = findSchemaLabel(PO.labels);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "6.3.4",
3
+ "version": "6.4.0",
4
4
  "author": "Raytio",
5
5
  "type": "module",
6
6
  "description": "A helper to decrypt data shared by Raytio users",
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@aws-amplify/auth": "3.4.25",
26
- "@raytio/core": "^11.4.1",
26
+ "@raytio/core": "^11.5.0",
27
27
  "@raytio/maxcryptor": "^3.1.0",
28
- "@raytio/types": "^7.3.0",
28
+ "@raytio/types": "^8.0.0",
29
29
  "aws-sdk": "^2.754.0",
30
30
  "jsx-pdf": "^2.3.0",
31
31
  "localstorage-polyfill": "^1.0.1",