@raytio/decrypt-helper 6.3.5 → 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>;
|
package/dist/api/authedFetch.js
CHANGED
|
@@ -11,7 +11,8 @@ 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
|
|
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 }));
|
|
15
16
|
let apiResponse = null;
|
|
16
17
|
const contentType = response.headers.get("content-type");
|
|
17
18
|
if (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("application/json")) {
|
|
@@ -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
|
|
23
|
-
|
|
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(
|
|
34
|
+
const { pathname, origin } = new URL(presigned_url);
|
|
33
35
|
return {
|
|
34
36
|
objectStoreId: pathname.slice(1),
|
|
35
37
|
retrievalUrl: origin + pathname,
|