@putkoff/abstract-securefiles 0.0.34 → 0.0.43

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,4 +1,4 @@
1
1
  export type { QueuedFile, FileItem, FileTableProps, UploadProps, ShareModalProps, FileRowProps } from './../imports';
2
- export { CloudArrowUpIcon, currentUsername, Button, Checkbox, Input, Spinner, useEffect, useRef, useState, useCallback, ClipboardIcon, createPortal, fetchSharePatch, } from './../imports';
2
+ export { CloudArrowUpIcon, currentUsername, Button, Checkbox, Input, Spinner, useEffect, useRef, useState, useCallback, ClipboardIcon, createPortal, fetchSharePatch } from './../imports';
3
3
  export { useFiles } from './../hooks';
4
4
  export { downloadFile, uploadFiles } from './../file_utils';
@@ -2,6 +2,15 @@
2
2
  * Cookie-authenticated API helpers.
3
3
  * All requests include credentials: 'include' so the browser sends the
4
4
  * session cookie (auth_session) automatically. No JWT tokens are used.
5
+ *
6
+ * API base URL resolution order (first truthy value wins):
7
+ * 1. window.__SECURE_FILES_API_BASE__ – runtime override (any bundler)
8
+ * 2. VITE_SECURE_FILES_API_BASE – Vite env var
9
+ * 3. REACT_APP_SECURE_FILES_API_BASE – Create React App env var
10
+ * 4. /api/secure-files – same-origin default
11
+ *
12
+ * Subdomain API example (set one of the above to the full origin + path):
13
+ * VITE_SECURE_FILES_API_BASE=https://api.example.com/secure-files
5
14
  */
6
15
  /**
7
16
  * Generic JSON fetch with session-cookie auth.
@@ -10,13 +19,15 @@
10
19
  export declare function cookieFetch<T = unknown>(path: string, body?: unknown, method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"): Promise<T>;
11
20
  /**
12
21
  * Check whether the current session is valid.
13
- * Calls /userInfo which requires authentication; returns true if the user is
14
- * logged in, false otherwise (no exception thrown).
22
+ * Calls /userInfo which requires authentication; returns true if the user
23
+ * is logged in, false otherwise (no exception thrown).
15
24
  */
16
25
  export declare function checkAuth(): Promise<boolean>;
17
26
  /**
18
27
  * Upload a single file using multipart/form-data with session-cookie auth.
19
- * @param file The File object to upload.
28
+ * @param file The File object to upload.
20
29
  * @param relPath Optional relative path within the user's directory.
21
30
  */
22
31
  export declare function cookieUpload(file: File, relPath?: string): Promise<unknown>;
32
+ /** The resolved API base URL, exported for debugging / display purposes. */
33
+ export declare const SECURE_FILES_API_BASE: string;
package/dist/index.cjs CHANGED
@@ -292,8 +292,39 @@ async function patchFileSetting(fileId, field, value) {
292
292
  * Cookie-authenticated API helpers.
293
293
  * All requests include credentials: 'include' so the browser sends the
294
294
  * session cookie (auth_session) automatically. No JWT tokens are used.
295
+ *
296
+ * API base URL resolution order (first truthy value wins):
297
+ * 1. window.__SECURE_FILES_API_BASE__ – runtime override (any bundler)
298
+ * 2. VITE_SECURE_FILES_API_BASE – Vite env var
299
+ * 3. REACT_APP_SECURE_FILES_API_BASE – Create React App env var
300
+ * 4. /api/secure-files – same-origin default
301
+ *
302
+ * Subdomain API example (set one of the above to the full origin + path):
303
+ * VITE_SECURE_FILES_API_BASE=https://api.example.com/secure-files
295
304
  */
296
- const API_BASE = "/api/secure-files";
305
+ function resolveApiBase() {
306
+ // 1. Runtime window config — works regardless of bundler
307
+ if (typeof window !== "undefined" && window.__SECURE_FILES_API_BASE__) {
308
+ return String(window.__SECURE_FILES_API_BASE__).replace(/\/+$/, "");
309
+ }
310
+ // 2. Vite (import.meta.env is replaced at build time; guard with try for non-Vite builds)
311
+ try {
312
+ const v = undefined?.VITE_SECURE_FILES_API_BASE;
313
+ if (v)
314
+ return String(v).replace(/\/+$/, "");
315
+ }
316
+ catch { /* not a Vite build */ }
317
+ // 3. Create React App / plain Node
318
+ try {
319
+ const v = process.env?.REACT_APP_SECURE_FILES_API_BASE;
320
+ if (v)
321
+ return String(v).replace(/\/+$/, "");
322
+ }
323
+ catch { /* process not defined */ }
324
+ // 4. Same-origin default
325
+ return "/api/secure-files";
326
+ }
327
+ const API_BASE = resolveApiBase();
297
328
  function apiUrl(path) {
298
329
  const p = path.startsWith("/") ? path : `/${path}`;
299
330
  return `${API_BASE}${p}`;
@@ -321,8 +352,8 @@ async function cookieFetch(path, body, method) {
321
352
  }
322
353
  /**
323
354
  * Check whether the current session is valid.
324
- * Calls /userInfo which requires authentication; returns true if the user is
325
- * logged in, false otherwise (no exception thrown).
355
+ * Calls /userInfo which requires authentication; returns true if the user
356
+ * is logged in, false otherwise (no exception thrown).
326
357
  */
327
358
  async function checkAuth() {
328
359
  try {
@@ -338,7 +369,7 @@ async function checkAuth() {
338
369
  }
339
370
  /**
340
371
  * Upload a single file using multipart/form-data with session-cookie auth.
341
- * @param file The File object to upload.
372
+ * @param file The File object to upload.
342
373
  * @param relPath Optional relative path within the user's directory.
343
374
  */
344
375
  async function cookieUpload(file, relPath = "") {