@iblai/web-utils 1.2.8 → 1.2.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
@@ -780,6 +780,9 @@ const TOOLS = {
780
780
  GOOGLE_SLIDES: "google-slides",
781
781
  GOOGLE_DOCUMENT: "google-docs",
782
782
  };
783
+ const REQUIRED_ACTIONS_FOR_GROUPS = {
784
+ NOTIFICATIONS: "Ibl.Notifications/Notification/action",
785
+ };
783
786
 
784
787
  const isJSON = (text) => {
785
788
  if (typeof text !== "string") {
@@ -2774,22 +2777,22 @@ async function getUserName(storageService) {
2774
2777
  * @param storageService - Storage service to access localStorage
2775
2778
  * @returns boolean indicating if token has expired
2776
2779
  */
2777
- async function isJwtTokenExpired(storageService) {
2780
+ async function isDmTokenExpired(storageService) {
2778
2781
  try {
2779
2782
  const dmTokenExpires = await storageService.getItem(LOCAL_STORAGE_KEYS.DM_TOKEN_EXPIRES);
2780
2783
  if (!dmTokenExpires) {
2781
- return false; // not expired if dm_token_expires not found
2784
+ return true;
2782
2785
  }
2783
2786
  const expiryTime = new Date(dmTokenExpires).getTime();
2784
2787
  const currentTime = Date.now();
2785
2788
  if (currentTime >= expiryTime) {
2786
- console.warn("[AuthProvider] JWT token has expired");
2789
+ console.warn("[AuthProvider] DM token has expired");
2787
2790
  return true;
2788
2791
  }
2789
2792
  return false;
2790
2793
  }
2791
2794
  catch (error) {
2792
- console.error("[AuthProvider] Error checking JWT token expiry:", error);
2795
+ console.error("[AuthProvider] Error checking DM token expiry:", error);
2793
2796
  return true; // Treat as expired on error
2794
2797
  }
2795
2798
  }
@@ -3008,12 +3011,12 @@ function useAuthProvider({ middleware = new Map(), onAuthSuccess, onAuthFailure,
3008
3011
  }
3009
3012
  // Check JWT token expiry and force logout for protected routes
3010
3013
  if (isProtectedRoute && storageService) {
3011
- const jwtExpired = await isJwtTokenExpired(storageService);
3012
- if (jwtExpired) {
3013
- console.log("[auth-redirect] JWT token has expired, forcing logout");
3014
+ const dmTokenExpired = await isDmTokenExpired(storageService);
3015
+ if (dmTokenExpired) {
3016
+ console.log("[auth-redirect] DM token has expired, forcing logout");
3014
3017
  // Clear all auth-related storage keys
3015
3018
  clearAuthCookies();
3016
- const reason = "JWT token expired";
3019
+ const reason = "DM token expired";
3017
3020
  onAuthFailure === null || onAuthFailure === void 0 ? void 0 : onAuthFailure(reason);
3018
3021
  safeRedirectToAuthSpa(undefined, undefined, true);
3019
3022
  return;
@@ -13611,6 +13614,7 @@ const buildEndpointFromService = (service, serviceFn) => {
13611
13614
  return { data };
13612
13615
  }
13613
13616
  catch (err) {
13617
+ console.error('[data-layer] API error:', JSON.stringify(err, Object.getOwnPropertyNames(err)));
13614
13618
  if (Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, err === null || err === void 0 ? void 0 : err.status)) {
13615
13619
  Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]({ ...((err === null || err === void 0 ? void 0 : err.data) || {}) });
13616
13620
  }
@@ -13681,7 +13685,7 @@ const invokeHttpErrorHandler = (status, error) => {
13681
13685
  }
13682
13686
  };
13683
13687
  /** HTTP status codes that should not be retried (e.g., 402 Payment Required). */
13684
- const NON_RETRYABLE_STATUS_CODES = [402];
13688
+ const NON_RETRYABLE_STATUS_CODES = [402, 401];
13685
13689
  /**
13686
13690
  * Wraps a base query to skip retries for non-retryable HTTP status codes.
13687
13691
  * Uses `retry.fail()` to immediately bail out of the retry loop.
@@ -13736,7 +13740,6 @@ const iblFetchBaseQuery = async (args, api, extraOptions) => {
13736
13740
  error: e,
13737
13741
  }));
13738
13742
  // Extract status from error and invoke HTTP error handlers
13739
- console.log('[MONETIZATION e]', { e });
13740
13743
  const err = e;
13741
13744
  const errorStatus = typeof e === 'object' && e !== null && 'status' in e
13742
13745
  ? e.status
@@ -14419,7 +14422,7 @@ createApi({
14419
14422
  });
14420
14423
 
14421
14424
  const featureTags = {
14422
- PLATFORM_USERS: "PLATFORM_USERS",
14425
+ PLATFORM_USERS: 'PLATFORM_USERS',
14423
14426
  };
14424
14427
 
14425
14428
  createApi({
@@ -14731,10 +14734,10 @@ createApi({
14731
14734
  credentials: 'omit',
14732
14735
  });
14733
14736
  if (!response.ok) {
14734
- const error = new Error('Failed to fetch RBAC group details');
14735
- error.status = response.status;
14736
- error.body = await response.text();
14737
- throw error;
14737
+ throw Object.assign(new Error('Failed to fetch RBAC group details'), {
14738
+ status: response.status,
14739
+ body: await response.text(),
14740
+ });
14738
14741
  }
14739
14742
  return response.json();
14740
14743
  }),
@@ -14768,10 +14771,10 @@ createApi({
14768
14771
  credentials: 'omit',
14769
14772
  });
14770
14773
  if (!response.ok) {
14771
- const error = new Error('Failed to fetch RBAC policy details');
14772
- error.status = response.status;
14773
- error.body = await response.text();
14774
- throw error;
14774
+ throw Object.assign(new Error('Failed to fetch RBAC policy details'), {
14775
+ status: response.status,
14776
+ body: await response.text(),
14777
+ });
14775
14778
  }
14776
14779
  return response.json();
14777
14780
  }),
@@ -14809,15 +14812,33 @@ createApi({
14809
14812
  credentials: 'omit',
14810
14813
  });
14811
14814
  if (!response.ok) {
14812
- const error = new Error('Failed to fetch RBAC role details');
14813
- error.status = response.status;
14814
- error.body = await response.text();
14815
- throw error;
14815
+ throw Object.assign(new Error('Failed to fetch RBAC role details'), {
14816
+ status: response.status,
14817
+ body: await response.text(),
14818
+ });
14816
14819
  }
14817
14820
  return response.json();
14818
14821
  }),
14819
14822
  providesTags: ['RbacRoles'],
14820
14823
  }),
14824
+ getDepartmentMemberCheck: builder.query({
14825
+ ...buildEndpointFromService(SERVICES.DM, async (args) => {
14826
+ const queryParams = new URLSearchParams({ platform_key: args.platform_key });
14827
+ const url = `${iblaiApi.OpenAPI.BASE}/api/core/departments/members/check/?${queryParams.toString()}`;
14828
+ const response = await fetch(url, {
14829
+ method: 'GET',
14830
+ headers: iblaiApi.OpenAPI.HEADERS,
14831
+ credentials: 'omit',
14832
+ });
14833
+ if (!response.ok) {
14834
+ throw Object.assign(new Error('Failed to fetch department member check'), {
14835
+ status: response.status,
14836
+ body: await response.text(),
14837
+ });
14838
+ }
14839
+ return response.json();
14840
+ }),
14841
+ }),
14821
14842
  getRbacMentorAccessList: builder.query({
14822
14843
  ...buildEndpointFromDmService(iblaiApi.CoreService.coreRbacMentorAccessList),
14823
14844
  }),
@@ -16092,6 +16113,7 @@ createApi({
16092
16113
  'catalog-roles',
16093
16114
  'catalog-invitations-course',
16094
16115
  'catalog-invitations-program',
16116
+ 'user-assigned-programs',
16095
16117
  ],
16096
16118
  endpoints: (builder) => ({
16097
16119
  getUserReportedSkills: builder.query({
@@ -16199,15 +16221,56 @@ createApi({
16199
16221
  credentials: 'omit',
16200
16222
  });
16201
16223
  if (!response.ok) {
16202
- const error = new Error('Failed to fetch program invitations');
16203
- error.status = response.status;
16204
- error.body = await response.text();
16205
- throw error;
16224
+ throw Object.assign(new Error('Failed to fetch program invitations'), {
16225
+ status: response.status,
16226
+ body: await response.text(),
16227
+ });
16206
16228
  }
16207
16229
  return response.json();
16208
16230
  }),
16209
16231
  providesTags: ['catalog-invitations-program'],
16210
16232
  }),
16233
+ getUserCatalogPathways: builder.query({
16234
+ ...buildEndpointFromService(SERVICES.DM, async (args) => {
16235
+ const params = new URLSearchParams({
16236
+ username: args.username,
16237
+ platform_key: args.platform_key,
16238
+ });
16239
+ const url = `${iblaiApi.OpenAPI.BASE}/api/catalog/pathways/?${params.toString()}`;
16240
+ const response = await fetch(url, {
16241
+ method: 'GET',
16242
+ headers: iblaiApi.OpenAPI.HEADERS,
16243
+ credentials: 'omit',
16244
+ });
16245
+ if (!response.ok) {
16246
+ throw Object.assign(new Error('Failed to fetch user catalog pathways'), {
16247
+ status: response.status,
16248
+ body: await response.text(),
16249
+ });
16250
+ }
16251
+ return response.json();
16252
+ }),
16253
+ providesTags: ['user-catalog-pathways'],
16254
+ }),
16255
+ getAssignedPrograms: builder.query({
16256
+ ...buildEndpointFromService(SERVICES.DM, async (args) => {
16257
+ const params = new URLSearchParams({ user_id: String(args.user_id) });
16258
+ const url = `${iblaiApi.OpenAPI.BASE}/api/catalog/suggestions/program/user/?${params.toString()}`;
16259
+ const response = await fetch(url, {
16260
+ method: 'GET',
16261
+ headers: iblaiApi.OpenAPI.HEADERS,
16262
+ credentials: 'omit',
16263
+ });
16264
+ if (!response.ok) {
16265
+ throw Object.assign(new Error('Failed to fetch assigned programs'), {
16266
+ status: response.status,
16267
+ body: await response.text(),
16268
+ });
16269
+ }
16270
+ return response.json();
16271
+ }),
16272
+ providesTags: ['user-assigned-programs'],
16273
+ }),
16211
16274
  }),
16212
16275
  });
16213
16276
 
@@ -16229,6 +16292,114 @@ createApi({
16229
16292
  }),
16230
16293
  });
16231
16294
 
16295
+ createApi({
16296
+ reducerPath: 'coursesApiSlice',
16297
+ baseQuery: iblFetchBaseQuery,
16298
+ tagTypes: ['user-enrolled-courses', 'user-assigned-courses'],
16299
+ endpoints: (builder) => ({
16300
+ getUserEnrolledCourses: builder.query({
16301
+ query: ({ username, query }) => {
16302
+ const params = new URLSearchParams();
16303
+ params.set('username', username);
16304
+ if (query) {
16305
+ for (const [k, v] of Object.entries(query)) {
16306
+ if (v !== undefined && v !== null)
16307
+ params.set(k, String(v));
16308
+ }
16309
+ }
16310
+ return {
16311
+ url: `/api/catalog/enrollment/courses/search/?${params.toString()}`,
16312
+ service: SERVICES.DM,
16313
+ method: 'GET',
16314
+ };
16315
+ },
16316
+ providesTags: ['user-enrolled-courses'],
16317
+ }),
16318
+ getUserAssignedCourses: builder.query({
16319
+ query: ({ user_id, query }) => {
16320
+ const params = new URLSearchParams();
16321
+ params.set('user_id', String(user_id));
16322
+ if (query) {
16323
+ for (const [k, v] of Object.entries(query)) {
16324
+ if (v !== undefined && v !== null)
16325
+ params.set(k, String(v));
16326
+ }
16327
+ }
16328
+ return {
16329
+ url: `/api/catalog/suggestions/course/user/?${params.toString()}`,
16330
+ service: SERVICES.DM,
16331
+ method: 'GET',
16332
+ };
16333
+ },
16334
+ providesTags: ['user-assigned-courses'],
16335
+ }),
16336
+ }),
16337
+ });
16338
+
16339
+ createApi({
16340
+ reducerPath: 'courseMetadataApiSlice',
16341
+ baseQuery: iblFetchBaseQuery,
16342
+ endpoints: (builder) => ({
16343
+ getCourseMetaData: builder.query({
16344
+ query: ({ courseKey }) => ({
16345
+ url: `/api/ibl/v1/course_metadata?course_key=${encodeURIComponent(courseKey)}`,
16346
+ service: SERVICES.LMS,
16347
+ method: 'GET',
16348
+ }),
16349
+ }),
16350
+ getCourseCompletionOutlines: builder.query({
16351
+ query: ({ courseKey }) => ({
16352
+ url: `/api/ibl/completion/course_outline/${courseKey}?course_id=${encodeURIComponent(courseKey)}`,
16353
+ service: SERVICES.LMS,
16354
+ method: 'GET',
16355
+ }),
16356
+ }),
16357
+ getCourseEligibility: builder.query({
16358
+ query: ({ courseKey }) => ({
16359
+ url: `/api/ibl/enrollment/enroll_status?course_id=${encodeURIComponent(courseKey)}`,
16360
+ service: SERVICES.LMS,
16361
+ method: 'GET',
16362
+ }),
16363
+ }),
16364
+ createCourseEnrollment: builder.mutation({
16365
+ query: (body) => ({
16366
+ url: `/api/enrollment/v1/enrollment`,
16367
+ service: SERVICES.LMS,
16368
+ method: 'POST',
16369
+ body,
16370
+ }),
16371
+ }),
16372
+ getCourseProgress: builder.query({
16373
+ query: ({ courseKey }) => ({
16374
+ url: `/api/course_home/progress/${courseKey}`,
16375
+ service: SERVICES.LMS,
16376
+ method: 'GET',
16377
+ }),
16378
+ }),
16379
+ getCourseCompletion: builder.query({
16380
+ query: ({ courseKey, userID }) => ({
16381
+ url: `/api/catalog/milestones/completions/course/manage/?course_id=${courseKey}&user_id=${userID}`,
16382
+ service: SERVICES.DM,
16383
+ method: 'GET',
16384
+ }),
16385
+ }),
16386
+ }),
16387
+ });
16388
+
16389
+ createApi({
16390
+ reducerPath: 'edxSsoApiSlice',
16391
+ baseQuery: iblFetchBaseQuery,
16392
+ endpoints: (builder) => ({
16393
+ getEdxSSOToken: builder.query({
16394
+ query: ({ username, redirectUrl }) => ({
16395
+ url: `/ibl/ai/sso/backend/edx/sso-auth-token/generate?username=${encodeURIComponent(username)}&redirect_url=${encodeURIComponent(redirectUrl)}`,
16396
+ service: SERVICES.LMS,
16397
+ method: 'GET',
16398
+ }),
16399
+ }),
16400
+ }),
16401
+ });
16402
+
16232
16403
  createApi({
16233
16404
  reducerPath: 'searchApiSlice',
16234
16405
  baseQuery: iblFakeBaseQuery,
@@ -16902,6 +17073,7 @@ const MEMORY_QUERY_KEYS = {
16902
17073
  MEMSEARCH_MENTOR_MEMORIES: () => ['MEMSEARCH_MENTOR_MEMORIES'],
16903
17074
  MEMSEARCH_MEMORY_CATEGORIES: () => ['MEMSEARCH_MEMORY_CATEGORIES'],
16904
17075
  MEMSEARCH_PLATFORM_CONFIG: () => ['MEMSEARCH_PLATFORM_CONFIG'],
17076
+ MEMSEARCH_STATUS: () => ['MEMSEARCH_STATUS'],
16905
17077
  };
16906
17078
  const MEMSEARCH_ENDPOINTS = {
16907
17079
  // User Memory Settings
@@ -16969,6 +17141,11 @@ const MEMSEARCH_ENDPOINTS = {
16969
17141
  service: SERVICES.AXD,
16970
17142
  path: (org, userId) => `/api/ai-mentor/orgs/${org}/users/${userId}/memsearch-config/`,
16971
17143
  },
17144
+ // Memsearch Status (available to students and admins)
17145
+ GET_MEMSEARCH_STATUS: {
17146
+ service: SERVICES.AXD,
17147
+ path: (org, userId) => `/api/ai-mentor/orgs/${org}/users/${userId}/memsearch-status/`,
17148
+ },
16972
17149
  };
16973
17150
 
16974
17151
  createApi({
@@ -16979,6 +17156,7 @@ createApi({
16979
17156
  ...MEMORY_QUERY_KEYS.MEMSEARCH_MENTOR_MEMORIES(),
16980
17157
  ...MEMORY_QUERY_KEYS.MEMSEARCH_MEMORY_CATEGORIES(),
16981
17158
  ...MEMORY_QUERY_KEYS.MEMSEARCH_PLATFORM_CONFIG(),
17159
+ ...MEMORY_QUERY_KEYS.MEMSEARCH_STATUS(),
16982
17160
  ],
16983
17161
  baseQuery: iblFetchBaseQuery,
16984
17162
  endpoints: (builder) => ({
@@ -17111,6 +17289,14 @@ createApi({
17111
17289
  }),
17112
17290
  invalidatesTags: MEMORY_QUERY_KEYS.MEMSEARCH_PLATFORM_CONFIG(),
17113
17291
  }),
17292
+ // Memsearch Status (student + admin accessible)
17293
+ getMemsearchStatus: builder.query({
17294
+ query: (args) => ({
17295
+ url: MEMSEARCH_ENDPOINTS.GET_MEMSEARCH_STATUS.path(args.org, args.userId),
17296
+ service: MEMSEARCH_ENDPOINTS.GET_MEMSEARCH_STATUS.service,
17297
+ }),
17298
+ providesTags: MEMORY_QUERY_KEYS.MEMSEARCH_STATUS(),
17299
+ }),
17114
17300
  }),
17115
17301
  });
17116
17302
 
@@ -18091,6 +18277,33 @@ createApi({
18091
18277
  }),
18092
18278
  });
18093
18279
 
18280
+ const AUDIT_LOGS_REDUCER_PATH = 'auditLogsApiSlice';
18281
+ const AUDIT_LOGS_QUERY_KEYS = {
18282
+ GET_AUDIT_LOGS: () => ['AUDIT_LOGS'],
18283
+ };
18284
+ const AUDIT_LOGS_ENDPOINTS = {
18285
+ GET_AUDIT_LOGS: {
18286
+ service: SERVICES.AXD,
18287
+ path: (org, userId) => `/api/ai-mentor/orgs/${org}/users/${userId}/mentors/audit-logs/`,
18288
+ },
18289
+ };
18290
+
18291
+ createApi({
18292
+ reducerPath: AUDIT_LOGS_REDUCER_PATH,
18293
+ tagTypes: [...AUDIT_LOGS_QUERY_KEYS.GET_AUDIT_LOGS()],
18294
+ baseQuery: iblFetchBaseQuery,
18295
+ endpoints: (builder) => ({
18296
+ getAuditLogs: builder.query({
18297
+ query: (args) => ({
18298
+ url: AUDIT_LOGS_ENDPOINTS.GET_AUDIT_LOGS.path(args.org, args.userId),
18299
+ service: AUDIT_LOGS_ENDPOINTS.GET_AUDIT_LOGS.service,
18300
+ params: args.params,
18301
+ }),
18302
+ providesTags: AUDIT_LOGS_QUERY_KEYS.GET_AUDIT_LOGS(),
18303
+ }),
18304
+ }),
18305
+ });
18306
+
18094
18307
  function useMentorSettings({ mentorId, tenantKey, username, isPublicRoute, }) {
18095
18308
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
18096
18309
  const isLoggedIn = username !== ANONYMOUS_USERNAME;
@@ -23334,6 +23547,7 @@ exports.MAX_INITIAL_WEBSOCKET_CONNECTION_ATTEMPTS = MAX_INITIAL_WEBSOCKET_CONNEC
23334
23547
  exports.MENTOR_CHAT_DOCUMENTS_EXTENSIONS = MENTOR_CHAT_DOCUMENTS_EXTENSIONS;
23335
23548
  exports.METADATAS = METADATAS;
23336
23549
  exports.MentorProvider = MentorProvider;
23550
+ exports.REQUIRED_ACTIONS_FOR_GROUPS = REQUIRED_ACTIONS_FOR_GROUPS;
23337
23551
  exports.STREAMING_CONTENT_BUFFER_THRESHOLD = STREAMING_CONTENT_BUFFER_THRESHOLD;
23338
23552
  exports.STREAMING_CONTENT_FLUSH_INTERVAL = STREAMING_CONTENT_FLUSH_INTERVAL;
23339
23553
  exports.SUBSCRIPTION_MESSAGES = SUBSCRIPTION_MESSAGES;