@iblai/web-utils 1.1.8 → 1.1.10

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.js CHANGED
@@ -1,4 +1,3 @@
1
- 'use client';
2
1
  'use strict';
3
2
 
4
3
  var React = require('react');
@@ -1220,10 +1219,13 @@ const getPlatform = () => {
1220
1219
  }
1221
1220
  return "unknown";
1222
1221
  };
1222
+ // Safe access to platform-specific APIs
1223
1223
  const safeRequire = (moduleName) => {
1224
1224
  try {
1225
- if (typeof __non_webpack_require__ !== "undefined") {
1226
- return __non_webpack_require__(moduleName);
1225
+ // eslint-disable-next-line no-undef, @typescript-eslint/no-require-imports
1226
+ if (typeof require !== "undefined") {
1227
+ // eslint-disable-next-line no-undef, @typescript-eslint/no-require-imports
1228
+ return require(moduleName);
1227
1229
  }
1228
1230
  }
1229
1231
  catch (error) {
@@ -3437,6 +3439,13 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
3437
3439
  // user is not authenticated so we don't need to do anything that concerns an authenticated user
3438
3440
  return;
3439
3441
  }
3442
+ // Logged-in user on a public route (e.g. shareable link) visiting another tenant
3443
+ // — treat as visitor, skip tenant join/token/RBAC calls that will 403
3444
+ if (userIsAccessingPublicRoute) {
3445
+ saveVisitingTenant === null || saveVisitingTenant === void 0 ? void 0 : saveVisitingTenant(newCurrentTenant);
3446
+ setIsLoading(false);
3447
+ return;
3448
+ }
3440
3449
  const { data: tenants } = await fetchUserTenants();
3441
3450
  const enhancedTenants = await enhanceTenants(tenants, data);
3442
3451
  saveUserTenants(enhancedTenants);
@@ -3454,10 +3463,10 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
3454
3463
  }
3455
3464
  if (currentTenant && currentTenant !== tenantKey) {
3456
3465
  setTenantKey(data.platform_key);
3457
- const rbacPermissions = await loadPlatformPermissions(data.platform_key);
3458
- onLoadPlatformPermissions === null || onLoadPlatformPermissions === void 0 ? void 0 : onLoadPlatformPermissions(rbacPermissions);
3459
3466
  const userAlreadyInTenant = enhancedTenants === null || enhancedTenants === void 0 ? void 0 : enhancedTenants.find((t) => t.key === tenantKey);
3460
3467
  if (userAlreadyInTenant) {
3468
+ const rbacPermissions = await loadPlatformPermissions(data.platform_key);
3469
+ onLoadPlatformPermissions === null || onLoadPlatformPermissions === void 0 ? void 0 : onLoadPlatformPermissions(rbacPermissions);
3461
3470
  const formData = new FormData();
3462
3471
  formData.append("platform_key", tenantKey);
3463
3472
  const { data: tokenResponse } = await getAppToken(formData).unwrap();
@@ -3488,6 +3497,8 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
3488
3497
  else {
3489
3498
  // TODO: What happense when if for any reason we fetch tenants and it's an empty list
3490
3499
  }
3500
+ const rbacPermissions = await loadPlatformPermissions(data.platform_key);
3501
+ onLoadPlatformPermissions === null || onLoadPlatformPermissions === void 0 ? void 0 : onLoadPlatformPermissions(rbacPermissions);
3491
3502
  onAutoJoinUserToTenant === null || onAutoJoinUserToTenant === void 0 ? void 0 : onAutoJoinUserToTenant((_c = data.platform_name) !== null && _c !== void 0 ? _c : data === null || data === void 0 ? void 0 : data.platform_key.toUpperCase());
3492
3503
  saveTenant === null || saveTenant === void 0 ? void 0 : saveTenant(tenantKey);
3493
3504
  setUserIsAccessingPublicRoute(false);
@@ -3959,7 +3970,7 @@ function MentorProvider({ children, fallback, onAuthSuccess, onAuthFailure, redi
3959
3970
  mentorDbId = await getMentorDbId(mentor);
3960
3971
  }
3961
3972
  // Load permissions if we have a mentor DB ID and user is logged in
3962
- if (mentorDbId && isLoggedIn) {
3973
+ if (mentorDbId && isLoggedIn && !userIsAccessingPublicRoute) {
3963
3974
  const rbacPermissions = await loadMentorsPermissions(mentorDbId);
3964
3975
  onLoadMentorsPermissions === null || onLoadMentorsPermissions === void 0 ? void 0 : onLoadMentorsPermissions(rbacPermissions);
3965
3976
  }
@@ -4006,7 +4017,9 @@ function MentorProvider({ children, fallback, onAuthSuccess, onAuthFailure, redi
4006
4017
  }
4007
4018
  else {
4008
4019
  console.log("requested mentor exists in tenant, proceeding", requestedMentorId);
4009
- if (requestedMentorDbId && isLoggedIn) {
4020
+ if (requestedMentorDbId &&
4021
+ isLoggedIn &&
4022
+ !userIsAccessingPublicRoute) {
4010
4023
  const rbacPermissions = await loadMentorsPermissions(requestedMentorDbId);
4011
4024
  onLoadMentorsPermissions === null || onLoadMentorsPermissions === void 0 ? void 0 : onLoadMentorsPermissions(rbacPermissions);
4012
4025
  }
@@ -15237,6 +15250,14 @@ const NON_AI_ANALYTICS_ENDPOINTS = {
15237
15250
  service: SERVICES.DM,
15238
15251
  path: (args) => `/api/analytics/conversations?platform_key=${args.platform_key}${args.mentor_unique_id ? `&mentor_unique_id=${args.mentor_unique_id}` : ''}&metric=${args.metric}${args.date_filter ? `&date_filter=${args.date_filter}` : ''}${args.start_date ? `&start_date=${args.start_date}` : ''}${args.end_date ? `&end_date=${args.end_date}` : ''}`,
15239
15252
  },
15253
+ GET_CONTENT_ANALYTICS: {
15254
+ service: SERVICES.DM,
15255
+ path: () => `/api/analytics/content/`,
15256
+ },
15257
+ GET_CONTENT_ANALYTICS_DETAILS: {
15258
+ service: SERVICES.DM,
15259
+ path: (content_id) => `/api/analytics/content/details/${content_id}/`,
15260
+ },
15240
15261
  };
15241
15262
  const ANALYTICS_REDUCER_PATH = 'analyticsApiSlice';
15242
15263
 
@@ -15521,6 +15542,38 @@ createApi({
15521
15542
  service: NON_AI_ANALYTICS_ENDPOINTS.GET_TRANSCRIPTS_CONVERSATION_HEADLINE.service,
15522
15543
  }),
15523
15544
  }),
15545
+ getContentAnalytics: builder.query({
15546
+ query: (args) => ({
15547
+ url: NON_AI_ANALYTICS_ENDPOINTS.GET_CONTENT_ANALYTICS.path(),
15548
+ service: NON_AI_ANALYTICS_ENDPOINTS.GET_CONTENT_ANALYTICS.service,
15549
+ params: args,
15550
+ }),
15551
+ }),
15552
+ getContentAnalyticsDetails: builder.query({
15553
+ query: (args) => ({
15554
+ url: NON_AI_ANALYTICS_ENDPOINTS.GET_CONTENT_ANALYTICS_DETAILS.path(args.content_id),
15555
+ service: NON_AI_ANALYTICS_ENDPOINTS.GET_CONTENT_ANALYTICS_DETAILS.service,
15556
+ params: args,
15557
+ }),
15558
+ }),
15559
+ }),
15560
+ });
15561
+
15562
+ createApi({
15563
+ reducerPath: 'analyticsCustomApiSlice',
15564
+ baseQuery: iblFetchBaseQuery,
15565
+ tagTypes: ['Analytics'],
15566
+ endpoints: (builder) => ({
15567
+ getDownloadReportFromURL: builder.query({
15568
+ query: ({ url }) => ({
15569
+ url: url,
15570
+ service: SERVICES.DM,
15571
+ method: 'GET',
15572
+ responseHandler: (response) => response.blob(),
15573
+ }),
15574
+ // Blobs are non-serializable; disable caching to prevent Redux serialization warnings
15575
+ keepUnusedDataFor: 0,
15576
+ }),
15524
15577
  }),
15525
15578
  });
15526
15579
 
@@ -17314,8 +17367,8 @@ createApi({
17314
17367
  }),
17315
17368
  });
