@iblai/data-layer 1.29.2 → 1.30.1

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
@@ -5978,6 +5978,15 @@ interface CustomQueryArgs extends Omit<FetchArgs, 'url'> {
5978
5978
  isJson?: boolean;
5979
5979
  contentType?: string;
5980
5980
  skipAuth?: boolean;
5981
+ /**
5982
+ * Statuses the caller needs to inspect (e.g. a 404 for a session the
5983
+ * caller no longer holds). Retries are unchanged; once they are exhausted
5984
+ * these are logged via `console.warn` and returned as `{ error }` instead
5985
+ * of thrown — RTK Query serializes a thrown error to `{}`, dropping
5986
+ * `status`. Defaults to `[]`, so existing endpoints behave exactly as
5987
+ * before.
5988
+ */
5989
+ returnErrorStatuses?: number[];
5981
5990
  }
5982
5991
  type ExtendedFetchBaseQueryError = FetchBaseQueryError & {
5983
5992
  data?: {
package/dist/index.esm.js CHANGED
@@ -39516,8 +39516,12 @@ const buildEndpointFromAxdService = (serviceFn, options) => buildEndpointFromSer
39516
39516
  * Build an endpoint from a hand-assembled URL (rather than a generated service
39517
39517
  * method), routed through `iblFetchBaseQuery`. Defaults to the DM service.
39518
39518
  */
39519
- const buildEndpointFromDmUrl = (buildUrl, service = SERVICES.DM) => ({
39520
- queryFn: async (args, api, extraOptions) => iblFetchBaseQuery({ url: buildUrl(args), service }, api, extraOptions),
39519
+ const buildEndpointFromDmUrl = (buildUrl, service = SERVICES.DM, options) => ({
39520
+ queryFn: async (args, api, extraOptions) => iblFetchBaseQuery({
39521
+ url: buildUrl(args),
39522
+ service,
39523
+ returnErrorStatuses: options === null || options === void 0 ? void 0 : options.returnErrorStatuses,
39524
+ }, api, extraOptions),
39521
39525
  });
39522
39526
  /**
39523
39527
  * Build an endpoint from a hand-assembled URL, taking its arguments in the
@@ -39581,7 +39585,6 @@ const baseQuery = (service, jsonContentType = true, contentType, skipAuth = fals
39581
39585
  */
39582
39586
  const invokeHttpErrorHandler = (status, error) => {
39583
39587
  const numericStatus = typeof status === 'number' ? status : parseInt(String(status), 10);
39584
- console.log('[MONETIZATION error] ', { error });
39585
39588
  if (!isNaN(numericStatus) &&
39586
39589
  Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, numericStatus)) {
39587
39590
  const err = error;
@@ -39629,7 +39632,7 @@ const withNonRetryableErrors = (query) => async (args, api, extraOptions) => {
39629
39632
  return result;
39630
39633
  };
39631
39634
  const iblFetchBaseQuery = async (args, api, extraOptions) => {
39632
- var _a, _b, _c;
39635
+ var _a, _b, _c, _d;
39633
39636
  try {
39634
39637
  const runQuery = () => {
39635
39638
  var _a;
@@ -39650,9 +39653,21 @@ const iblFetchBaseQuery = async (args, api, extraOptions) => {
39650
39653
  }
39651
39654
  // Query completed
39652
39655
  if (result.error) {
39653
- console.log('[MONETIZATION ERROR HANDLER]: ', { result });
39656
+ // A status the caller handles itself (e.g. a 404 for a session the
39657
+ // caller no longer holds): don't escalate to Sentry via console.error
39658
+ // and return `{ error }` instead of throwing, so the status reaches the
39659
+ // caller via RTK Query's normal `error` field.
39660
+ if ((_b = args.returnErrorStatuses) === null || _b === void 0 ? void 0 : _b.includes(result.error.status)) {
39661
+ console.warn('[data-layer] returning expected error:', `url=${args.url}, status=${result.error.status}`);
39662
+ return {
39663
+ error: {
39664
+ status: result.error.status,
39665
+ data: result.error.data,
39666
+ },
39667
+ };
39668
+ }
39654
39669
  // Invoke registered HTTP error handlers (e.g., logout on 401)
39655
- invokeHttpErrorHandler(result.error.status, (_b = result.error) === null || _b === void 0 ? void 0 : _b.data);
39670
+ invokeHttpErrorHandler(result.error.status, (_c = result.error) === null || _c === void 0 ? void 0 : _c.data);
39656
39671
  // For profile image upload errors, preserve the original error structure
39657
39672
  if (args.url && args.url.includes('/profile_images/')) {
39658
39673
  throw result.error;
@@ -39670,7 +39685,7 @@ const iblFetchBaseQuery = async (args, api, extraOptions) => {
39670
39685
  // Ensure we throw a plain FetchBaseQueryError shape with enumerable fields
39671
39686
  throw {
39672
39687
  status: result.error.status,
39673
- data: (_c = result.error.data) !== null && _c !== void 0 ? _c : errorMessage,
39688
+ data: (_d = result.error.data) !== null && _d !== void 0 ? _d : errorMessage,
39674
39689
  };
39675
39690
  }
39676
39691
  return { data: result === null || result === void 0 ? void 0 : result.data };
@@ -39903,7 +39918,7 @@ const RECENT_MESSAGES_LIMIT_PARAM = 'limit';
39903
39918
  const RECENT_MESSAGES_OFFSET_PARAM = 'offset';
39904
39919
  const CHAT_CUSTOM_ENDPOINTS = {
39905
39920
  GET_CHAT_MESSAGE_TTS: {
39906
- path: (org, user_id, chat_message_id) => `/api/ai-mentor/orgs/${org}/users/${user_id}/chat-messages/${chat_message_id}/tts`,
39921
+ path: (org, user_id, chat_message_id) => `/api/ai-mentor/orgs/${org}/users/${user_id}/chat-messages/${chat_message_id}/tts/`,
39907
39922
  service: SERVICES.DM,
39908
39923
  },
39909
39924
  };
@@ -42920,12 +42935,23 @@ const sessionApiSlice = createApi({
42920
42935
  invalidatesTags: ['sessionId'],
42921
42936
  }),
42922
42937
  getSessionId: builder.query({
42923
- ...buildEndpointFromDmUrl(buildSessionRetrieveUrl),
42924
- providesTags: ['sessionId'],
42938
+ // A 404 here means the caller holds a session id the backend no longer
42939
+ // recognizes (e.g. purged, or a stale localStorage cache). Return it as
42940
+ // `{ error }` so the chat can detect it and mint a fresh session.
42941
+ ...buildEndpointFromDmUrl(buildSessionRetrieveUrl, SERVICES.DM, {
42942
+ returnErrorStatuses: [404],
42943
+ }),
42944
+ // A 404 is now returned as `{ error }` rather than thrown (see above),
42945
+ // so RTK Query would otherwise still tag the errored cache entry and
42946
+ // `createSessionId`'s invalidation would refetch the dead id right
42947
+ // after the heal mints a new session. Only provide the tag on success.
42948
+ providesTags: (_result, error) => (error ? [] : ['sessionId']),
42925
42949
  }),
42926
42950
  getSharedSessionId: builder.query({
42927
- ...buildEndpointFromDmUrl(buildSharedSessionRetrieveUrl),
42928
- providesTags: ['sessionId'],
42951
+ ...buildEndpointFromDmUrl(buildSharedSessionRetrieveUrl, SERVICES.DM, {
42952
+ returnErrorStatuses: [404],
42953
+ }),
42954
+ providesTags: (_result, error) => (error ? [] : ['sessionId']),
42929
42955
  }),
42930
42956
  editSession: builder.mutation({
42931
42957
  ...buildEndpointFromDmService(AiMentorService.aiMentorOrgsUsersSessionsUpdate),