@iblai/iblai-js 2.71.1 → 2.73.0

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.
Files changed (119) hide show
  1. package/dist/data-layer/playwright/billing-tab-helpers.d.ts +61 -48
  2. package/dist/data-layer/playwright/credit-balance-helpers.d.ts +40 -18
  3. package/dist/data-layer/playwright/index.d.ts +3 -2
  4. package/dist/data-layer/playwright/plan-picker-helpers.d.ts +26 -0
  5. package/dist/data-layer/playwright/spend-limits-helpers.d.ts +5 -4
  6. package/dist/playwright/index.cjs +306 -193
  7. package/dist/playwright/index.cjs.map +1 -1
  8. package/dist/playwright/index.d.ts +133 -71
  9. package/dist/playwright/index.esm.js +293 -194
  10. package/dist/playwright/index.esm.js.map +1 -1
  11. package/dist/playwright/playwright/billing-tab-helpers.d.ts +61 -48
  12. package/dist/playwright/playwright/credit-balance-helpers.d.ts +40 -18
  13. package/dist/playwright/playwright/index.d.ts +3 -2
  14. package/dist/playwright/playwright/plan-picker-helpers.d.ts +26 -0
  15. package/dist/playwright/playwright/spend-limits-helpers.d.ts +5 -4
  16. package/dist/security/playwright/billing-tab-helpers.d.ts +61 -48
  17. package/dist/security/playwright/credit-balance-helpers.d.ts +40 -18
  18. package/dist/security/playwright/index.d.ts +3 -2
  19. package/dist/security/playwright/plan-picker-helpers.d.ts +26 -0
  20. package/dist/security/playwright/spend-limits-helpers.d.ts +5 -4
  21. package/dist/web-containers/playwright/billing-tab-helpers.d.ts +61 -48
  22. package/dist/web-containers/playwright/credit-balance-helpers.d.ts +40 -18
  23. package/dist/web-containers/playwright/index.d.ts +3 -2
  24. package/dist/web-containers/playwright/plan-picker-helpers.d.ts +26 -0
  25. package/dist/web-containers/playwright/spend-limits-helpers.d.ts +5 -4
  26. package/dist/web-containers/source/add-credits-modal.js +170 -24
  27. package/dist/web-containers/source/add-credits-modal.js.map +1 -1
  28. package/dist/web-containers/source/auto-recharge-modal.js +1 -1
  29. package/dist/web-containers/source/auto-recharge-modal.js.map +1 -1
  30. package/dist/web-containers/source/billing-credits.js +4 -4
  31. package/dist/web-containers/source/billing-credits.js.map +1 -1
  32. package/dist/web-containers/source/billing.js +60 -101
  33. package/dist/web-containers/source/billing.js.map +1 -1
  34. package/dist/web-containers/source/components/credit-balance.js +44 -72
  35. package/dist/web-containers/source/components/credit-balance.js.map +1 -1
  36. package/dist/web-containers/source/components/modals/contact-admin-modal.js +32 -0
  37. package/dist/web-containers/source/components/modals/contact-admin-modal.js.map +1 -0
  38. package/dist/web-containers/source/components/modals/upgrade-package-modal.js +281 -20
  39. package/dist/web-containers/source/components/modals/upgrade-package-modal.js.map +1 -1
  40. package/dist/web-containers/source/components/profile/add-credits-modal.js +170 -24
  41. package/dist/web-containers/source/components/profile/add-credits-modal.js.map +1 -1
  42. package/dist/web-containers/source/components/profile/auto-recharge-modal.js +1 -1
  43. package/dist/web-containers/source/components/profile/auto-recharge-modal.js.map +1 -1
  44. package/dist/web-containers/source/components/profile/billing-credits.js +4 -4
  45. package/dist/web-containers/source/components/profile/billing-credits.js.map +1 -1
  46. package/dist/web-containers/source/components/profile/billing.js +60 -101
  47. package/dist/web-containers/source/components/profile/billing.js.map +1 -1
  48. package/dist/web-containers/source/components/profile/pending-credit-top-up.js +202 -0
  49. package/dist/web-containers/source/components/profile/pending-credit-top-up.js.map +1 -0
  50. package/dist/web-containers/source/components/profile/use-complete-pending-credit-top-up.js +68 -0
  51. package/dist/web-containers/source/components/profile/use-complete-pending-credit-top-up.js.map +1 -0
  52. package/dist/web-containers/source/components/subscription-top-banner.js +119 -0
  53. package/dist/web-containers/source/components/subscription-top-banner.js.map +1 -0
  54. package/dist/web-containers/source/components/welcome-chat/welcome-message.js +23 -3
  55. package/dist/web-containers/source/components/welcome-chat/welcome-message.js.map +1 -1
  56. package/dist/web-containers/source/contact-admin-modal.js +32 -0
  57. package/dist/web-containers/source/contact-admin-modal.js.map +1 -0
  58. package/dist/web-containers/source/credit-balance.js +44 -72
  59. package/dist/web-containers/source/credit-balance.js.map +1 -1
  60. package/dist/web-containers/source/en.json.js +125 -21
  61. package/dist/web-containers/source/en.json.js.map +1 -1
  62. package/dist/web-containers/source/es.json.js +127 -23
  63. package/dist/web-containers/source/es.json.js.map +1 -1
  64. package/dist/web-containers/source/fr.json.js +125 -21
  65. package/dist/web-containers/source/fr.json.js.map +1 -1
  66. package/dist/web-containers/source/i18n/messages/en.json.js +125 -21
  67. package/dist/web-containers/source/i18n/messages/en.json.js.map +1 -1
  68. package/dist/web-containers/source/i18n/messages/es.json.js +127 -23
  69. package/dist/web-containers/source/i18n/messages/es.json.js.map +1 -1
  70. package/dist/web-containers/source/i18n/messages/fr.json.js +125 -21
  71. package/dist/web-containers/source/i18n/messages/fr.json.js.map +1 -1
  72. package/dist/web-containers/source/i18n/messages/zh.json.js +126 -22
  73. package/dist/web-containers/source/i18n/messages/zh.json.js.map +1 -1
  74. package/dist/web-containers/source/messages/en.json.js +125 -21
  75. package/dist/web-containers/source/messages/en.json.js.map +1 -1
  76. package/dist/web-containers/source/messages/es.json.js +127 -23
  77. package/dist/web-containers/source/messages/es.json.js.map +1 -1
  78. package/dist/web-containers/source/messages/fr.json.js +125 -21
  79. package/dist/web-containers/source/messages/fr.json.js.map +1 -1
  80. package/dist/web-containers/source/messages/zh.json.js +126 -22
  81. package/dist/web-containers/source/messages/zh.json.js.map +1 -1
  82. package/dist/web-containers/source/modals/contact-admin-modal.js +32 -0
  83. package/dist/web-containers/source/modals/contact-admin-modal.js.map +1 -0
  84. package/dist/web-containers/source/modals/upgrade-package-modal.js +281 -20
  85. package/dist/web-containers/source/modals/upgrade-package-modal.js.map +1 -1
  86. package/dist/web-containers/source/pending-credit-top-up.js +202 -0
  87. package/dist/web-containers/source/pending-credit-top-up.js.map +1 -0
  88. package/dist/web-containers/source/profile/add-credits-modal.js +170 -24
  89. package/dist/web-containers/source/profile/add-credits-modal.js.map +1 -1
  90. package/dist/web-containers/source/profile/auto-recharge-modal.js +1 -1
  91. package/dist/web-containers/source/profile/auto-recharge-modal.js.map +1 -1
  92. package/dist/web-containers/source/profile/billing-credits.js +4 -4
  93. package/dist/web-containers/source/profile/billing-credits.js.map +1 -1
  94. package/dist/web-containers/source/profile/billing.js +60 -101
  95. package/dist/web-containers/source/profile/billing.js.map +1 -1
  96. package/dist/web-containers/source/profile/pending-credit-top-up.js +202 -0
  97. package/dist/web-containers/source/profile/pending-credit-top-up.js.map +1 -0
  98. package/dist/web-containers/source/profile/use-complete-pending-credit-top-up.js +68 -0
  99. package/dist/web-containers/source/profile/use-complete-pending-credit-top-up.js.map +1 -0
  100. package/dist/web-containers/source/subscription-top-banner.js +119 -0
  101. package/dist/web-containers/source/subscription-top-banner.js.map +1 -0
  102. package/dist/web-containers/source/tsconfig.build.tsbuildinfo +1 -1
  103. package/dist/web-containers/source/upgrade-package-modal.js +281 -20
  104. package/dist/web-containers/source/upgrade-package-modal.js.map +1 -1
  105. package/dist/web-containers/source/use-complete-pending-credit-top-up.js +68 -0
  106. package/dist/web-containers/source/use-complete-pending-credit-top-up.js.map +1 -0
  107. package/dist/web-containers/source/web-containers/tsconfig.build.tsbuildinfo +1 -1
  108. package/dist/web-containers/source/welcome-chat/welcome-message.js +23 -3
  109. package/dist/web-containers/source/welcome-chat/welcome-message.js.map +1 -1
  110. package/dist/web-containers/source/welcome-message.js +23 -3
  111. package/dist/web-containers/source/welcome-message.js.map +1 -1
  112. package/dist/web-containers/source/zh.json.js +126 -22
  113. package/dist/web-containers/source/zh.json.js.map +1 -1
  114. package/dist/web-utils/playwright/billing-tab-helpers.d.ts +61 -48
  115. package/dist/web-utils/playwright/credit-balance-helpers.d.ts +40 -18
  116. package/dist/web-utils/playwright/index.d.ts +3 -2
  117. package/dist/web-utils/playwright/plan-picker-helpers.d.ts +26 -0
  118. package/dist/web-utils/playwright/spend-limits-helpers.d.ts +5 -4
  119. package/package.json +5 -5