17316
17369
 
17317
- function useMentorSettings({ mentorId, tenantKey, username, }) {
17318
- var _a, _b, _c, _d;
17370
+ function useMentorSettings({ mentorId, tenantKey, username, isPublicRoute, }) {
17371
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
17319
17372
  const isLoggedIn = username !== ANONYMOUS_USERNAME;
17320
17373
  const { data: mentorSettings } = useGetMentorSettingsQuery({
17321
17374
  mentor: mentorId,
@@ -17323,7 +17376,7 @@ function useMentorSettings({ mentorId, tenantKey, username, }) {
17323
17376
  // @ts-expect-error - userId is passed but not in generated API types
17324
17377
  userId: username !== null && username !== void 0 ? username : "",
17325
17378
  }, {
17326
- skip: !username || !isLoggedIn,
17379
+ skip: !username || !isLoggedIn || !!isPublicRoute,
17327
17380
  });
17328
17381
  const { data: mentorPublicSettings } = useGetMentorPublicSettingsQuery({
17329
17382
  mentor: mentorId,
@@ -17335,44 +17388,26 @@ function useMentorSettings({ mentorId, tenantKey, username, }) {
17335
17388
  });
17336
17389
  return {
17337
17390
  data: {
17338
- profileImage: isLoggedIn
17339
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.profile_image
17340
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.profile_image,
17341
- greetingMethod: isLoggedIn
17342
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.greeting_method
17343
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.greeting_method,
17344
- proactiveResponse: isLoggedIn
17345
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.proactive_response
17346
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.proactive_response,
17347
- llmProvider: isLoggedIn ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_provider : "",
17348
- llmName: isLoggedIn
17349
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_name
17350
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.llm_name,
17351
- mentorUniqueId: isLoggedIn
17352
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_unique_id
17353
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_unique_id,
17354
- mentorVisibility: isLoggedIn
17355
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_visibility
17356
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_visibility,
17357
- mentorName: (_a = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor) !== null && _a !== void 0 ? _a : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor,
17358
- enableGuidedPrompts: isLoggedIn
17359
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.enable_guided_prompts
17360
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.enable_guided_prompts,
17361
- mentorSlug: isLoggedIn
17362
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_slug
17363
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_slug,
17364
- safetyDisclaimer: isLoggedIn
17365
- ? (_b = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.metadata) === null || _b === void 0 ? void 0 : _b.safety_disclaimer
17366
- : (_c = mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.metadata) === null || _c === void 0 ? void 0 : _c.safety_disclaimer,
17367
- mentorTools: isLoggedIn
17368
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_tools
17369
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_tools,
17370
- allowAnonymous: (_d = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.allow_anonymous) !== null && _d !== void 0 ? _d : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.allow_anonymous,
17391
+ profileImage: (_a = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.profile_image) !== null && _a !== void 0 ? _a : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.profile_image,
17392
+ greetingMethod: (_b = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.greeting_method) !== null && _b !== void 0 ? _b : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.greeting_method,
17393
+ proactiveResponse: (_c = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.proactive_response) !== null && _c !== void 0 ? _c : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.proactive_response,
17394
+ llmProvider: (mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_provider) ||
17395
+ (mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.llm_provider) ||
17396
+ "",
17397
+ llmName: (_d = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_name) !== null && _d !== void 0 ? _d : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.llm_name,
17398
+ mentorUniqueId: (_e = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_unique_id) !== null && _e !== void 0 ? _e : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_unique_id,
17399
+ mentorVisibility: (_f = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_visibility) !== null && _f !== void 0 ? _f : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_visibility,
17400
+ mentorName: (_g = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor) !== null && _g !== void 0 ? _g : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor,
17401
+ enableGuidedPrompts: (_h = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.enable_guided_prompts) !== null && _h !== void 0 ? _h : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.enable_guided_prompts,
17402
+ mentorSlug: (_j = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_slug) !== null && _j !== void 0 ? _j : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_slug,
17403
+ safetyDisclaimer: (_l = (_k = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.metadata) === null || _k === void 0 ? void 0 : _k.safety_disclaimer) !== null && _l !== void 0 ? _l : (_m = mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.metadata) === null || _m === void 0 ? void 0 : _m.safety_disclaimer,
17404
+ mentorTools: (_o = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_tools) !== null && _o !== void 0 ? _o : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_tools,
17405
+ allowAnonymous: (_p = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.allow_anonymous) !== null && _p !== void 0 ? _p : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.allow_anonymous,
17371
17406
  },
17372
17407
  };
17373
17408
  }
17374
17409
 
17375
- function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, token, wsUrl, stopGenerationWsUrl, redirectToAuthSpa, errorHandler, sendMessageToParentWebsite, isPreviewMode, mentorShareableToken, on402Error, cachedSessionId, onStartNewChat, onOAuthRequired, onOAuthResolved, isOffline = false, onOfflineWithoutLocalLLM, }) {
17410
+ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, token, wsUrl, stopGenerationWsUrl, redirectToAuthSpa, errorHandler, sendMessageToParentWebsite, isPreviewMode, mentorShareableToken, on402Error, cachedSessionId, onStartNewChat, onOAuthRequired, onOAuthResolved, isOffline = false, onOfflineWithoutLocalLLM, isPublicRoute, }) {
17376
17411
  var _a, _b, _c, _d;
17377
17412
  const dispatch = useDispatch();
17378
17413
  const [createSessionId, { isLoading: isLoadingSessionIds }] = dataLayer.useCreateSessionIdMutation();
@@ -17392,6 +17427,7 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
17392
17427
  mentorId,
17393
17428
  tenantKey,
17394
17429
  username,
17430
+ isPublicRoute,
17395
17431
  });
