@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.esm.js CHANGED
@@ -5861,7 +5861,7 @@ const STREAMING_CONTENT_BUFFER_THRESHOLD = 300; // characters
5861
5861
  const STREAMING_CONTENT_FLUSH_INTERVAL = 300; // milliseconds
5862
5862
  const defaultSessionIds = Object.fromEntries(Object.keys(advancedTabsProperties).map((key) => [key, ""]));
5863
5863
  const defaultChatState = Object.fromEntries(Object.keys(advancedTabsProperties).map((key) => [key, []]));
5864
- const initialState$2 = {
5864
+ const initialState$3 = {
5865
5865
  chats: defaultChatState,
5866
5866
  isTyping: false,
5867
5867
  streaming: false,
@@ -5894,7 +5894,7 @@ const initialState$2 = {
5894
5894
  };
5895
5895
  const chatSlice = createSlice$1({
5896
5896
  name: "chatSliceShared",
5897
- initialState: initialState$2,
5897
+ initialState: initialState$3,
5898
5898
  reducers: {
5899
5899
  setChats: (state, action) => {
5900
5900
  state.chats = action.payload;
@@ -6558,12 +6558,12 @@ function useTimeTrackerNative(config) {
6558
6558
  };
6559
6559
  }
6560
6560
 
6561
- const initialState$1 = {
6561
+ const initialState$2 = {
6562
6562
  attachedFiles: [],
6563
6563
  };
6564
6564
  const filesSlice = createSlice$1({
6565
6565
  name: "files",
6566
- initialState: initialState$1,
6566
+ initialState: initialState$2,
6567
6567
  reducers: {
6568
6568
  addFiles: (state, action) => {
6569
6569
  state.attachedFiles = [...state.attachedFiles, ...action.payload];
@@ -6742,6 +6742,44 @@ function csvDataToText(data) {
6742
6742
  ].join("\n");
6743
6743
  }
6744
6744
 
6745
+ const initialState$1 = {
6746
+ displayMonetizationCheckoutModal: false,
6747
+ accessCheckResponse: null,
6748
+ paywallClosable: true,
6749
+ onClosePayload: undefined,
6750
+ };
6751
+ const monetizationSlice = createSlice$1({
6752
+ name: "monetization",
6753
+ initialState: initialState$1,
6754
+ reducers: {
6755
+ setDisplayMonetizationCheckoutModal(state, action) {
6756
+ state.displayMonetizationCheckoutModal = action.payload;
6757
+ if (!action.payload) {
6758
+ state.accessCheckResponse = null;
6759
+ }
6760
+ },
6761
+ setAccessCheckResponse(state, action) {
6762
+ state.accessCheckResponse = action.payload;
6763
+ },
6764
+ showMonetizationCheckoutModal(state, action) {
6765
+ var _a, _b, _c, _d, _e;
6766
+ state.displayMonetizationCheckoutModal =
6767
+ (_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.showModal) !== null && _b !== void 0 ? _b : true;
6768
+ state.accessCheckResponse = action.payload;
6769
+ state.paywallClosable = (_d = (_c = action.payload) === null || _c === void 0 ? void 0 : _c.paywallClosable) !== null && _d !== void 0 ? _d : true;
6770
+ state.onClosePayload = (_e = action.payload) === null || _e === void 0 ? void 0 : _e.onClosePayload;
6771
+ },
6772
+ setAdvancedDisplayMonetizationCheckoutModal(state, action) {
6773
+ var _a, _b, _c, _d, _e;
6774
+ state.displayMonetizationCheckoutModal =
6775
+ (_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.showModal) !== null && _b !== void 0 ? _b : true;
6776
+ state.paywallClosable = (_d = (_c = action.payload) === null || _c === void 0 ? void 0 : _c.paywallClosable) !== null && _d !== void 0 ? _d : true;
6777
+ state.onClosePayload = (_e = action.payload) === null || _e === void 0 ? void 0 : _e.onClosePayload;
6778
+ },
6779
+ },
6780
+ });
6781
+ const { setDisplayMonetizationCheckoutModal, setAccessCheckResponse, showMonetizationCheckoutModal, setAdvancedDisplayMonetizationCheckoutModal, } = monetizationSlice.actions;
6782
+
6745
6783
  /**
6746
6784
  * Ollama API client for local LLM chat
6747
6785
  *
@@ -13519,12 +13557,12 @@ const buildEndpointFromService = (service, serviceFn) => {
13519
13557
  }
13520
13558
  catch (err) {
13521
13559
  if (Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, err === null || err === void 0 ? void 0 : err.status)) {
13522
- Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]();
13560
+ Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]({ ...((err === null || err === void 0 ? void 0 : err.data) || {}) });
13523
13561
  }
13524
13562
  return {
13525
13563
  error: {
13526
13564
  status: (err === null || err === void 0 ? void 0 : err.status) || 500,
13527
- data: (err === null || err === void 0 ? void 0 : err.body) || (err === null || err === void 0 ? void 0 : err.message) || 'Unknown error',
13565
+ 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',
13528
13566
  },
13529
13567
  };
13530
13568
  }
@@ -13578,24 +13616,40 @@ const baseQuery = (service, jsonContentType = true, contentType, skipAuth = fals
13578
13616
  /**
13579
13617
  * Helper to invoke registered HTTP error handlers (e.g., logout on 401).
13580
13618
  */
13581
- const invokeHttpErrorHandler = (status) => {
13619
+ const invokeHttpErrorHandler = (status, error) => {
13582
13620
  const numericStatus = typeof status === 'number' ? status : parseInt(String(status), 10);
13621
+ console.log('[MONETIZATION error] ', { error });
13583
13622
  if (!isNaN(numericStatus) &&
13584
13623
  Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, numericStatus)) {
13585
- Config.httpErrorHandlers[numericStatus]();
13624
+ const err = error;
13625
+ Config.httpErrorHandlers[numericStatus]({ ...(err || {}) });
13586
13626
  }
13587
13627
  };
13628
+ /** HTTP status codes that should not be retried (e.g., 402 Payment Required). */
13629
+ const NON_RETRYABLE_STATUS_CODES = [402];
13630
+ /**
13631
+ * Wraps a base query to skip retries for non-retryable HTTP status codes.
13632
+ * Uses `retry.fail()` to immediately bail out of the retry loop.
13633
+ */
13634
+ const withNonRetryableErrors = (query) => async (args, api, extraOptions) => {
13635
+ const result = await query(args, api, extraOptions);
13636
+ if (result.error && NON_RETRYABLE_STATUS_CODES.includes(result.error.status)) {
13637
+ retry.fail(result.error);
13638
+ }
13639
+ return result;
13640
+ };
13588
13641
  const iblFetchBaseQuery = async (args, api, extraOptions) => {
13589
- var _a, _b;
13642
+ var _a, _b, _c;
13590
13643
  try {
13591
13644
  // Executing base query
13592
- 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), {
13645
+ 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)), {
13593
13646
  maxRetries: 3,
13594
13647
  })(args, api, extraOptions);
13595
13648
  // Query completed
13596
13649
  if (result.error) {
13650
+ console.log('[MONETIZATION ERROR HANDLER]: ', { result });
13597
13651
  // Invoke registered HTTP error handlers (e.g., logout on 401)
13598
- invokeHttpErrorHandler(result.error.status);
13652
+ invokeHttpErrorHandler(result.error.status, (_b = result.error) === null || _b === void 0 ? void 0 : _b.data);
13599
13653
  // For profile image upload errors, preserve the original error structure
13600
13654
  if (args.url && args.url.includes('/profile_images/')) {
13601
13655
  throw result.error;
@@ -13613,7 +13667,7 @@ const iblFetchBaseQuery = async (args, api, extraOptions) => {
13613
13667
  // Ensure we throw a plain FetchBaseQueryError shape with enumerable fields
13614
13668
  throw {
13615
13669
  status: result.error.status,
13616
- data: (_b = result.error.data) !== null && _b !== void 0 ? _b : errorMessage,
13670
+ data: (_c = result.error.data) !== null && _c !== void 0 ? _c : errorMessage,
13617
13671
  };
13618
13672
  }
13619
13673
  return { data: result === null || result === void 0 ? void 0 : result.data };
@@ -13627,10 +13681,12 @@ const iblFetchBaseQuery = async (args, api, extraOptions) => {
13627
13681
  error: e,
13628
13682
  }));
13629
13683
  // Extract status from error and invoke HTTP error handlers
13684
+ console.log('[MONETIZATION e]', { e });
13685
+ const err = e;
13630
13686
  const errorStatus = typeof e === 'object' && e !== null && 'status' in e
13631
13687
  ? e.status
13632
13688
  : undefined;
13633
- invokeHttpErrorHandler(errorStatus);
13689
+ invokeHttpErrorHandler(errorStatus, err === null || err === void 0 ? void 0 : err.data);
13634
13690
  // Preserve original RTK error object for profile image uploads
13635
13691
  if (args.url &&
13636
13692
  args.url.includes('/profile_images/') &&
@@ -13667,7 +13723,11 @@ const buildEndpointFromServiceLegacy = (service, serviceFn) => {
13667
13723
  }
13668
13724
  catch (err) {
13669
13725
  if (Object.prototype.hasOwnProperty.call(Config.httpErrorHandlers, err === null || err === void 0 ? void 0 : err.status)) {
13670
- Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]();
13726
+ Config.httpErrorHandlers[err === null || err === void 0 ? void 0 : err.status]({
13727
+ status: err === null || err === void 0 ? void 0 : err.status,
13728
+ body: err === null || err === void 0 ? void 0 : err.body,
13729
+ message: err === null || err === void 0 ? void 0 : err.message,
13730
+ });
13671
13731
  }
13672
13732
  return {
13673
13733
  error: {
@@ -15107,6 +15167,309 @@ createApi({
15107
15167
  }),
15108
15168
  });
15109
15169
 
15170
+ const MONETIZATION_REDUCER_PATH = 'monetizationApiSlice';
15171
+ const SERVICE_BASE = '/api/service/platforms';
15172
+ const BILLING_BASE = '/api/billing/platforms';
15173
+ const MONETIZATION_ENDPOINTS = {
15174
+ // Flow 1 — Stripe Connect Onboarding (Admin)
15175
+ STRIPE_CONNECT_STATUS: {
15176
+ path: (key) => `${SERVICE_BASE}/${key}/stripe/connect/status/`,
15177
+ service: SERVICES.DM,
15178
+ },
15179
+ STRIPE_CONNECT_ONBOARD: {
15180
+ path: (key) => `${SERVICE_BASE}/${key}/stripe/connect/onboard/`,
15181
+ service: SERVICES.DM,
15182
+ },
15183
+ STRIPE_CONNECT_DASHBOARD: {
15184
+ path: (key) => `${SERVICE_BASE}/${key}/stripe/connect/dashboard/`,
15185
+ service: SERVICES.DM,
15186
+ },
15187
+ // Flow 2 — Configure Paywall (Admin)
15188
+ PAYWALL_CONFIG: {
15189
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/paywall/`,
15190
+ service: SERVICES.DM,
15191
+ },
15192
+ // Flow 3 — Manage Prices (Admin)
15193
+ PAYWALL_PRICES: {
15194
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/paywall/prices/`,
15195
+ service: SERVICES.DM,
15196
+ },
15197
+ PAYWALL_PRICE_DETAIL: {
15198
+ path: (key, type, id, priceId) => `${BILLING_BASE}/${key}/items/${type}/${id}/paywall/prices/${priceId}/`,
15199
+ service: SERVICES.DM,
15200
+ },
15201
+ // Flow 4 — Public Pricing (No Auth)
15202
+ PUBLIC_PRICING: {
15203
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/pricing/`,
15204
+ service: SERVICES.DM,
15205
+ },
15206
+ // Flow 5 — Access Check
15207
+ ACCESS_CHECK: {
15208
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/access-check/`,
15209
+ service: SERVICES.DM,
15210
+ },
15211
+ ACCESS_CHECK_UNSCOPED: {
15212
+ path: (type, id) => `/api/billing/access-check/${type}/${id}/`,
15213
+ service: SERVICES.DM,
15214
+ },
15215
+ // Flow 6 — Checkout
15216
+ CHECKOUT: {
15217
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/checkout/`,
15218
+ service: SERVICES.DM,
15219
+ },
15220
+ CHECKOUT_GUEST: {
15221
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/checkout-guest/`,
15222
+ service: SERVICES.DM,
15223
+ },
15224
+ // Flow 7 — Cancel Subscription
15225
+ CANCEL_SUBSCRIPTION: {
15226
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/subscription/cancel/`,
15227
+ service: SERVICES.DM,
15228
+ },
15229
+ // Flow 8 — User Subscriptions
15230
+ MY_SUBSCRIPTIONS: {
15231
+ path: (key) => `${BILLING_BASE}/${key}/my-subscriptions/`,
15232
+ service: SERVICES.DM,
15233
+ },
15234
+ ITEM_SUBSCRIPTION: {
15235
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/subscription/`,
15236
+ service: SERVICES.DM,
15237
+ },
15238
+ // Flow 9 — Platform Analytics (Admin)
15239
+ LIST_PAYWALLS: {
15240
+ path: (key) => `${BILLING_BASE}/${key}/paywalls/`,
15241
+ service: SERVICES.DM,
15242
+ },
15243
+ LIST_SUBSCRIBERS: {
15244
+ path: (key) => `${BILLING_BASE}/${key}/subscribers/`,
15245
+ service: SERVICES.DM,
15246
+ },
15247
+ ITEM_SUBSCRIBERS: {
15248
+ path: (key, type, id) => `${BILLING_BASE}/${key}/items/${type}/${id}/subscribers/`,
15249
+ service: SERVICES.DM,
15250
+ },
15251
+ REVENUE: {
15252
+ path: (key) => `${BILLING_BASE}/${key}/revenue/`,
15253
+ service: SERVICES.DM,
15254
+ },
15255
+ };
15256
+
15257
+ createApi({
15258
+ reducerPath: MONETIZATION_REDUCER_PATH,
15259
+ baseQuery: iblFetchBaseQuery,
15260
+ tagTypes: [
15261
+ 'stripeConnectStatus',
15262
+ 'paywallConfig',
15263
+ 'paywallPrices',
15264
+ 'publicPricing',
15265
+ 'accessCheck',
15266
+ 'mySubscriptions',
15267
+ 'itemSubscription',
15268
+ 'paywalls',
15269
+ 'subscribers',
15270
+ 'revenue',
15271
+ ],
15272
+ endpoints: (builder) => ({
15273
+ // ── Flow 1: Stripe Connect ──
15274
+ getStripeConnectStatus: builder.query({
15275
+ query: ({ platform_key }) => ({
15276
+ url: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_STATUS.path(platform_key),
15277
+ service: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_STATUS.service,
15278
+ method: 'GET',
15279
+ }),
15280
+ providesTags: ['stripeConnectStatus'],
15281
+ }),
15282
+ startStripeConnectOnboarding: builder.mutation({
15283
+ query: ({ platform_key, ...body }) => ({
15284
+ url: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_ONBOARD.path(platform_key),
15285
+ service: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_ONBOARD.service,
15286
+ method: 'POST',
15287
+ body: JSON.stringify(body),
15288
+ }),
15289
+ invalidatesTags: ['stripeConnectStatus'],
15290
+ }),
15291
+ getStripeConnectDashboard: builder.query({
15292
+ query: ({ platform_key }) => ({
15293
+ url: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_DASHBOARD.path(platform_key),
15294
+ service: MONETIZATION_ENDPOINTS.STRIPE_CONNECT_DASHBOARD.service,
15295
+ method: 'GET',
15296
+ }),
15297
+ }),
15298
+ // ── Flow 2: Paywall Config ──
15299
+ getPaywallConfig: builder.query({
15300
+ query: ({ platform_key, item_type, item_id }) => ({
15301
+ url: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.path(platform_key, item_type, item_id),
15302
+ service: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.service,
15303
+ method: 'GET',
15304
+ }),
15305
+ providesTags: ['paywallConfig'],
15306
+ }),
15307
+ enablePaywall: builder.mutation({
15308
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15309
+ url: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.path(platform_key, item_type, item_id),
15310
+ service: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.service,
15311
+ method: 'POST',
15312
+ body: JSON.stringify(body),
15313
+ }),
15314
+ invalidatesTags: ['paywallConfig', 'paywalls'],
15315
+ }),
15316
+ disablePaywall: builder.mutation({
15317
+ query: ({ platform_key, item_type, item_id }) => ({
15318
+ url: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.path(platform_key, item_type, item_id),
15319
+ service: MONETIZATION_ENDPOINTS.PAYWALL_CONFIG.service,
15320
+ method: 'DELETE',
15321
+ }),
15322
+ invalidatesTags: ['paywallConfig', 'paywalls'],
15323
+ }),
15324
+ // ── Flow 3: Manage Prices ──
15325
+ listPrices: builder.query({
15326
+ query: ({ platform_key, item_type, item_id }) => ({
15327
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.path(platform_key, item_type, item_id),
15328
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.service,
15329
+ method: 'GET',
15330
+ }),
15331
+ providesTags: ['paywallPrices'],
15332
+ }),
15333
+ createPrice: builder.mutation({
15334
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15335
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.path(platform_key, item_type, item_id),
15336
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICES.service,
15337
+ method: 'POST',
15338
+ body: JSON.stringify(body),
15339
+ }),
15340
+ invalidatesTags: ['paywallPrices', 'paywallConfig'],
15341
+ }),
15342
+ updatePrice: builder.mutation({
15343
+ query: ({ platform_key, item_type, item_id, price_unique_id, ...body }) => ({
15344
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.path(platform_key, item_type, item_id, price_unique_id),
15345
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.service,
15346
+ method: 'PUT',
15347
+ body: JSON.stringify(body),
15348
+ }),
15349
+ invalidatesTags: ['paywallPrices', 'paywallConfig'],
15350
+ }),
15351
+ deletePrice: builder.mutation({
15352
+ query: ({ platform_key, item_type, item_id, price_unique_id }) => ({
15353
+ url: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.path(platform_key, item_type, item_id, price_unique_id),
15354
+ service: MONETIZATION_ENDPOINTS.PAYWALL_PRICE_DETAIL.service,
15355
+ method: 'DELETE',
15356
+ }),
15357
+ invalidatesTags: ['paywallPrices', 'paywallConfig'],
15358
+ }),
15359
+ // ── Flow 4: Public Pricing (No Auth) ──
15360
+ getPublicPricing: builder.query({
15361
+ query: ({ platform_key, item_type, item_id }) => ({
15362
+ url: MONETIZATION_ENDPOINTS.PUBLIC_PRICING.path(platform_key, item_type, item_id),
15363
+ service: MONETIZATION_ENDPOINTS.PUBLIC_PRICING.service,
15364
+ method: 'GET',
15365
+ skipAuth: true,
15366
+ }),
15367
+ providesTags: ['publicPricing'],
15368
+ }),
15369
+ // ── Flow 5: Access Check ──
15370
+ checkAccess: builder.query({
15371
+ query: ({ platform_key, item_type, item_id }) => ({
15372
+ url: MONETIZATION_ENDPOINTS.ACCESS_CHECK.path(platform_key, item_type, item_id),
15373
+ service: MONETIZATION_ENDPOINTS.ACCESS_CHECK.service,
15374
+ method: 'GET',
15375
+ }),
15376
+ providesTags: ['accessCheck'],
15377
+ }),
15378
+ checkAccessUnscoped: builder.query({
15379
+ query: ({ item_type, item_id, platform_key }) => ({
15380
+ url: MONETIZATION_ENDPOINTS.ACCESS_CHECK_UNSCOPED.path(item_type, item_id),
15381
+ service: MONETIZATION_ENDPOINTS.ACCESS_CHECK_UNSCOPED.service,
15382
+ method: 'GET',
15383
+ params: { platform_key },
15384
+ }),
15385
+ providesTags: ['accessCheck'],
15386
+ }),
15387
+ // ── Flow 6A/6B: Checkout (Subscription & One-Time) ──
15388
+ createCheckout: builder.mutation({
15389
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15390
+ url: MONETIZATION_ENDPOINTS.CHECKOUT.path(platform_key, item_type, item_id),
15391
+ service: MONETIZATION_ENDPOINTS.CHECKOUT.service,
15392
+ method: 'POST',
15393
+ body: JSON.stringify(body),
15394
+ }),
15395
+ }),
15396
+ // ── Flow 6C: Guest Checkout (No Auth) ──
15397
+ createGuestCheckout: builder.mutation({
15398
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15399
+ url: MONETIZATION_ENDPOINTS.CHECKOUT_GUEST.path(platform_key, item_type, item_id),
15400
+ service: MONETIZATION_ENDPOINTS.CHECKOUT_GUEST.service,
15401
+ method: 'POST',
15402
+ body: JSON.stringify(body),
15403
+ skipAuth: true,
15404
+ }),
15405
+ }),
15406
+ // ── Flow 7: Cancel Subscription ──
15407
+ cancelSubscription: builder.mutation({
15408
+ query: ({ platform_key, item_type, item_id, ...body }) => ({
15409
+ url: MONETIZATION_ENDPOINTS.CANCEL_SUBSCRIPTION.path(platform_key, item_type, item_id),
15410
+ service: MONETIZATION_ENDPOINTS.CANCEL_SUBSCRIPTION.service,
15411
+ method: 'POST',
15412
+ body: JSON.stringify(body),
15413
+ }),
15414
+ invalidatesTags: ['mySubscriptions', 'itemSubscription', 'accessCheck', 'subscribers'],
15415
+ }),
15416
+ // ── Flow 8: User Subscriptions ──
15417
+ getMySubscriptions: builder.query({
15418
+ query: ({ platform_key, ...params }) => ({
15419
+ url: MONETIZATION_ENDPOINTS.MY_SUBSCRIPTIONS.path(platform_key),
15420
+ service: MONETIZATION_ENDPOINTS.MY_SUBSCRIPTIONS.service,
15421
+ method: 'GET',
15422
+ params,
15423
+ }),
15424
+ providesTags: ['mySubscriptions'],
15425
+ }),
15426
+ getItemSubscription: builder.query({
15427
+ query: ({ platform_key, item_type, item_id }) => ({
15428
+ url: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIPTION.path(platform_key, item_type, item_id),
15429
+ service: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIPTION.service,
15430
+ method: 'GET',
15431
+ }),
15432
+ providesTags: ['itemSubscription'],
15433
+ }),
15434
+ // ── Flow 9: Platform Analytics (Admin) ──
15435
+ listPaywalls: builder.query({
15436
+ query: ({ platform_key, ...params }) => ({
15437
+ url: MONETIZATION_ENDPOINTS.LIST_PAYWALLS.path(platform_key),
15438
+ service: MONETIZATION_ENDPOINTS.LIST_PAYWALLS.service,
15439
+ method: 'GET',
15440
+ params,
15441
+ }),
15442
+ providesTags: ['paywalls'],
15443
+ }),
15444
+ listSubscribers: builder.query({
15445
+ query: ({ platform_key, ...params }) => ({
15446
+ url: MONETIZATION_ENDPOINTS.LIST_SUBSCRIBERS.path(platform_key),
15447
+ service: MONETIZATION_ENDPOINTS.LIST_SUBSCRIBERS.service,
15448
+ method: 'GET',
15449
+ params,
15450
+ }),
15451
+ providesTags: ['subscribers'],
15452
+ }),
15453
+ listItemSubscribers: builder.query({
15454
+ query: ({ platform_key, item_type, item_id, ...params }) => ({
15455
+ url: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIBERS.path(platform_key, item_type, item_id),
15456
+ service: MONETIZATION_ENDPOINTS.ITEM_SUBSCRIBERS.service,
15457
+ method: 'GET',
15458
+ params,
15459
+ }),
15460
+ providesTags: ['subscribers'],
15461
+ }),
15462
+ getRevenue: builder.query({
15463
+ query: ({ platform_key }) => ({
15464
+ url: MONETIZATION_ENDPOINTS.REVENUE.path(platform_key),
15465
+ service: MONETIZATION_ENDPOINTS.REVENUE.service,
15466
+ method: 'GET',
15467
+ }),
15468
+ providesTags: ['revenue'],
15469
+ }),
15470
+ }),
15471
+ });
15472
+
15110
15473
  const STRIPE_ENDPOINTS = {
15111
15474
  GET_STRIPE_CONTEXT: {
15112
15475
  service: SERVICES.DM,
@@ -17919,11 +18282,18 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
17919
18282
  onStartNewChat === null || onStartNewChat === void 0 ? void 0 : onStartNewChat(response.session_id);
17920
18283
  }
17921
18284
  catch (error) {
18285
+ console.log("[MONETIZATION] session error", { error });
17922
18286
  if (mentorSettings.mentorVisibility !==
17923
18287
  MentorVisibilityEnum.VIEWABLE_BY_ANYONE) {
17924
- errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(`Failed to start new chat: ${JSON.stringify(error)}`);
17925
- console.log("[auth-redirect] Failed to start new chat", JSON.stringify({ error }));
17926
- redirectToAuthSpa(undefined, undefined, true);
18288
+ //only logging out if error code isn't 402
18289
+ if ((error === null || error === void 0 ? void 0 : error.status) === 402) {
18290
+ on402Error === null || on402Error === void 0 ? void 0 : on402Error(error === null || error === void 0 ? void 0 : error.data);
18291
+ }
18292
+ else {
18293
+ errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(`Failed to start new chat: ${JSON.stringify(error)}`);
18294
+ console.log("[auth-redirect] Failed to start new chat", JSON.stringify({ error }));
18295
+ redirectToAuthSpa(undefined, undefined, true);
18296
+ }
17927
18297
  }
17928
18298
  }
17929
18299
  }, [
@@ -22898,5 +23268,5 @@ const checkRbacPermission = (rbacPermissions, rbacResource, enableRBAC = true) =
22898
23268
  return checkRbacPermissionInternal(rbacPermissions, rbacResource);
22899
23269
  };
22900
23270
 
22901
- export { ALPHANUMERIC_32_REGEX, ANONYMOUS_USERNAME, AuthContext, AuthContextProvider, AuthProvider, CHAT_AREA_SIZE, LOCAL_STORAGE_KEYS, MAX_INITIAL_WEBSOCKET_CONNECTION_ATTEMPTS, MENTOR_CHAT_DOCUMENTS_EXTENSIONS, METADATAS, MentorProvider, STREAMING_CONTENT_BUFFER_THRESHOLD, STREAMING_CONTENT_FLUSH_INTERVAL, SUBSCRIPTION_MESSAGES, SUBSCRIPTION_PACKAGES, SUBSCRIPTION_PACKAGES_V2, SUBSCRIPTION_TRIGGERS, SUBSCRIPTION_V2_TRIGGERS, SubscriptionFlow, SubscriptionFlowV2, TOOLS, TenantContext, TenantContextProvider, TenantProvider, TimeTracker, WithFormPermissions, WithPermissions, addFiles, addProtocolToUrl, advancedTabs, advancedTabsProperties, chatActions, chatSliceReducerShared, checkModelAvailable, checkOllamaHealth, checkRbacPermission, clearAuthCookies, clearCookies, clearCurrentTenantCookie, clearFiles, combineCSVData, convertToOllamaMessages, createFileReference, createMultipleFileReferences, csvDataToText, defaultSessionIds, deleteCookie, deleteCookieOnAllDomains, filesReducer, filesSlice, formatRelativeTime, getAuthSpaJoinUrl, getDomainParts, getFileInfo, getInitials, getLocalLLMSystemPrompt, getNextNavigation, getParentDomain, getPlatform, getPlatformKey, getTimeAgo, getUserName, handleLogout, isAlphaNumeric32, isExpo, isInIframe, isJSON, isLoggedIn, isNode, isReactNative$1 as isReactNative, isTauri, isWeb$2 as isWeb, loadMetadataConfig, markdownToPlainText, parseCSV, redirectToAuthSpa, redirectToAuthSpaJoinTenant, removeFile, requestPresignedUrl, safeRequire, selectActiveChatMessages, selectActiveTab, selectArtifactsEnabled, selectChats, selectCurrentStreamingArtifact, selectCurrentStreamingMessage, selectDocumentFilter, selectIframeContext, selectIsError, selectIsPending, selectIsStopped, selectIsTyping, selectLastArtifactContentFlushTime, selectNumberOfActiveChatMessages, selectSessionId, selectSessionIds, selectShouldStartNewChat, selectShowingSharedChat, selectStatus, selectStreaming, selectStreamingArtifactContentBuffer, selectStreamingArtifactFullContent, selectToken, selectTokenEnabled, selectTools, sendMessageToParentWebsite, setCookieForAuth, streamOllamaChat, syncAuthToCookies, tenantKeySchema, tenantSchema, translatePrompt, updateFileMetadata, updateFileProgress, updateFileRetryCount, updateFileStatus, updateFileUrl, updateFileUrlFromWebSocket, uploadToS3, useAdvancedChat, useAuthContext, useAuthProvider, useChat, useDayJs, useExternalPricingPlan, useMentorSettings, useMentorTools, useProfileImageUpload, useSubscriptionHandler, useSubscriptionHandlerV2, useTenantContext, useTenantMetadata, useTimeTracker, useTimeTrackerNative, useUserProfileUpdate, userDataSchema, validateFile };
23271
+ export { ALPHANUMERIC_32_REGEX, ANONYMOUS_USERNAME, AuthContext, AuthContextProvider, AuthProvider, CHAT_AREA_SIZE, LOCAL_STORAGE_KEYS, MAX_INITIAL_WEBSOCKET_CONNECTION_ATTEMPTS, MENTOR_CHAT_DOCUMENTS_EXTENSIONS, METADATAS, MentorProvider, STREAMING_CONTENT_BUFFER_THRESHOLD, STREAMING_CONTENT_FLUSH_INTERVAL, SUBSCRIPTION_MESSAGES, SUBSCRIPTION_PACKAGES, SUBSCRIPTION_PACKAGES_V2, SUBSCRIPTION_TRIGGERS, SUBSCRIPTION_V2_TRIGGERS, SubscriptionFlow, SubscriptionFlowV2, TOOLS, TenantContext, TenantContextProvider, TenantProvider, TimeTracker, WithFormPermissions, WithPermissions, addFiles, addProtocolToUrl, advancedTabs, advancedTabsProperties, chatActions, chatSliceReducerShared, checkModelAvailable, checkOllamaHealth, checkRbacPermission, clearAuthCookies, clearCookies, clearCurrentTenantCookie, clearFiles, combineCSVData, convertToOllamaMessages, createFileReference, createMultipleFileReferences, csvDataToText, defaultSessionIds, deleteCookie, deleteCookieOnAllDomains, filesReducer, filesSlice, formatRelativeTime, getAuthSpaJoinUrl, getDomainParts, getFileInfo, getInitials, getLocalLLMSystemPrompt, getNextNavigation, getParentDomain, getPlatform, getPlatformKey, getTimeAgo, getUserName, handleLogout, isAlphaNumeric32, isExpo, isInIframe, isJSON, isLoggedIn, isNode, isReactNative$1 as isReactNative, isTauri, isWeb$2 as isWeb, loadMetadataConfig, markdownToPlainText, monetizationSlice, parseCSV, redirectToAuthSpa, redirectToAuthSpaJoinTenant, removeFile, requestPresignedUrl, safeRequire, selectActiveChatMessages, selectActiveTab, selectArtifactsEnabled, selectChats, selectCurrentStreamingArtifact, selectCurrentStreamingMessage, selectDocumentFilter, selectIframeContext, selectIsError, selectIsPending, selectIsStopped, selectIsTyping, selectLastArtifactContentFlushTime, selectNumberOfActiveChatMessages, selectSessionId, selectSessionIds, selectShouldStartNewChat, selectShowingSharedChat, selectStatus, selectStreaming, selectStreamingArtifactContentBuffer, selectStreamingArtifactFullContent, selectToken, selectTokenEnabled, selectTools, sendMessageToParentWebsite, setAccessCheckResponse, setAdvancedDisplayMonetizationCheckoutModal, setCookieForAuth, setDisplayMonetizationCheckoutModal, showMonetizationCheckoutModal, streamOllamaChat, syncAuthToCookies, tenantKeySchema, tenantSchema, translatePrompt, updateFileMetadata, updateFileProgress, updateFileRetryCount, updateFileStatus, updateFileUrl, updateFileUrlFromWebSocket, uploadToS3, useAdvancedChat, useAuthContext, useAuthProvider, useChat, useDayJs, useExternalPricingPlan, useMentorSettings, useMentorTools, useProfileImageUpload, useSubscriptionHandler, useSubscriptionHandlerV2, useTenantContext, useTenantMetadata, useTimeTracker, useTimeTrackerNative, useUserProfileUpdate, userDataSchema, validateFile };
22902
23272
  //# sourceMappingURL=index.esm.js.map