@@ -0,0 +1,202 @@
1
+ /**
2
+ * A credit top-up that has to wait for a payment method.
3
+ *
4
+ * Someone without a card on file still just presses "Add Credits" and types an
5
+ * amount. We then send them to the Stripe customer portal to save a card, and
6
+ * when Stripe brings them back we charge that amount and add the credits —
7
+ * one trip instead of "add a card, come back, open Add Credits again".
8
+ *
9
+ * The amount travels on the portal's after-completion URL so the return page
10
+ * knows what was asked for, but the URL alone never charges anything: the
11
+ * amount is also written to localStorage under a one-time nonce before the
12
+ * redirect, and the charge only runs when the URL's nonce, amount and tenant
13
+ * all match that record and it is still fresh. The record is deleted the
14
+ * moment it is claimed, so a reload (or a second mounted surface) can't charge
15
+ * twice, and a crafted link can't charge an amount the person never entered.
16
+ *
17
+ * localStorage (not sessionStorage) because the Stripe portal is a full
18
+ * navigation and some hosts open it in a new tab.
19
+ */
20
+ const PENDING_CREDIT_TOP_UP_STORAGE_KEY = 'ibl_pending_credit_top_up';
21
+ /** Query params appended to the portal's after-completion URL. */
22
+ const CREDIT_TOP_UP_QUERY_PARAMS = {
23
+ nonce: 'credit_topup',
24
+ amount: 'credit_topup_amount',
25
+ };
26
+ /** A top-up that is not claimed within the hour is forgotten. */
27
+ const PENDING_CREDIT_TOP_UP_TTL_MS = 60 * 60 * 1000;
28
+ function getStorage() {
29
+ try {
30
+ if (typeof window === 'undefined' || !window.localStorage)
31
+ return null;
32
+ return window.localStorage;
33
+ }
34
+ catch (_a) {
35
+ return null;
36
+ }
37
+ }
38
+ function createNonce() {
39
+ const cryptoApi = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
40
+ if (cryptoApi && typeof cryptoApi.randomUUID === 'function') {
41
+ return cryptoApi.randomUUID();
42
+ }
43
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
44
+ }
45
+ /** Normalises any accepted amount input to the "25.00" form stored and sent. */
46
+ function normaliseTopUpAmountUsd(amount) {
47
+ const num = typeof amount === 'string' ? parseFloat(amount) : amount;
48
+ if (!Number.isFinite(num) || num <= 0)
49
+ return null;
50
+ return num.toFixed(2);
51
+ }
52
+ /** The pending record, if one is stored, well-formed and not expired. */
53
+ function readPendingCreditTopUp(now = Date.now()) {
54
+ const storage = getStorage();
55
+ if (!storage)
56
+ return null;
57
+ const raw = storage.getItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
58
+ if (!raw)
59
+ return null;
60
+ try {
61
+ const parsed = JSON.parse(raw);
62
+ if (!parsed ||
63
+ typeof parsed.nonce !== 'string' ||
64
+ typeof parsed.amountUsd !== 'string' ||
65
+ typeof parsed.tenant !== 'string' ||
66
+ typeof parsed.createdAt !== 'number') {
67
+ storage.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
68
+ return null;
69
+ }
70
+ if (now - parsed.createdAt > PENDING_CREDIT_TOP_UP_TTL_MS) {
71
+ storage.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
72
+ return null;
73
+ }
74
+ return parsed;
75
+ }
76
+ catch (_a) {
77
+ storage.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
78
+ return null;
79
+ }
80
+ }
81
+ function clearPendingCreditTopUp() {
82
+ var _a;
83
+ (_a = getStorage()) === null || _a === void 0 ? void 0 : _a.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
84
+ }
85
+ /**
86
+ * Records the top-up to finish after the payment method is saved and returns
87
+ * the URL Stripe should send the person back to: `currentUrl` plus the amount
88
+ * and the one-time nonce. Any existing query (e.g. `profileTab=billing`) is
89
+ * kept so the person lands where they left.
90
+ */
91
+ function beginPendingCreditTopUp({ tenant, amountUsd, currentUrl, now = Date.now(), }) {
92
+ var _a;
93
+ const pending = {
94
+ nonce: createNonce(),
95
+ amountUsd,
96
+ tenant,
97
+ createdAt: now,
98
+ };
99
+ (_a = getStorage()) === null || _a === void 0 ? void 0 : _a.setItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY, JSON.stringify(pending));
100
+ const url = new URL(currentUrl);
101
+ url.searchParams.set(CREDIT_TOP_UP_QUERY_PARAMS.nonce, pending.nonce);
102
+ url.searchParams.set(CREDIT_TOP_UP_QUERY_PARAMS.amount, pending.amountUsd);
103
+ return { pending, afterCompletionUrl: url.toString() };
104
+ }
105
+ /** True when the URL carries the top-up return params at all. */
106
+ function hasPendingCreditTopUpParams(url) {
107
+ try {
108
+ return new URL(url).searchParams.has(CREDIT_TOP_UP_QUERY_PARAMS.nonce);
109
+ }
110
+ catch (_a) {
111
+ return false;
112
+ }
113
+ }
114
+ /** The same URL without the top-up return params (for `history.replaceState`). */
115
+ function stripPendingCreditTopUpParams(url) {
116
+ try {
117
+ const parsed = new URL(url);
118
+ parsed.searchParams.delete(CREDIT_TOP_UP_QUERY_PARAMS.nonce);
119
+ parsed.searchParams.delete(CREDIT_TOP_UP_QUERY_PARAMS.amount);
120
+ return parsed.toString();
121
+ }
122
+ catch (_a) {
123
+ return url;
124
+ }
125
+ }
126
+ /**
127
+ * Claims the top-up the URL refers to: returns it, and deletes the stored
128
+ * record, only when the URL's nonce and amount match the record for this
129
+ * tenant. Returns null (and leaves nothing to claim) otherwise.
130
+ */
131
+ function claimPendingCreditTopUp({ url, tenant, now = Date.now(), }) {
132
+ let params;
133
+ try {
134
+ params = new URL(url).searchParams;
135
+ }
136
+ catch (_a) {
137
+ return null;
138
+ }
139
+ const nonce = params.get(CREDIT_TOP_UP_QUERY_PARAMS.nonce);
140
+ const amount = params.get(CREDIT_TOP_UP_QUERY_PARAMS.amount);
141
+ if (!nonce || !amount)
142
+ return null;
143
+ const pending = readPendingCreditTopUp(now);
144
+ if (!pending)
145
+ return null;
146
+ if (pending.nonce !== nonce || pending.tenant !== tenant)
147
+ return null;
148
+ if (normaliseTopUpAmountUsd(amount) !== pending.amountUsd)
149
+ return null;
150
+ clearPendingCreditTopUp();
151
+ return pending;
152
+ }
153
+ /**
154
+ * The backend's plain-sentence refusal from a rejected top-up call, whatever
155
+ * shape the data layer threw it in (`{ data: { detail } }`, `{ data: 'text' }`
156
+ * or a bare `{ detail }`). Undefined when there is none.
157
+ */
158
+ function readTopUpErrorDetail(error) {
159
+ if (!error || typeof error !== 'object')
160
+ return undefined;
161
+ const err = error;
162
+ if (typeof err.data === 'string' && err.data.trim())
163
+ return err.data;
164
+ if (err.data && typeof err.data === 'object') {
165
+ const detail = err.data.detail;
166
+ if (typeof detail === 'string' && detail.trim())
167
+ return detail;
168
+ }
169
+ if (typeof err.detail === 'string' && err.detail.trim())
170
+ return err.detail;
171
+ return undefined;
172
+ }
173
+ function readStringField(body, key) {
174
+ if (!body || typeof body !== 'object')
175
+ return undefined;
176
+ const value = body[key];
177
+ return typeof value === 'string' && value.trim() ? value : undefined;
178
+ }
179
+ function readTopUpError(error) {
180
+ if (!error || typeof error !== 'object')
181
+ return {};
182
+ const err = error;
183
+ const body = err.data && typeof err.data === 'object' ? err.data : error;
184
+ return {
185
+ detail: readTopUpErrorDetail(error),
186
+ code: readStringField(body, 'code'),
187
+ errorType: readStringField(body, 'error_type'),
188
+ };
189
+ }
190
+ /** Refusals that saving a (new) card on Stripe fixes. */
191
+ const PAYMENT_METHOD_ERROR_TYPES = new Set(['card_error', 'payment_method_error']);
192
+ /**
193
+ * True when the backend refused the top-up because of the payment method:
194
+ * the card on file was refused (expired, declined, …) or there is none.
195
+ */
196
+ function isPaymentMethodProblem(error) {
197
+ const { errorType } = readTopUpError(error);
198
+ return errorType !== undefined && PAYMENT_METHOD_ERROR_TYPES.has(errorType);
199
+ }
200
+
201
+ export { CREDIT_TOP_UP_QUERY_PARAMS, PENDING_CREDIT_TOP_UP_STORAGE_KEY, PENDING_CREDIT_TOP_UP_TTL_MS, beginPendingCreditTopUp, claimPendingCreditTopUp, clearPendingCreditTopUp, hasPendingCreditTopUpParams, isPaymentMethodProblem, normaliseTopUpAmountUsd, readPendingCreditTopUp, readTopUpError, readTopUpErrorDetail, stripPendingCreditTopUpParams };
202
+ //# sourceMappingURL=pending-credit-top-up.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-credit-top-up.js","sources":["../../../../../../../src/components/profile/pending-credit-top-up.ts"],"sourcesContent":[null],"names":[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MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC;IAC3C,OAAO,SAAS,KAAK,SAAS,IAAI,0BAA0B,CAAC,GAAG,CAAC,SAAS,CAAC;AAC7E;;;;"}
@@ -0,0 +1,68 @@
1
+ import { useState, useRef, useEffect } from 'react';
2
+ import { useTriggerAutoRechargeMutation } from '@iblai/data-layer';
3
+ import { toast } from 'sonner';
4
+ import { useT } from '../../i18n/context.js';
5
+ import '../../packages/i18n/dist/index.esm.js';
6
+ import { hasPendingCreditTopUpParams, claimPendingCreditTopUp, stripPendingCreditTopUpParams, readTopUpErrorDetail } from './pending-credit-top-up.js';
7
+
8
+ function formatUsd(amount) {
9
+ const num = parseFloat(amount);
10
+ return Number.isFinite(num) ? `$${num.toFixed(2)}` : `$${amount}`;
11
+ }
12
+ /**
13
+ * Finishes a credit top-up that was waiting for a payment method (see
14
+ * `pending-credit-top-up.ts`). Mount it on every surface that offers
15
+ * "Add Credits" — the Billing tab and the navbar credit dropdown — so whichever
16
+ * one is on the page Stripe returns to charges the saved card for the amount
17
+ * the person entered, adds the credits, and says so in a toast. The billing
18
+ * query is invalidated by the mutation, so the balance on screen updates too.
19
+ *
20
+ * Claiming deletes the stored record first, so with both surfaces mounted only
21
+ * the first effect to run charges; the other finds nothing. The return params
22
+ * are removed from the address bar either way so a reload can't replay them.
23
+ */
24
+ function useCompletePendingCreditTopUp({ tenant, enabled = true, }) {
25
+ const t = useT();
26
+ const [triggerAutoRecharge] = useTriggerAutoRechargeMutation();
27
+ const [isCompleting, setIsCompleting] = useState(false);
28
+ const startedRef = useRef(false);
29
+ useEffect(() => {
30
+ if (!enabled || !tenant || startedRef.current)
31
+ return;
32
+ if (typeof window === 'undefined')
33
+ return;
34
+ const currentUrl = window.location.href;
35
+ if (!hasPendingCreditTopUpParams(currentUrl))
36
+ return;
37
+ startedRef.current = true;
38
+ const pending = claimPendingCreditTopUp({ url: currentUrl, tenant });
39
+ // A null state lets Next's patched replaceState sync the app router (and
40
+ // useSearchParams) with the new URL. Handing window.history.state back
41
+ // carries Next's internal marker, which makes it skip that sync, and a
42
+ // later router.replace built from the stale params would put the nonce
43
+ // and amount back in the address bar.
44
+ window.history.replaceState(null, '', stripPendingCreditTopUpParams(currentUrl));
45
+ if (!pending)
46
+ return;
47
+ setIsCompleting(true);
48
+ const toastId = toast.loading(t('profileAddCreditsModal.addingCredits'));
49
+ triggerAutoRecharge({ amount_usd: pending.amountUsd, platform_key: tenant })
50
+ .unwrap()
51
+ .then(() => {
52
+ toast.success(t('profileAddCreditsModal.creditsAddedAfterPayment', {
53
+ amount: formatUsd(pending.amountUsd),
54
+ }), { id: toastId });
55
+ })
56
+ .catch((error) => {
57
+ var _a;
58
+ toast.error((_a = readTopUpErrorDetail(error)) !== null && _a !== void 0 ? _a : t('profileAddCreditsModal.failedToAddCreditsAfterPayment'), { id: toastId });
59
+ })
60
+ .finally(() => setIsCompleting(false));
61
+ // The claim is one-shot by design (startedRef): re-runs from a changed
62
+ // dependency find nothing left to do.
63
+ }, [enabled, tenant, t, triggerAutoRecharge]);
64
+ return { isCompleting };
65
+ }
66
+
67
+ export { useCompletePendingCreditTopUp };
68
+ //# sourceMappingURL=use-complete-pending-credit-top-up.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-complete-pending-credit-top-up.js","sources":["../../../../../../../src/components/profile/use-complete-pending-credit-top-up.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAaA,SAAS,SAAS,CAAC,MAAc,EAAA;AAC/B,IAAA,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;IAC9B,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAA,CAAA,EAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA,CAAE,GAAG,CAAA,CAAA,EAAI,MAAM,CAAA,CAAE;AACnE;AAEA;;;;;;;;;;;AAWG;AACG,SAAU,6BAA6B,CAAC,EAC5C,MAAM,EACN,OAAO,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AC;AACA,aAAA,KAAK,CAAC,CAAC,KAAc,KAAI;;YACxB,KAAK,CAAC,KAAK,CACT,CAAA,EAAA,GAAA,oBAAoB,CAAC,KAAK,CAAC,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,CAAC,CAAC,uDAAuD,CAAC,EACzF,EAAE,EAAE,EAAE,OAAO,EAAE,CAChB;AACH,QAAA,CAAC;aACA,OAAO,CAAC,MAAM,eAAe,CAAC,KAAK,CAAC,CAAC;;;IAG1C,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC;IAE7C,OAAO,EAAE,YAAY,EAAE;AACzB;;;;"}
@@ -0,0 +1,119 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useState, useEffect } from 'react';
3
+ import { useSelector } from 'react-redux';
4
+ import { useIsStripeActivated, useTopBannerButtonHandler, isLoggedIn, SUBSCRIPTION_BANNER_PARENT_SELECTOR } from '@iblai/web-utils';
5
+ import { useT } from '../i18n/context.js';
6
+ import '../packages/i18n/dist/index.esm.js';
7
+ import { TopBanner } from './top-banner/index.js';
8
+
9
+ const byId = (selector) => document.querySelector(selector);
10
+ /**
11
+ * The credits banner across the top of the app ("You've run out of credits…"),
12
+ * driven by the `topBanner` slice the subscription flow writes to. A non-admin
13
+ * whose organization ran out gets `ContactAdminModal` instead. Its button does what
14
+ * `useTopBannerButtonHandler` maps the banner's trigger to. Shows only for a
15
+ * signed-in person on a tenant with billing on.
16
+ *
17
+ * While shown it shortens the sidebar shell (`[data-slot="sidebar-*"]`) and
18
+ * the main content container by its own height so nothing scrolls under it,
19
+ * and puts everything back when closed.
20
+ */
21
+ function SubscriptionTopBanner({ hidden = false, parentContainerSelector = SUBSCRIPTION_BANNER_PARENT_SELECTOR, }) {
22
+ const t = useT();
23
+ const stripeActivated = useIsStripeActivated();
24
+ const topBannerOptions = useSelector((state) => { var _a; return (_a = state.topBanner) === null || _a === void 0 ? void 0 : _a.topBannerOptions; });
25
+ const getTopBannerButtonHandler = useTopBannerButtonHandler();
26
+ const [initialStyles, setInitialStyles] = useState({});
27
+ useEffect(() => {
28
+ const sideBarWrapper = byId('[data-slot="sidebar-wrapper"]');
29
+ const mainContentContainer = byId('#main-content-container > div');
30
+ const sidebarContainer = byId('[data-slot="sidebar-container"]');
31
+ const sidebarInset = byId('[data-slot="sidebar-inset"]');
32
+ const body = byId('body');
33
+ setInitialStyles({
34
+ sideBarWrapper: sideBarWrapper
35
+ ? {
36
+ maxHeight: sideBarWrapper.style.maxHeight,
37
+ top: sideBarWrapper.style.top,
38
+ position: sideBarWrapper.style.position,
39
+ }
40
+ : undefined,
41
+ mainContentContainer: mainContentContainer
42
+ ? {
43
+ position: mainContentContainer.style.position,
44
+ top: mainContentContainer.style.top,
45
+ }
46
+ : undefined,
47
+ sidebarContainer: sidebarContainer
48
+ ? { top: sidebarContainer.style.top, height: sidebarContainer.style.height }
49
+ : undefined,
50
+ sidebarInset: sidebarInset
51
+ ? { top: sidebarInset.style.top, height: sidebarInset.style.height }
52
+ : undefined,
53
+ body: body ? { overflow: body.style.overflow } : undefined,
54
+ });
55
+ }, []);
56
+ const handleTopBannerLoad = (bannerRef) => {
57
+ if (!bannerRef)
58
+ return;
59
+ const bannerHeight = bannerRef.clientHeight;
60
+ const sideBarWrapper = byId('[data-slot="sidebar-wrapper"]');
61
+ if (sideBarWrapper) {
62
+ sideBarWrapper.style.maxHeight = `calc(100vh - ${bannerHeight}px)`;
63
+ sideBarWrapper.style.top = '3px';
64
+ sideBarWrapper.style.position = 'relative';
65
+ }
66
+ const mainContentContainer = byId('#main-content-container > div');
67
+ if (mainContentContainer) {
68
+ mainContentContainer.style.position = 'relative';
69
+ mainContentContainer.style.top = '-12px';
70
+ }
71
+ const sidebarContainer = byId('[data-slot="sidebar-container"]');
72
+ if (sidebarContainer) {
73
+ sidebarContainer.style.top = '48px';
74
+ sidebarContainer.style.height = `calc(100% - ${bannerHeight}px)`;
75
+ }
76
+ const sidebarInset = byId('[data-slot="sidebar-inset"]');
77
+ if (sidebarInset) {
78
+ sidebarInset.style.height = `calc(100dvh - ${bannerHeight}px)`;
79
+ }
80
+ const body = byId('body');
81
+ if (body) {
82
+ body.style.overflow = 'hidden';
83
+ }
84
+ };
85
+ const handleTopBannerClose = () => {
86
+ var _a;
87
+ const sideBarWrapper = byId('[data-slot="sidebar-wrapper"]');
88
+ if (sideBarWrapper && initialStyles.sideBarWrapper) {
89
+ sideBarWrapper.style.maxHeight = initialStyles.sideBarWrapper.maxHeight;
90
+ sideBarWrapper.style.top = initialStyles.sideBarWrapper.top;
91
+ sideBarWrapper.style.position = initialStyles.sideBarWrapper.position;
92
+ }
93
+ const mainContentContainer = byId('#main-content-container > div');
94
+ if (mainContentContainer && initialStyles.mainContentContainer) {
95
+ mainContentContainer.style.position = initialStyles.mainContentContainer.position;
96
+ mainContentContainer.style.top = initialStyles.mainContentContainer.top;
97
+ }
98
+ const sidebarContainer = byId('[data-slot="sidebar-container"]');
99
+ if (sidebarContainer && initialStyles.sidebarContainer) {
100
+ sidebarContainer.style.top = initialStyles.sidebarContainer.top;
101
+ sidebarContainer.style.height = initialStyles.sidebarContainer.height;
102
+ }
103
+ const sidebarInset = byId('[data-slot="sidebar-inset"]');
104
+ if (sidebarInset && initialStyles.sidebarInset) {
105
+ sidebarInset.style.height = initialStyles.sidebarInset.height;
106
+ }
107
+ const body = byId('body');
108
+ if (body) {
109
+ body.style.overflow = ((_a = initialStyles.body) === null || _a === void 0 ? void 0 : _a.overflow) || 'auto';
110
+ }
111
+ };
112
+ if (hidden || !(topBannerOptions === null || topBannerOptions === void 0 ? void 0 : topBannerOptions.enabled) || !stripeActivated || !isLoggedIn()) {
113
+ return null;
114
+ }
115
+ return (jsx(TopBanner, { parentContainerSelector: parentContainerSelector, bannerText: topBannerOptions.bannerText, buttonHandler: getTopBannerButtonHandler(topBannerOptions.onUpgrade), buttonLabel: topBannerOptions.buttonLabel || t('creditBalance.upgrade'), loading: topBannerOptions.loading, tooltipText: topBannerOptions.tooltipText, onLoad: handleTopBannerLoad, onClose: handleTopBannerClose }));
116
+ }
117
+
118
+ export { SubscriptionTopBanner };
119
+ //# sourceMappingURL=subscription-top-banner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-top-banner.js","sources":["../../../../../../src/components/subscription-top-banner.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;;;AA6BA,MAAM,IAAI,GAAG,CAAC,QAAgB,KAAK,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAuB;AAEzF;;;;;;;;;;AAUG;AACG,SAAU,qBAAqB,CAAC,EACpC,MAAM,GAAG,KAAK,EACd,uBAAuB,GAAG,mCAAmC,GAClC,EAAA;AAC3B,IAAA,MAAM,CAAC,GAAG,IAAI,EAAE;AAChB,IAAA,MAAM,eAAe,GAAG,oBAAoB,EAAE;AAC9C,IAAA,MAAM,gBAAgB,GAAG,WAAW,CAClC,CAAC,KAAqC,KAAI,EAAA,IAAA,EAAA,CAAA,CAAC,OAAA,CAAA,EAAA,GAAA,KAAK,CAAC,SAAS,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,MAAA,GAAA,EAAA,CAAE,gBAAgB,CAAA,CAAA,CAAA,CAC7E;AACD,IAAA,MAAM,yBAAyB,GAAG,yBAAyB,EAAE;IAC7D,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAe,EAAE,CAAC;IAEpE,SAAS,CAAC,MAAK;AACb,QAAA,MAAM,cAAc,GAAG,IAAI,CAAC,+BAA+B,CAAC;AAC5D,QAAA,MAAM,oBAAoB,GAAG,IAAI,CAAC,+BAA+B,CAAC;AAClE,QAAA,MAAM,gBAAgB,GAAG,IAAI,CAAC,iCAAiC,CAAC;AAChE,QAAA,MAAM,YAAY,GAAG,IAAI,CAAC,6BAA6B,CAAC;AACxD,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;AA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,EAAE,gBAAgB,CAAC,UAAU,EACvC,aAAa,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,SAAS,CAAC,EACpE,WAAW,EAAE,gBAAgB,CAAC,WAAW,IAAI,CAAC,CAAC,uBAAuB,CAAC,EACvE,OAAO,EAAE,gBAAgB,CAAC,OAAO,EACjC,WAAW,EAAE,gBAAgB,CAAC,WAAW,EACzC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,oBAAoB,EAAA,CAC7B;AAEN;;;;"}
@@ -1,11 +1,13 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useChatHost, useChatMarkdown } from '../chat/chat-host-context.js';
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
+ import { useRef, useId, useState, useLayoutEffect } from 'react';
3
+ import { useChatHost, useChatMarkdown, useChatT } from '../chat/chat-host-context.js';
3
4
  import { useChatWelcomeMessage } from '../chat/hooks/use-chat-welcome-message.js';