17396
17432
  const onStreamingChange = (streamingState) => {
17397
17433
  dispatch(chatActions.setStreaming(streamingState));
@@ -17704,26 +17740,30 @@ function hasTool(tools, mentorSettings, toolSlug) {
17704
17740
  // Check if the specific tool exists in both available tools and enabled tools
17705
17741
  return tools.some((tool) => tool.slug === toolSlug && enabledToolSlugs.has(tool.slug));
17706
17742
  }
17707
- function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, errorHandler, }) {
17743
+ function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, errorHandler, isPublicRoute, }) {
17708
17744
  var _a;
17709
17745
  const dispatch = useDispatch();
17710
17746
  const activeTools = useSelector(selectTools);
17711
17747
  const artifactsEnabled = useSelector(selectArtifactsEnabled);
17712
17748
  const sessionId = useSelector(selectSessionId);
17713
17749
  const [editSession] = dataLayer.useEditSessionMutation();
17714
- const { data: tools } = dataLayer.useGetToolsQuery({
17750
+ const { data: apiTools } = dataLayer.useGetToolsQuery({
17715
17751
  mentor: mentorId,
17716
17752
  org: tenantKey,
17717
17753
  // @ts-expect-error - userId is passed but not in generated API types
17718
17754
  userId: username !== null && username !== void 0 ? username : "",
17719
17755
  }, {
17720
- skip: !username || username === ANONYMOUS_USERNAME,
17756
+ skip: !username || username === ANONYMOUS_USERNAME || !!isPublicRoute,
17721
17757
  });
17722
17758
  const { data: mentorSettings } = useMentorSettings({
17723
17759
  mentorId,
17724
17760
  tenantKey,
17725
17761
  username,
17762
+ isPublicRoute,
17726
17763
  });
17764
+ // Fall back to mentor_tools from public settings when available-tools endpoint
17765
+ // is blocked by RBAC (403). This ensures shareable link users see tool buttons.
17766
+ const tools = apiTools !== null && apiTools !== void 0 ? apiTools : mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentorTools;
17727
17767
  const { data: prompts } = dataLayer.useGetPromptsSearchQuery({
17728
17768
  org: tenantKey,
17729
17769
  username: username !== null && username !== void 0 ? username : "",
@@ -17733,7 +17773,7 @@ function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, er
17733
17773
  mentor: mentorId,
17734
17774
  orderDirection: "asc",
17735
17775
  }, {
17736
- skip: !tenantKey || !username || !mentorId,
17776
+ skip: !tenantKey || !username || !mentorId || !!isPublicRoute,
17737
17777
  });
17738
17778
  const updateSessionTools = async (tool) => {
17739
17779
  let toolsToAdd = activeTools;