varminer-app-header 2.2.7 → 2.2.8

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.
package/dist/index.d.ts CHANGED
@@ -115,11 +115,6 @@ declare const setI18nLocaleToStorage: (locale: string) => void;
115
115
  * @returns Object with auth, decodedToken, and other keys (user/userDetails/profile null when using header key)
116
116
  */
117
117
  declare const getAllDataFromStorage: () => any;
118
- /**
119
- * Get profile picture URL from object store API using user_id.
120
- * @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
121
- * @returns Profile picture URL or null if user_id is not available
122
- */
123
118
  declare const getProfilePictureUrl: (baseUrl?: string) => string | null;
124
119
  /**
125
120
  * Get access token from all known storage keys (header, IAM, userdb, and plain keys).
package/dist/index.esm.js CHANGED
@@ -373,22 +373,28 @@ const getAllDataFromStorage = () => {
373
373
  * @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
374
374
  * @returns Profile picture URL or null if user_id is not available
375
375
  */
376
+ const VERIFICATION_USER_ID = 4590; // set to null to use only storage userId
376
377
  const getProfilePictureUrl = (baseUrl = "http://objectstore.impact0mics.local:9012") => {
377
378
  try {
378
379
  const allData = getAllDataFromStorage();
379
- const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? null;
380
+ const userId = allData.decodedToken?.user_id ?? allData.auth?.user_id ?? getStoredUserDetails()?.userId ?? VERIFICATION_USER_ID ?? null;
380
381
  if (userId == null)
381
382
  return null;
382
- return `${baseUrl.replace(/\/$/, "")}/v1/objectStore/profilePicture/path/4590`;
383
+ return `${baseUrl.replace(/\/$/, "")}/v1/objectStore/profilePicture/path/${userId}`;
383
384
  }
384
385
  catch (err) {
385
386
  console.error("Error getting profile picture URL:", err);
386
387
  return null;
387
388
  }
388
389
  };
390
+ /** Extract S3 object key from s3Uri (e.g. s3://bucket/key → key). */
391
+ function getKeyFromS3Uri(s3Uri) {
392
+ const match = /^s3:\/\/[^/]+\/(.+)$/.exec(s3Uri.trim());
393
+ return match ? match[1] : null;
394
+ }
389
395
  /**
390
- * Fetch profile picture from object store API (plain GET with Authorization header).
391
- * API returns the image directly; response is converted to a blob URL for use in img src.
396
+ * Fetch profile picture: (1) GET path API for JSON with filePath/s3Uri, (2) GET download API with key to get image, return blob URL.
397
+ * Path API returns JSON: { statusResponse, filePath, s3Uri, errors }. Download API: GET /v1/objectStore/download?key=<key>.
392
398
  * @param baseUrl - Base URL for the object store API (default: http://objectstore.impact0mics.local:9012)
393
399
  * @returns Promise that resolves to blob URL string or null if fetch fails
394
400
  */
@@ -518,8 +524,8 @@ function getAccessTokenForRequest() {
518
524
  }
519
525
  const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact0mics.local:9012", accessTokenOverride) => {
520
526
  try {
521
- const profilePictureUrl = getProfilePictureUrl(baseUrl);
522
- if (!profilePictureUrl)
527
+ const profilePicturePathUrl = getProfilePictureUrl(baseUrl);
528
+ if (!profilePicturePathUrl)
523
529
  return null;
524
530
  const accessToken = (typeof accessTokenOverride === "string" && accessTokenOverride.length > 0
525
531
  ? accessTokenOverride
@@ -531,17 +537,48 @@ const fetchProfilePictureAsBlobUrl = async (baseUrl = "http://objectstore.impact
531
537
  if (accessToken) {
532
538
  headers["Authorization"] = `Bearer ${accessToken}`;
533
539
  }
534
- const response = await fetch(profilePictureUrl, { method: "GET", headers });
535
- if (!response.ok) {
536
- console.warn(`Failed to fetch profile picture: ${response.status} ${response.statusText}`);
540
+ // Step 1: GET path API JSON with filePath, s3Uri
541
+ const pathResponse = await fetch(profilePicturePathUrl, { method: "GET", headers });
542
+ if (!pathResponse.ok) {
543
+ console.warn(`Failed to fetch profile picture path: ${pathResponse.status} ${pathResponse.statusText}`);
544
+ return null;
545
+ }
546
+ const pathData = (await pathResponse.json());
547
+ const status = pathData?.statusResponse?.status;
548
+ if (status !== "SUCCESS") {
549
+ console.warn("Profile picture path API did not return SUCCESS:", status, pathData?.errors);
550
+ return null;
551
+ }
552
+ // Key for download API: from s3Uri (s3://bucket/key) or response.key
553
+ let downloadKey = pathData.key ??
554
+ (pathData.s3Uri ? getKeyFromS3Uri(pathData.s3Uri) : null);
555
+ if (!downloadKey && pathData.filePath) {
556
+ try {
557
+ const u = new URL(pathData.filePath);
558
+ downloadKey = u.pathname.replace(/^\//, ""); // path without leading slash as key
559
+ }
560
+ catch {
561
+ // ignore
562
+ }
563
+ }
564
+ if (!downloadKey) {
565
+ console.warn("Profile picture response has no key/s3Uri/filePath for download");
566
+ return null;
567
+ }
568
+ // Step 2: GET download API → image bytes
569
+ const cleanBase = baseUrl.replace(/\/$/, "");
570
+ const downloadUrl = `${cleanBase}/v1/objectStore/download?key=${encodeURIComponent(downloadKey)}`;
571
+ const imageResponse = await fetch(downloadUrl, { method: "GET", headers });
572
+ if (!imageResponse.ok) {
573
+ console.warn(`Failed to fetch profile picture image: ${imageResponse.status} ${imageResponse.statusText}`);
537
574
  return null;
538
575
  }
539
- const contentType = response.headers.get("content-type");
576
+ const contentType = imageResponse.headers.get("content-type");
540
577
  if (!contentType || !contentType.startsWith("image/")) {
541
- console.warn(`Profile picture response is not an image: ${contentType}`);
578
+ console.warn(`Profile picture download is not an image: ${contentType}`);
542
579
  return null;
543
580
  }
544
- const blob = await response.blob();
581
+ const blob = await imageResponse.blob();
545
582
  return URL.createObjectURL(blob);
546
583
  }
547
584
  catch (err) {