4
5
 
5
6
  function WelcomeMessage({ aiWelcomeMessage, sessionId, username, tenantKey, mentorUniqueId, token, isNewSession, className = 'text-gray-600 text-lg max-w-3xl', }) {
6
7
  var _a;
7
8
  const { config } = useChatHost();
8
9
  const Markdown = useChatMarkdown();
10
+ const t = useChatT();
9
11
  const { welcomeMessage } = useChatWelcomeMessage({
10
12
  sessionId,
11
13
  username,
@@ -15,7 +17,25 @@ function WelcomeMessage({ aiWelcomeMessage, sessionId, username, tenantKey, ment
15
17
  wsUrl: `${(_a = config === null || config === void 0 ? void 0 : config.baseWsUrl()) !== null && _a !== void 0 ? _a : ''}/ws/langflow/`,
16
18
  isNewSession,
17
19
  });
18
- return jsx(Markdown, { className: className, children: welcomeMessage || aiWelcomeMessage || '' });
20
+ const text = welcomeMessage || aiWelcomeMessage || '';
21
+ const boxRef = useRef(null);
22
+ const boxId = useId();
23
+ const [overflows, setOverflows] = useState(false);
24
+ // Keyed on the session so every new chat starts collapsed.
25
+ const [expandedSession, setExpandedSession] = useState(null);
26
+ const expanded = overflows && expandedSession === sessionId;
27
+ // The greeting streams in, so overflow is re-measured on every text change,
28
+ // and only while clamped: the opened box has its own scroll height.
29
+ useLayoutEffect(() => {
30
+ const box = boxRef.current;
31
+ if (!box || expanded)
32
+ return;
33
+ // A box scrolled while open keeps its offset under the clamp, which would
34
+ // show the middle of the greeting instead of its first lines.
35
+ box.scrollTop = 0;
36
+ setOverflows(box.scrollHeight > box.clientHeight);
37
+ }, [text, expanded]);
38
+ return (jsxs(Fragment, { children: [jsx("div", { ref: boxRef, id: boxId, "data-testid": "welcome-message-box", className: expanded ? 'max-h-[40vh] overflow-y-auto overscroll-contain text-left' : 'line-clamp-3', children: jsx(Markdown, { className: className, children: text }) }), overflows && (jsx("button", { type: "button", "aria-expanded": expanded, "aria-controls": boxId, onClick: () => setExpandedSession(expanded ? null : sessionId), className: "mt-1 text-sm font-medium text-blue-600 hover:text-blue-700 hover:underline", "data-testid": "welcome-message-toggle", children: expanded ? t('chat.welcomeMessage.showLess') : t('chat.welcomeMessage.showMore') }))] }));
19
39
  }
20
40
 
21
41
  export { WelcomeMessage };
@@ -1 +1 @@
1
- {"version":3,"file":"welcome-message.js","sources":["../../../../../../../src/components/welcome-chat/welcome-message.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;AAgBM,SAAU,cAAc,CAAC,EAC7B,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,SAAS,EACT,cAAc,EACd,KAAK,EACL,YAAY,EACZ,SAAS,GAAG,iCAAiC,GACzB,EAAA;;AACpB,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE;AAChC,IAAA,MAAM,QAAQ,GAAG,eAAe,EAAE;AAClC,IAAA,MAAM,EAAE,cAAc,EAAE,GAAG,qBAAqB,CAAC;QAC/C,SAAS;QACT,QAAQ;QACR,SAAS;QACT,cAAc;QACd,KAAK;AACL,QAAA,KAAK,EAAE,CAAA,EAAG,CAAA,EAAA,GAAA,MAAM,KAAA,IAAA,IAAN,MAAM,KAAA,MAAA,GAAA,MAAA,GAAN,MAAM,CAAE,SAAS,EAAE,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,EAAE,CAAA,aAAA,CAAe;QAClD,YAAY;AACb,KAAA,CAAC;AACF,IAAA,OAAOA,GAAA,CAAC,QAAQ,EAAA,EAAC,SAAS,EAAE,SAAS,EAAA,QAAA,EAAG,cAAc,IAAI,gBAAgB,IAAI,EAAE,GAAY;AAC9F;;;;"}
1
+ {"version":3,"file":"welcome-message.js","sources":["../../../../../../../src/components/welcome-chat/welcome-message.tsx"],"sourcesContent":[null],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;AAiBM,SAAU,cAAc,CAAC,EAC7B,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,SAAS,EACT,cAAc,EACd,KAAK,EACL,YAAY,EACZ,SAAS,GAAG,iCAAiC,GACzB,EAAA;;AACpB,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE;AAChC,IAAA,MAAM,QAAQ,GAAG,eAAe,EAAE;AAClC,IAAA,MAAM,CAAC,GAAG,QAAQ,EAAE;AACpB,IAAA,MAAM,EAAE,cAAc,EAAE,GAAG,qBAAqB,CAAC;QAC/C,SAAS;QACT,QAAQ;QACR,SAAS;QACT,cAAc;QACd,KAAK;AACL,QAAA,KAAK,EAAE,CAAA,EAAG,CAAA,EAAA,GAAA,MAAM,KAAA,IAAA,IAAN,MAAM,KAAA,MAAA,GAAA,MAAA,GAAN,MAAM,CAAE,SAAS,EAAE,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,EAAE,CAAA,aAAA,CAAe;QAClD,YAAY;AACb,KAAA,CAAC;AACF,IAAA,MAAM,IAAI,GAAG,cAAc,IAAI,gBAAgB,IAAI,EAAE;AAErD,IAAA,MAAM,MAAM,GAAG,MAAM,CAAiB,IAAI,CAAC;AAC3C,IAAA,MAAM,KAAK,GAAG,KAAK,EAAE;IACrB,MAAM,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TRIGGERS } from '@iblai/web-utils';
3
+ import { Dialog, DialogContent, DialogTitle, DialogDescription } from '../ui/dialog.js';
4
+ import { useT } from '../../i18n/context.js';
5
+ import '../../packages/i18n/dist/index.esm.js';
6
+ import Mail from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/mail.js';
7
+
8
+ /**
9
+ * What a non-admin sees when their organization has run out of credits: the
10
+ * one line that says so and a Contact Now button that opens their mail client
11
+ * on the organization's support address (the same mail the credits banner's
12
+ * Contact Now used to send, through `useTopBannerButtonHandler`).
13
+ *
14
+ * Opened through the `subscription` slice's `openContactAdminModal`
15
+ * (`setOpenContactAdminModal`), which `use402ErrorCheck` and the subscription
16
+ * flow set; hosts render it next to `AppleRestrictionModal`.
17
+ */
18
+ function ContactAdminModal({ isOpen, onClose }) {
19
+ const t = useT();
20
+ const getBannerButtonHandler = useTopBannerButtonHandler();
21
+ const contactAdmin = getBannerButtonHandler(SUBSCRIPTION_V2_TRIGGERS.CONTACT_ADMIN);
22
+ return (jsx(Dialog, { open: isOpen, onOpenChange: (open) => {
23
+ if (!open)
24
+ onClose();
25
+ }, children: jsx(DialogContent, { className: "max-w-sm gap-0 overflow-hidden rounded-2xl p-0", children: jsxs("div", { className: "flex flex-col items-center gap-6 px-8 py-10 text-center", children: [jsx("div", { className: "flex h-16 w-16 items-center justify-center rounded-full bg-blue-50 dark:bg-blue-900/30", children: jsx(Mail, { className: "h-8 w-8 text-blue-600 dark:text-blue-400", strokeWidth: 1.5 }) }), jsxs("div", { className: "flex flex-col gap-2", children: [jsx(DialogTitle, { className: "text-xl font-bold tracking-tight text-gray-900 dark:text-gray-100", children: t('modalsContactAdminModal.title') }), jsx(DialogDescription, { className: "text-sm leading-relaxed text-gray-500 dark:text-gray-400", children: t('modalsContactAdminModal.description') })] }), jsx("button", { type: "button", onClick: () => {
26
+ contactAdmin();
27
+ onClose();
28
+ }, className: "flex w-full items-center justify-center rounded-full bg-blue-600 py-3 text-sm font-semibold text-white hover:bg-blue-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2", children: t('modalsContactAdminModal.contactNow') })] }) }) }));
29
+ }
30
+
31
+ export { ContactAdminModal };
32
+ //# sourceMappingURL=contact-admin-modal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contact-admin-modal.js","sources":["../../../../../../../src/components/modals/contact-admin-modal.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs"],"mappings":";;;;;;;AAiBA;;;;;;;;;AASG;SACa,iBAAiB,CAAC,EAAE,MAAM,EAAE,OAAO,EAA0B,EAAA;AAC3E,IAAA,MAAM,CAAC,GAAG,IAAI,EAAE;AAChB,IAAA,MAAM,sBAAsB,GAAG,yBAAyB,EAAE;IAC1D,MAAM,YAAY,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,aAAa,CAAC;AAEnF,IAAA,QACEA,GAAA,CAAC,MAAM,EAAA,EACL,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,IAAI,KAAI;AACrB,YAAA,IAAI,CAAC,IAAI;AAAE,gBAAA,OAAO,EAAE;AACtB,QAAA,CAAC,EAAA,QAAA,EAEDA,GAAA,CAAC,aAAa,EAAA,EAAC,SAAS,EAAC,gDAAgD,EAAA,QAAA,EACvEC,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,yDAAyD,EAAA,QAAA,EAAA,CACtED,aAAK,SAAS,EAAC,wFAAwF,EAAA,QAAA,EACrGA,GAAA,CAAC,IAAI,EAAA,EAAC,SAAS,EAAC,0CAA0C,EAAC,WAAW,EAAE,GAAG,EAAA,CAAI,EAAA,CAC3E,EAENC,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,qBAAqB,EAAA,QAAA,EAAA,CAClCD,GAAA,CAAC,WAAW,EAAA,EAAC,SAAS,EAAC,mEAAmE,EAAA,QAAA,EACvF,CAAC,CAAC,+BAA+B,CAAC,EAAA,CACvB,EACdA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