@iblai/web-utils 1.2.5 → 1.2.6

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
@@ -5881,7 +5881,7 @@ const STREAMING_CONTENT_BUFFER_THRESHOLD = 300; // characters
5881
5881
  const STREAMING_CONTENT_FLUSH_INTERVAL = 300; // milliseconds
5882
5882
  const defaultSessionIds = Object.fromEntries(Object.keys(advancedTabsProperties).map((key) => [key, ""]));
5883
5883
  const defaultChatState = Object.fromEntries(Object.keys(advancedTabsProperties).map((key) => [key, []]));
5884
- const initialState$2 = {
5884
+ const initialState$3 = {
5885
5885
  chats: defaultChatState,
5886
5886
  isTyping: false,
5887
5887
  streaming: false,
@@ -5914,7 +5914,7 @@ const initialState$2 = {
5914
5914
  };
5915
5915
  const chatSlice = createSlice$1({
5916
5916
  name: "chatSliceShared",
5917
- initialState: initialState$2,
5917
+ initialState: initialState$3,
5918
5918
  reducers: {
5919
5919
  setChats: (state, action) => {
5920
5920
  state.chats = action.payload;
@@ -6578,12 +6578,12 @@ function useTimeTrackerNative(config) {
6578
6578
  };
6579
6579
  }
6580
6580
 
6581
- const initialState$1 = {
6581
+ const initialState$2 = {
6582
6582
  attachedFiles: [],
6583
6583
  };
6584
6584
  const filesSlice = createSlice$1({
6585
6585
  name: "files",
6586
- initialState: initialState$1,
6586
+ initialState: initialState$2,
6587
6587
  reducers: {
6588
6588
  addFiles: (state, action) => {
6589
6589
  state.attachedFiles = [...state.attachedFiles, ...action.payload];
@@ -6762,6 +6762,44 @@ function csvDataToText(data) {
6762
6762
  ].join("\n");
6763
6763
  }
6764
6764
 
6765
+ const initialState$1 = {
6766
+ displayMonetizationCheckoutModal: false,
6767
+ accessCheckResponse: null,
6768
+ paywallClosable: true,
6769
+ onClosePayload: undefined,
6770
+ };
6771
+ const monetizationSlice = createSlice$1({
6772
+ name: "monetization",
6773
+ initialState: initialState$1,
6774
+ reducers: {
6775
+ setDisplayMonetizationCheckoutModal(state, action) {
6776
+ state.displayMonetizationCheckoutModal = action.payload;
6777
+ if (!action.payload) {
6778
+ state.accessCheckResponse = null;
6779
+ }
6780
+ },
6781
+ setAccessCheckResponse(state, action) {
6782
+ state.accessCheckResponse = action.payload;
6783
+ },
6784
+ showMonetizationCheckoutModal(state, action) {
6785
+ var _a, _b, _c, _d, _e;
6786
+ state.displayMonetizationCheckoutModal =
6787
+ (_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.showModal) !== null && _b !== void 0 ? _b : true;
6788
+ state.accessCheckResponse = action.payload;
6789
+ state.paywallClosable = (_d = (_c = action.payload) === null || _c === void 0 ? void 0 : _c.paywallClosable) !== null && _d !== void 0 ? _d : true;
6790
+ state.onClosePayload = (_e = action.payload) === null || _e === void 0 ? void 0 : _e.onClosePayload;
6791
+ },
6792
+ setAdvancedDisplayMonetizationCheckoutModal(state, action) {
6793
+ var _a, _b, _c, _d, _e;
6794
+ state.displayMonetizationCheckoutModal =
6795
+ (_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.showModal) !== null && _b !== void 0 ? _b : true;
6796
+ state.paywallClosable = (_d = (_c = action.payload) === null || _c === void 0 ? void 0 : _c.paywallClosable) !== null && _d !== void 0 ? _d : true;
6797
+ state.onClosePayload = (_e = action.payload) === null || _e === void 0 ? void 0 : _e.onClosePayload;
6798
+ },
6799
+ },
6800
+ });
6801
+ const { setDisplayMonetizationCheckoutModal, setAccessCheckResponse, showMonetizationCheckoutModal, setAdvancedDisplayMonetizationCheckoutModal, } = monetizationSlice.actions;
6802
+
6765
6803
  /**
6766
6804
  * Ollama API client for local LLM chat
6767
6805
  *
@@ -13539,12 +13577,12 @@ const buildEndpointFromService = (service, serviceFn) => {
13539
13577
  }
13540
13578
  catch (err) {
13541
13579
  if (Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, err === null || err === void 0 ? void 0 : err.status)) {
13542
- Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]();
13580
+ Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]({ ...((err === null || err === void 0 ? void 0 : err.data) || {}) });
13543
13581
  }
13544
13582
  return {
13545
13583
  error: {
13546
13584
  status: (err === null || err === void 0 ? void 0 : err.status) || 500,
13547
- data: (err === null || err === void 0 ? void 0 : err.body) || (err === null || err === void 0 ? void 0 : err.message) || 'Unknown error',
13585
+ data: (err === null || err === void 0 ? void 0 : err.body) || (err === null || err === void 0 ? void 0 : err.data) || (err === null || err === void 0 ? void 0 : err.message) || 'Unknown error',
13548
13586
  },
13549
13587
  };
13550
13588
  }
@@ -13598,24 +13636,40 @@ const baseQuery = (service, jsonContentType = true, contentType, skipAuth = fals
13598
13636
  /**
13599
13637
  * Helper to invoke registered HTTP error handlers (e.g., logout on 401).
13600
13638
  */
13601
- const invokeHttpErrorHandler = (status) => {
13639
+ const invokeHttpErrorHandler = (status, error) => {
13602
13640
  const numericStatus = typeof status === 'number' ? status : parseInt(String(status), 10);
13641
+ console.log('[MONETIZATION error] ', { error });
13603
13642
  if (!isNaN(numericStatus) &&
13604
13643
  Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, numericStatus)) {
13605
- Config.httpErrorHandlers[numericStatus]();
13644
+ const err = error;
13645
+ Config.httpErrorHandlers[numericStatus]({ ...(err || {}) });
13606
13646
  }
13607
13647
  };
13648
+ /** HTTP status codes that should not be retried (e.g., 402 Payment Required). */
13649
+ const NON_RETRYABLE_STATUS_CODES = [402];
13650
+ /**
13651
+ * Wraps a base query to skip retries for non-retryable HTTP status codes.
13652
+ * Uses `retry.fail()` to immediately bail out of the retry loop.
13653
+ */
13654
+ const withNonRetryableErrors = (query) => async (args, api, extraOptions) => {
13655
+ const result = await query(args, api, extraOptions);
13656
+ if (result.error && NON_RETRYABLE_STATUS_CODES.includes(result.error.status)) {
13657
+ retry.fail(result.error);
13658
+ }
13659
+ return result;
13660
+ };
13608
13661
  const iblFetchBaseQuery = async (args, api, extraOptions) => {
13609
- var _a, _b;
13662
+ var _a, _b, _c;
13610
13663
  try {
13611
13664
  // Executing base query
13612
- const result = await retry(baseQuery(args.service, (_a = args === null || args === void 0 ? void 0 : args.isJson) !== null && _a !== void 0 ? _a : true, args === null || args === void 0 ? void 0 : args.contentType, args === null || args === void 0 ? void 0 : args.skipAuth), {
13665
+ const result = await retry(withNonRetryableErrors(baseQuery(args.service, (_a = args === null || args === void 0 ? void 0 : args.isJson) !== null && _a !== void 0 ? _a : true, args === null || args === void 0 ? void 0 : args.contentType, args === null || args === void 0 ? void 0 : args.skipAuth)), {
13613
13666
  maxRetries: 3,
13614
13667
  })(args, api, extraOptions);
13615
13668
  // Query completed
13616
13669
  if (result.error) {
13670
+ console.log('[MONETIZATION ERROR HANDLER]: ', { result });
13617
13671
  // Invoke registered HTTP error handlers (e.g., logout on 401)
13618
- invokeHttpErrorHandler(result.error.status);
13672
+ invokeHttpErrorHandler(result.error.status, (_b = result.error) === null || _b === void 0 ? void 0 : _b.data);
13619
13673
  // For profile image upload errors, preserve the original error structure
13620
13674
  if (args.url && args.url.includes('/profile_images/')) {
13621
13675
  throw result.error;
@@ -13633,7 +13687,7 @@ const iblFetchBaseQuery = async (args, api, extraOptions) => {
13633
13687
  // Ensure we throw a plain FetchBaseQueryError shape with enumerable fields
13634
13688
  throw {
13635
13689
  status: result.error.status,
13636
- data: (_b = result.error.data) !== null && _b !== void 0 ? _b : errorMessage,
13690
+ data: (_c = result.error.data) !== null && _c !== void 0 ? _c : errorMessage,
13637
13691
  };
13638
13692
  }
13639
13693
  return { data: result === null || result === void 0 ? void 0 : result.data };
@@ -13647,10 +13701,12 @@ const iblFetchBaseQuery = async (args, api, extraOptions) => {
13647
13701
  error: e,
13648
13702
  }));
13649
13703
  // Extract status from error and invoke HTTP error handlers
13704
+ console.log('[MONETIZATION e]', { e });
13705
+ const err = e;
13650
13706
  const errorStatus = typeof e === 'object' && e !== null && 'status' in e
13651
13707
  ? e.status
13652
13708
  : undefined;
13653
- invokeHttpErrorHandler(errorStatus);
13709
+ invokeHttpErrorHandler(errorStatus, err === null || err === void 0 ? void 0 : err.data);
13654
13710
  // Preserve original RTK error object for profile image uploads
13655
13711
  if (args.url &&
13656
13712
  args.url.includes('/profile_images/') &&
@@ -13687,7 +13743,11 @@ const buildEndpointFromServiceLegacy = (service, serviceFn) => {
13687
13743
  }
13688
13744
  catch (err) {
13689
13745
  if (Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, err === null || err === void 0 ? void 0 : err.status)) {
13690
- Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]();
13746
+ Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]({
13747
+ status: err === null || err === void 0 ? void 0 : err.status,
13748
+ body: err === null || err === void 0 ? void 0 : err.body,
13749
+ message: err === null || err === void 0 ? void 0 : err.message,
13750
+ });
13691
13751
  }
13692
13752
  return {
13693
13753
  error: {
@@ -15127,6 +15187,309 @@ createApi({
15127
15187
  }),
15128
15188
  });
15129
15189
 
15190
+ const MONETIZATION_REDUCER_PATH = 'monetizationApiSlice';
15191
+ const SERVICE_BASE = '/api/service/platforms';
15192
+ const BILLING_BASE = '/api/billing/platforms';
15193
+ const MONETIZATION_ENDPOINTS = {
15194
+ // Flow 1 — Stripe Connect Onboarding (Admin)
15195
+ STRIPE_CONNECT_STATUS: {
15196
+ path: (key) => `${SERVICE_BASE}/${key}/stripe/connect/status/`,
15197
+ service: SERVICES.DM,
15198
+ },
15199
+ STRIPE_CONNECT_ONBOARD: {
15200
+ path: (key) => `${SERVICE_BASE}/${key}/stripe/connect/onboard/`,
15201
+ service: SERVICES.DM,
15202
+ },
15203
+ STRIPE_CONNECT_DASHBOARD: {
15204
+ path: (key) => `${SERVICE_BASE}/${key}/stripe/connect/dashboard/`,
15205
+ service: SERVICES.DM,
15206
+ },
15207
+ // Flow 2 — Configure Paywall (Admin)
15208
+ PAYWALL_CONFIG: {
15209
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/paywall/`,
15210
+ service: SERVICES.DM,
15211
+ },
15212
+ // Flow 3 — Manage Prices (Admin)
15213
+ PAYWALL_PRICES: {
15214
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/paywall/prices/`,
15215
+ service: SERVICES.DM,
15216
+ },
15217
+ PAYWALL_PRICE_DETAIL: {
15218
+ path: (key, type, id, priceId) => `${BILLING_BASE}/${key}/items/${type}/${id}/paywall/prices/${priceId}/`,
15219
+ service: SERVICES.DM,
15220
+ },
15221
+ // Flow 4 — Public Pricing (No Auth)
15222
+ PUBLIC_PRICING: {
15223
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/pricing/`,
15224
+ service: SERVICES.DM,
15225
+ },
15226
+ // Flow 5 — Access Check
15227
+ ACCESS_CHECK: {
15228
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/access-check/`,
15229
+ service: SERVICES.DM,
15230
+ },
15231
+ ACCESS_CHECK_UNSCOPED: {
15232
+ path: (type, id) => `/api/billing/access-check/${type}/${id}/`,
15233
+ service: SERVICES.DM,
15234
+ },
15235
+ // Flow 6 — Checkout
15236
+ CHECKOUT: {
15237
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/checkout/`,
15238
+ service: SERVICES.DM,
15239
+ },
15240
+ CHECKOUT_GUEST: {
15241
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/checkout-guest/`,
15242
+ service: SERVICES.DM,
15243
+ },
15244
+ // Flow 7 — Cancel Subscription
15245
+ CANCEL_SUBSCRIPTION: {
15246
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/subscription/cancel/`,
15247
+ service: SERVICES.DM,
15248
+ },
15249
+ // Flow 8 — User Subscriptions
15250
+ MY_SUBSCRIPTIONS: {
15251
+ path: (key) => `${BILLING_BASE}/${key}/my-subscriptions/`,
15252
+ service: SERVICES.DM,
15253
+ },
15254
+ ITEM_SUBSCRIPTION: {
15255
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/subscription/`,
15256
+ service: SERVICES.DM,
15257
+ },
15258
+ // Flow 9 — Platform Analytics (Admin)
15259
+ LIST_PAYWALLS: {
15260
+ path: (key) => `${BILLING_BASE}/${key}/paywalls/`,
15261
+ service: SERVICES.DM,
15262
+ },
15263
+ LIST_SUBSCRIBERS: {
15264
+ path: (key) => `${BILLING_BASE}/${key}/subscribers/`,
15265
+ service: SERVICES.DM,
15266
+ },
15267
+ ITEM_SUBSCRIBERS: {
15268
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/subscribers/`,
15269
+ service: SERVICES.DM,
15270
+ },
15271
+ REVENUE: {
15272
+ path: (key) => `${BILLING_BASE}/${key}/revenue/`,
15273
+ service: SERVICES.DM,
15274
+ },
15275
+ };
15276
+
15277
+ createApi({
15278
+ reducerPath: MONETIZATION_REDUCER_PATH,
15279
+ baseQuery: iblFetchBaseQuery,
15280
+ tagTypes: [
15281
+ 'stripeConnectStatus',
15282
+ 'paywallConfig',
15283
+ 'paywallPrices',
15284
+ 'publicPricing',
15285
+ 'accessCheck',
15286
+ 'mySubscriptions',
15287
+ 'itemSubscription',
15288
+ 'paywalls',
15289
+ 'subscribers',
15290
+ 'revenue',
15291
+ ],
15292
+ endpoints: (builder) => ({
15293
+ // ── Flow 1: Stripe Connect ──
15294
+ getStripeConnectStatus: builder.query({
15295
+ query: ({ platform_key }) => ({
15296
+ url: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_STATUS.path(platform_key),
15297
+ service: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_STATUS.service,
15298
+ method: 'GET',
15299
+ }),
15300
+ providesTags: ['stripeConnectStatus'],
15301
+ }),
15302
+ startStripeConnectOnboarding: builder.mutation({
15303
+ query: ({ platform_key, ...body }) => ({
15304
+ url: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_ONBOARD.path(platform_key),
15305
+ service: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_ONBOARD.service,
15306
+ method: 'POST',
15307
+ body: JSON.stringify(body),
15308
+ }),
15309
+ invalidatesTags: ['stripeConnectStatus'],
15310
+ }),
15311
+ getStripeConnectDashboard: builder.query({
15312
+ query: ({ platform_key }) => ({
15313
+ url: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_DASHBOARD.path(platform_key),
15314
+ service: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_DASHBOARD.service,
15315
+ method: 'GET',
15316
+ }),
15317
+ }),
15318
+ // ── Flow 2: Paywall Config ──
15319
+ getPaywallConfig: builder.query({
15320
+ query: ({ platform_key, item_type, item_id }) => ({
15321
+ url: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.path(platform_key, item_type, item_id),
15322
+ service: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.service,
15323
+ method: 'GET',
15324
+ }),
15325
+ providesTags: ['paywallConfig'],
15326
+ }),
15327
+ enablePaywall: builder.mutation({
15328
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15329
+ url: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.path(platform_key, item_type, item_id),
15330
+ service: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.service,
15331
+ method: 'POST',
15332
+ body: JSON.stringify(body),
15333
+ }),
15334
+ invalidatesTags: ['paywallConfig', 'paywalls'],
15335
+ }),
15336
+ disablePaywall: builder.mutation({
15337
+ query: ({ platform_key, item_type, item_id }) => ({
15338
+ url: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.path(platform_key, item_type, item_id),
15339
+ service: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.service,
15340
+ method: 'DELETE',
15341
+ }),
15342
+ invalidatesTags: ['paywallConfig', 'paywalls'],
15343
+ }),
15344
+ // ── Flow 3: Manage Prices ──
15345
+ listPrices: builder.query({
15346
+ query: ({ platform_key, item_type, item_id }) => ({
15347
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.path(platform_key, item_type, item_id),
15348
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.service,
15349
+ method: 'GET',
15350
+ }),
15351
+ providesTags: ['paywallPrices'],
15352
+ }),
15353
+ createPrice: builder.mutation({
15354
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15355
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.path(platform_key, item_type, item_id),
15356
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.service,
15357
+ method: 'POST',
15358
+ body: JSON.stringify(body),
15359
+ }),
15360
+ invalidatesTags: ['paywallPrices', 'paywallConfig'],
15361
+ }),
15362
+ updatePrice: builder.mutation({
15363
+ query: ({ platform_key, item_type, item_id, price_unique_id, ...body }) => ({
15364
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.path(platform_key, item_type, item_id, price_unique_id),
15365
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.service,
15366
+ method: 'PUT',
15367
+ body: JSON.stringify(body),
15368
+ }),
15369
+ invalidatesTags: ['paywallPrices', 'paywallConfig'],
15370
+ }),
15371
+ deletePrice: builder.mutation({
15372
+ query: ({ platform_key, item_type, item_id, price_unique_id }) => ({
15373
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.path(platform_key, item_type, item_id, price_unique_id),
15374
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.service,
15375
+ method: 'DELETE',
15376
+ }),
15377
+ invalidatesTags: ['paywallPrices', 'paywallConfig'],
15378
+ }),
15379
+ // ── Flow 4: Public Pricing (No Auth) ──
15380
+ getPublicPricing: builder.query({
15381
+ query: ({ platform_key, item_type, item_id }) => ({
15382
+ url: MONETIZATION_ENDPOINTS.PUBLIC_PRICING.path(platform_key, item_type, item_id),
15383
+ service: MONETIZATION_ENDPOINTS.PUBLIC_PRICING.service,
15384
+ method: 'GET',
15385
+ skipAuth: true,
15386
+ }),
15387
+ providesTags: ['publicPricing'],
15388
+ }),
15389
+ // ── Flow 5: Access Check ──
15390
+ checkAccess: builder.query({
15391
+ query: ({ platform_key, item_type, item_id }) => ({
15392
+ url: MONETIZATION_ENDPOINTS.ACCESS_CHECK.path(platform_key, item_type, item_id),
15393
+ service: MONETIZATION_ENDPOINTS.ACCESS_CHECK.service,
15394
+ method: 'GET',
15395
+ }),
15396
+ providesTags: ['accessCheck'],
15397
+ }),
15398
+ checkAccessUnscoped: builder.query({
15399
+ query: ({ item_type, item_id, platform_key }) => ({
15400
+ url: MONETIZATION_ENDPOINTS.ACCESS_CHECK_UNSCOPED.path(item_type, item_id),
15401
+ service: MONETIZATION_ENDPOINTS.ACCESS_CHECK_UNSCOPED.service,
15402
+ method: 'GET',
15403
+ params: { platform_key },
15404
+ }),
15405
+ providesTags: ['accessCheck'],
15406
+ }),
15407
+ // ── Flow 6A/6B: Checkout (Subscription & One-Time) ──
15408
+ createCheckout: builder.mutation({
15409
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15410
+ url: MONETIZATION_ENDPOINTS.CHECKOUT.path(platform_key, item_type, item_id),
15411
+ service: MONETIZATION_ENDPOINTS.CHECKOUT.service,
15412
+ method: 'POST',
15413
+ body: JSON.stringify(body),
15414
+ }),
15415
+ }),
15416
+ // ── Flow 6C: Guest Checkout (No Auth) ──
15417
+ createGuestCheckout: builder.mutation({
15418
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15419
+ url: MONETIZATION_ENDPOINTS.CHECKOUT_GUEST.path(platform_key, item_type, item_id),
15420
+ service: MONETIZATION_ENDPOINTS.CHECKOUT_GUEST.service,
15421
+ method: 'POST',
15422
+ body: JSON.stringify(body),
15423
+ skipAuth: true,
15424
+ }),
15425
+ }),
15426
+ // ── Flow 7: Cancel Subscription ──
15427
+ cancelSubscription: builder.mutation({
15428
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15429
+ url: MONETIZATION_ENDPOINTS.CANCEL_SUBSCRIPTION.path(platform_key, item_type, item_id),
15430
+ service: MONETIZATION_ENDPOINTS.CANCEL_SUBSCRIPTION.service,
15431
+ method: 'POST',
15432
+ body: JSON.stringify(body),
15433
+ }),
15434
+ invalidatesTags: ['mySubscriptions', 'itemSubscription', 'accessCheck', 'subscribers'],
15435
+ }),
15436
+ // ── Flow 8: User Subscriptions ──
15437
+ getMySubscriptions: builder.query({
15438
+ query: ({ platform_key, ...params }) => ({
15439
+ url: MONETIZATION_ENDPOINTS.MY_SUBSCRIPTIONS.path(platform_key),
15440
+ service: MONETIZATION_ENDPOINTS.MY_SUBSCRIPTIONS.service,
15441
+ method: 'GET',
15442
+ params,
15443
+ }),
15444
+ providesTags: ['mySubscriptions'],
15445
+ }),
15446
+ getItemSubscription: builder.query({
15447
+ query: ({ platform_key, item_type, item_id }) => ({
15448
+ url: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIPTION.path(platform_key, item_type, item_id),
15449
+ service: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIPTION.service,
15450
+ method: 'GET',
15451
+ }),
15452
+ providesTags: ['itemSubscription'],
15453
+ }),
15454
+ // ── Flow 9: Platform Analytics (Admin) ──
15455
+ listPaywalls: builder.query({
15456
+ query: ({ platform_key, ...params }) => ({
15457
+ url: MONETIZATION_ENDPOINTS.LIST_PAYWALLS.path(platform_key),
15458
+ service: MONETIZATION_ENDPOINTS.LIST_PAYWALLS.service,
15459
+ method: 'GET',
15460
+ params,
15461
+ }),
15462
+ providesTags: ['paywalls'],
15463
+ }),
15464
+ listSubscribers: builder.query({
15465
+ query: ({ platform_key, ...params }) => ({
15466
+ url: MONETIZATION_ENDPOINTS.LIST_SUBSCRIBERS.path(platform_key),
15467
+ service: MONETIZATION_ENDPOINTS.LIST_SUBSCRIBERS.service,
15468
+ method: 'GET',
15469
+ params,
15470
+ }),
15471
+ providesTags: ['subscribers'],
15472
+ }),
15473
+ listItemSubscribers: builder.query({
15474
+ query: ({ platform_key, item_type, item_id, ...params }) => ({
15475
+ url: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIBERS.path(platform_key, item_type, item_id),
15476
+ service: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIBERS.service,
15477
+ method: 'GET',
15478
+ params,
15479
+ }),
15480
+ providesTags: ['subscribers'],
15481
+ }),
15482
+ getRevenue: builder.query({
15483
+ query: ({ platform_key }) => ({
15484
+ url: MONETIZATION_ENDPOINTS.REVENUE.path(platform_key),
15485
+ service: MONETIZATION_ENDPOINTS.REVENUE.service,
15486
+ method: 'GET',
15487
+ }),
15488
+ providesTags: ['revenue'],
15489
+ }),
15490
+ }),
15491
+ });
15492
+
15130
15493
  const STRIPE_ENDPOINTS = {
15131
15494
  GET_STRIPE_CONTEXT: {
15132
15495
  service: SERVICES.DM,
@@ -17939,11 +18302,18 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
17939
18302
  onStartNewChat === null || onStartNewChat === void 0 ? void 0 : onStartNewChat(response.session_id);
17940
18303
  }
17941
18304
  catch (error) {
18305
+ console.log("[MONETIZATION] session error", { error });
17942
18306
  if (mentorSettings.mentorVisibility !==
17943
18307
  iblaiApi.MentorVisibilityEnum.VIEWABLE_BY_ANYONE) {
17944
- errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(`Failed to start new chat: ${JSON.stringify(error)}`);
17945
- console.log("[auth-redirect] Failed to start new chat", JSON.stringify({ error }));
17946
- redirectToAuthSpa(undefined, undefined, true);
18308
+ //only logging out if error code isn't 402
18309
+ if ((error === null || error === void 0 ? void 0 : error.status) === 402) {
18310
+ on402Error === null || on402Error === void 0 ? void 0 : on402Error(error === null || error === void 0 ? void 0 : error.data);
18311
+ }
18312
+ else {
18313
+ errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(`Failed to start new chat: ${JSON.stringify(error)}`);
18314
+ console.log("[auth-redirect] Failed to start new chat", JSON.stringify({ error }));
18315
+ redirectToAuthSpa(undefined, undefined, true);
18316
+ }
17947
18317
  }
17948
18318
  }
17949
18319
  }, [
@@ -22992,6 +23362,7 @@ exports.isTauri = isTauri;
22992
23362
  exports.isWeb = isWeb$2;
22993
23363
  exports.loadMetadataConfig = loadMetadataConfig;
22994
23364
  exports.markdownToPlainText = markdownToPlainText;
23365
+ exports.monetizationSlice = monetizationSlice;
22995
23366
  exports.parseCSV = parseCSV;
22996
23367
  exports.redirectToAuthSpa = redirectToAuthSpa;
22997
23368
  exports.redirectToAuthSpaJoinTenant = redirectToAuthSpaJoinTenant;
@@ -23024,7 +23395,11 @@ exports.selectToken = selectToken;
23024
23395
  exports.selectTokenEnabled = selectTokenEnabled;
23025
23396
  exports.selectTools = selectTools;
23026
23397
  exports.sendMessageToParentWebsite = sendMessageToParentWebsite;
23398
+ exports.setAccessCheckResponse = setAccessCheckResponse;
23399
+ exports.setAdvancedDisplayMonetizationCheckoutModal = setAdvancedDisplayMonetizationCheckoutModal;
23027
23400
  exports.setCookieForAuth = setCookieForAuth;
23401
+ exports.setDisplayMonetizationCheckoutModal = setDisplayMonetizationCheckoutModal;
23402
+ exports.showMonetizationCheckoutModal = showMonetizationCheckoutModal;
23028
23403
  exports.streamOllamaChat = streamOllamaChat;
23029
23404
  exports.syncAuthToCookies = syncAuthToCookies;
23030
23405
  exports.tenantKeySchema = tenantKeySchema;