@iblai/web-containers 1.72.0 → 1.73.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/cjs/_virtual/index2.js +2 -2
  2. package/dist/cjs/_virtual/index3.js +2 -2
  3. package/dist/cjs/components/credit-balance.js +41 -69
  4. package/dist/cjs/components/credit-balance.js.map +1 -1
  5. package/dist/cjs/components/modals/contact-admin-modal.js +34 -0
  6. package/dist/cjs/components/modals/contact-admin-modal.js.map +1 -0
  7. package/dist/cjs/components/modals/upgrade-package-modal.js +279 -18
  8. package/dist/cjs/components/modals/upgrade-package-modal.js.map +1 -1
  9. package/dist/cjs/components/profile/add-credits-modal.js +167 -21
  10. package/dist/cjs/components/profile/add-credits-modal.js.map +1 -1
  11. package/dist/cjs/components/profile/auto-recharge-modal.js +1 -1
  12. package/dist/cjs/components/profile/auto-recharge-modal.js.map +1 -1
  13. package/dist/cjs/components/profile/billing-credits.js +4 -4
  14. package/dist/cjs/components/profile/billing-credits.js.map +1 -1
  15. package/dist/cjs/components/profile/billing.js +58 -99
  16. package/dist/cjs/components/profile/billing.js.map +1 -1
  17. package/dist/cjs/components/profile/pending-credit-top-up.js +216 -0
  18. package/dist/cjs/components/profile/pending-credit-top-up.js.map +1 -0
  19. package/dist/cjs/components/profile/use-complete-pending-credit-top-up.js +70 -0
  20. package/dist/cjs/components/profile/use-complete-pending-credit-top-up.js.map +1 -0
  21. package/dist/cjs/components/subscription-top-banner.js +121 -0
  22. package/dist/cjs/components/subscription-top-banner.js.map +1 -0
  23. package/dist/cjs/components/workflows/workflow-editor.js +28 -8
  24. package/dist/cjs/components/workflows/workflow-editor.js.map +1 -1
  25. package/dist/cjs/i18n/messages/en.json.js +122 -20
  26. package/dist/cjs/i18n/messages/en.json.js.map +1 -1
  27. package/dist/cjs/i18n/messages/es.json.js +124 -22
  28. package/dist/cjs/i18n/messages/es.json.js.map +1 -1
  29. package/dist/cjs/i18n/messages/fr.json.js +122 -20
  30. package/dist/cjs/i18n/messages/fr.json.js.map +1 -1
  31. package/dist/cjs/i18n/messages/zh.json.js +123 -21
  32. package/dist/cjs/i18n/messages/zh.json.js.map +1 -1
  33. package/dist/cjs/index.js +4 -0
  34. package/dist/cjs/index.js.map +1 -1
  35. package/dist/cjs/node_modules/.pnpm/css-mediaquery@0.1.2/node_modules/css-mediaquery/index.js +1 -1
  36. package/dist/cjs/node_modules/.pnpm/matchmediaquery@0.4.2/node_modules/matchmediaquery/index.js +1 -1
  37. package/dist/cjs/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.js +1 -1
  38. package/dist/cjs/web-containers/tsconfig.build.tsbuildinfo +1 -1
  39. package/dist/esm/components/credit-balance.js +44 -72
  40. package/dist/esm/components/credit-balance.js.map +1 -1
  41. package/dist/esm/components/modals/contact-admin-modal.js +32 -0
  42. package/dist/esm/components/modals/contact-admin-modal.js.map +1 -0
  43. package/dist/esm/components/modals/upgrade-package-modal.js +281 -20
  44. package/dist/esm/components/modals/upgrade-package-modal.js.map +1 -1
  45. package/dist/esm/components/profile/add-credits-modal.js +170 -24
  46. package/dist/esm/components/profile/add-credits-modal.js.map +1 -1
  47. package/dist/esm/components/profile/auto-recharge-modal.js +1 -1
  48. package/dist/esm/components/profile/auto-recharge-modal.js.map +1 -1
  49. package/dist/esm/components/profile/billing-credits.js +4 -4
  50. package/dist/esm/components/profile/billing-credits.js.map +1 -1
  51. package/dist/esm/components/profile/billing.js +60 -101
  52. package/dist/esm/components/profile/billing.js.map +1 -1
  53. package/dist/esm/components/profile/pending-credit-top-up.js +202 -0
  54. package/dist/esm/components/profile/pending-credit-top-up.js.map +1 -0
  55. package/dist/esm/components/profile/use-complete-pending-credit-top-up.js +68 -0
  56. package/dist/esm/components/profile/use-complete-pending-credit-top-up.js.map +1 -0
  57. package/dist/esm/components/subscription-top-banner.js +119 -0
  58. package/dist/esm/components/subscription-top-banner.js.map +1 -0
  59. package/dist/esm/components/workflows/workflow-editor.js +28 -8
  60. package/dist/esm/components/workflows/workflow-editor.js.map +1 -1
  61. package/dist/esm/i18n/messages/en.json.js +121 -21
  62. package/dist/esm/i18n/messages/en.json.js.map +1 -1
  63. package/dist/esm/i18n/messages/es.json.js +123 -23
  64. package/dist/esm/i18n/messages/es.json.js.map +1 -1
  65. package/dist/esm/i18n/messages/fr.json.js +121 -21
  66. package/dist/esm/i18n/messages/fr.json.js.map +1 -1
  67. package/dist/esm/i18n/messages/zh.json.js +122 -22
  68. package/dist/esm/i18n/messages/zh.json.js.map +1 -1
  69. package/dist/esm/index.js +2 -0
  70. package/dist/esm/index.js.map +1 -1
  71. package/dist/esm/web-containers/tsconfig.build.tsbuildinfo +1 -1
  72. package/dist/index.d.ts +95 -5
  73. package/dist/package.json +1 -1
  74. package/package.json +4 -4
@@ -0,0 +1,216 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * A credit top-up that has to wait for a payment method.
5
+ *
6
+ * Someone without a card on file still just presses "Add Credits" and types an
7
+ * amount. We then send them to the Stripe customer portal to save a card, and
8
+ * when Stripe brings them back we charge that amount and add the credits —
9
+ * one trip instead of "add a card, come back, open Add Credits again".
10
+ *
11
+ * The amount travels on the portal's after-completion URL so the return page
12
+ * knows what was asked for, but the URL alone never charges anything: the
13
+ * amount is also written to localStorage under a one-time nonce before the
14
+ * redirect, and the charge only runs when the URL's nonce, amount and tenant
15
+ * all match that record and it is still fresh. The record is deleted the
16
+ * moment it is claimed, so a reload (or a second mounted surface) can't charge
17
+ * twice, and a crafted link can't charge an amount the person never entered.
18
+ *
19
+ * localStorage (not sessionStorage) because the Stripe portal is a full
20
+ * navigation and some hosts open it in a new tab.
21
+ */
22
+ const PENDING_CREDIT_TOP_UP_STORAGE_KEY = 'ibl_pending_credit_top_up';
23
+ /** Query params appended to the portal's after-completion URL. */
24
+ const CREDIT_TOP_UP_QUERY_PARAMS = {
25
+ nonce: 'credit_topup',
26
+ amount: 'credit_topup_amount',
27
+ };
28
+ /** A top-up that is not claimed within the hour is forgotten. */
29
+ const PENDING_CREDIT_TOP_UP_TTL_MS = 60 * 60 * 1000;
30
+ function getStorage() {
31
+ try {
32
+ if (typeof window === 'undefined' || !window.localStorage)
33
+ return null;
34
+ return window.localStorage;
35
+ }
36
+ catch (_a) {
37
+ return null;
38
+ }
39
+ }
40
+ function createNonce() {
41
+ const cryptoApi = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
42
+ if (cryptoApi && typeof cryptoApi.randomUUID === 'function') {
43
+ return cryptoApi.randomUUID();
44
+ }
45
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
46
+ }
47
+ /** Normalises any accepted amount input to the "25.00" form stored and sent. */
48
+ function normaliseTopUpAmountUsd(amount) {
49
+ const num = typeof amount === 'string' ? parseFloat(amount) : amount;
50
+ if (!Number.isFinite(num) || num <= 0)
51
+ return null;
52
+ return num.toFixed(2);
53
+ }
54
+ /** The pending record, if one is stored, well-formed and not expired. */
55
+ function readPendingCreditTopUp(now = Date.now()) {
56
+ const storage = getStorage();
57
+ if (!storage)
58
+ return null;
59
+ const raw = storage.getItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
60
+ if (!raw)
61
+ return null;
62
+ try {
63
+ const parsed = JSON.parse(raw);
64
+ if (!parsed ||
65
+ typeof parsed.nonce !== 'string' ||
66
+ typeof parsed.amountUsd !== 'string' ||
67
+ typeof parsed.tenant !== 'string' ||
68
+ typeof parsed.createdAt !== 'number') {
69
+ storage.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
70
+ return null;
71
+ }
72
+ if (now - parsed.createdAt > PENDING_CREDIT_TOP_UP_TTL_MS) {
73
+ storage.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
74
+ return null;
75
+ }
76
+ return parsed;
77
+ }
78
+ catch (_a) {
79
+ storage.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
80
+ return null;
81
+ }
82
+ }
83
+ function clearPendingCreditTopUp() {
84
+ var _a;
85
+ (_a = getStorage()) === null || _a === void 0 ? void 0 : _a.removeItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY);
86
+ }
87
+ /**
88
+ * Records the top-up to finish after the payment method is saved and returns
89
+ * the URL Stripe should send the person back to: `currentUrl` plus the amount
90
+ * and the one-time nonce. Any existing query (e.g. `profileTab=billing`) is
91
+ * kept so the person lands where they left.
92
+ */
93
+ function beginPendingCreditTopUp({ tenant, amountUsd, currentUrl, now = Date.now(), }) {
94
+ var _a;
95
+ const pending = {
96
+ nonce: createNonce(),
97
+ amountUsd,
98
+ tenant,
99
+ createdAt: now,
100
+ };
101
+ (_a = getStorage()) === null || _a === void 0 ? void 0 : _a.setItem(PENDING_CREDIT_TOP_UP_STORAGE_KEY, JSON.stringify(pending));
102
+ const url = new URL(currentUrl);
103
+ url.searchParams.set(CREDIT_TOP_UP_QUERY_PARAMS.nonce, pending.nonce);
104
+ url.searchParams.set(CREDIT_TOP_UP_QUERY_PARAMS.amount, pending.amountUsd);
105
+ return { pending, afterCompletionUrl: url.toString() };
106
+ }
107
+ /** True when the URL carries the top-up return params at all. */
108
+ function hasPendingCreditTopUpParams(url) {
109
+ try {
110
+ return new URL(url).searchParams.has(CREDIT_TOP_UP_QUERY_PARAMS.nonce);
111
+ }
112
+ catch (_a) {
113
+ return false;
114
+ }
115
+ }
116
+ /** The same URL without the top-up return params (for `history.replaceState`). */
117
+ function stripPendingCreditTopUpParams(url) {
118
+ try {
119
+ const parsed = new URL(url);
120
+ parsed.searchParams.delete(CREDIT_TOP_UP_QUERY_PARAMS.nonce);
121
+ parsed.searchParams.delete(CREDIT_TOP_UP_QUERY_PARAMS.amount);
122
+ return parsed.toString();
123
+ }
124
+ catch (_a) {
125
+ return url;
126
+ }
127
+ }
128
+ /**
129
+ * Claims the top-up the URL refers to: returns it, and deletes the stored
130
+ * record, only when the URL's nonce and amount match the record for this
131
+ * tenant. Returns null (and leaves nothing to claim) otherwise.
132
+ */
133
+ function claimPendingCreditTopUp({ url, tenant, now = Date.now(), }) {
134
+ let params;
135
+ try {
136
+ params = new URL(url).searchParams;
137
+ }
138
+ catch (_a) {
139
+ return null;
140
+ }
141
+ const nonce = params.get(CREDIT_TOP_UP_QUERY_PARAMS.nonce);
142
+ const amount = params.get(CREDIT_TOP_UP_QUERY_PARAMS.amount);
143
+ if (!nonce || !amount)
144
+ return null;
145
+ const pending = readPendingCreditTopUp(now);
146
+ if (!pending)
147
+ return null;
148
+ if (pending.nonce !== nonce || pending.tenant !== tenant)
149
+ return null;
150
+ if (normaliseTopUpAmountUsd(amount) !== pending.amountUsd)
151
+ return null;
152
+ clearPendingCreditTopUp();
153
+ return pending;
154
+ }
155
+ /**
156
+ * The backend's plain-sentence refusal from a rejected top-up call, whatever
157
+ * shape the data layer threw it in (`{ data: { detail } }`, `{ data: 'text' }`
158
+ * or a bare `{ detail }`). Undefined when there is none.
159
+ */
160
+ function readTopUpErrorDetail(error) {
161
+ if (!error || typeof error !== 'object')
162
+ return undefined;
163
+ const err = error;
164
+ if (typeof err.data === 'string' && err.data.trim())
165
+ return err.data;
166
+ if (err.data && typeof err.data === 'object') {
167
+ const detail = err.data.detail;
168
+ if (typeof detail === 'string' && detail.trim())
169
+ return detail;
170
+ }
171
+ if (typeof err.detail === 'string' && err.detail.trim())
172
+ return err.detail;
173
+ return undefined;
174
+ }
175
+ function readStringField(body, key) {
176
+ if (!body || typeof body !== 'object')
177
+ return undefined;
178
+ const value = body[key];
179
+ return typeof value === 'string' && value.trim() ? value : undefined;
180
+ }
181
+ function readTopUpError(error) {
182
+ if (!error || typeof error !== 'object')
183
+ return {};
184
+ const err = error;
185
+ const body = err.data && typeof err.data === 'object' ? err.data : error;
186
+ return {
187
+ detail: readTopUpErrorDetail(error),
188
+ code: readStringField(body, 'code'),
189
+ errorType: readStringField(body, 'error_type'),
190
+ };
191
+ }
192
+ /** Refusals that saving a (new) card on Stripe fixes. */
193
+ const PAYMENT_METHOD_ERROR_TYPES = new Set(['card_error', 'payment_method_error']);
194
+ /**
195
+ * True when the backend refused the top-up because of the payment method:
196
+ * the card on file was refused (expired, declined, …) or there is none.
197
+ */
198
+ function isPaymentMethodProblem(error) {
199
+ const { errorType } = readTopUpError(error);
200
+ return errorType !== undefined && PAYMENT_METHOD_ERROR_TYPES.has(errorType);
201
+ }
202
+
203
+ exports.CREDIT_TOP_UP_QUERY_PARAMS = CREDIT_TOP_UP_QUERY_PARAMS;
204
+ exports.PENDING_CREDIT_TOP_UP_STORAGE_KEY = PENDING_CREDIT_TOP_UP_STORAGE_KEY;
205
+ exports.PENDING_CREDIT_TOP_UP_TTL_MS = PENDING_CREDIT_TOP_UP_TTL_MS;
206
+ exports.beginPendingCreditTopUp = beginPendingCreditTopUp;
207
+ exports.claimPendingCreditTopUp = claimPendingCreditTopUp;
208
+ exports.clearPendingCreditTopUp = clearPendingCreditTopUp;
209
+ exports.hasPendingCreditTopUpParams = hasPendingCreditTopUpParams;
210
+ exports.isPaymentMethodProblem = isPaymentMethodProblem;
211
+ exports.normaliseTopUpAmountUsd = normaliseTopUpAmountUsd;
212
+ exports.readPendingCreditTopUp = readPendingCreditTopUp;
213
+ exports.readTopUpError = readTopUpError;
214
+ exports.readTopUpErrorDetail = readTopUpErrorDetail;
215
+ exports.stripPendingCreditTopUpParams = stripPendingCreditTopUpParams;
216
+ //# 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":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;AAkBG;AAEI,MAAM,iCAAiC,GAAG;AAEjD;AACO,MAAM,0BAA0B,GAAG;AACxC,IAAA,KAAK,EAAE,cAAc;AACrB,IAAA,MAAM,EAAE,qBAAqB;;AAG/B;MACa,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG;AAUtD,SAAS,UAAU,GAAA;AACjB,IAAA,IAAI;QACF,IAAI,OAAO,MA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AG,CAAC,MAAM;AAC1E,IAAA,OAAO,SAAS;AAClB;AAcA,SAAS,eAAe,CAAC,IAAa,EAAE,GAAW,EAAA;AACjD,IAAA,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;AAAE,QAAA,OAAO,SAAS;AACvD,IAAA,MAAM,KAAK,GAAI,IAAgC,CAAC,GAAG,CAAC;AACpD,IAAA,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,SAAS;AACtE;AAEM,SAAU,cAAc,CAAC,KAAc,EAAA;AAC3C,IAAA,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,EAAE;IAClD,MAAM,GAAG,GAAG,KAA2B;IACvC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,GAAG,GAAG,CAAC,IAAI,GAAG,KAAK;IACxE,OAAO;AACL,QAAA,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC;AACnC,QAAA,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC;AACnC,QAAA,SAAS,EAAE,eAAe,CAAC,IAAI,EAAE,YAAY,CAAC;KAC/C;AACH;AAEA;AACA,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;AAElF;;;AAGG;AACG,SAAU,sBAAsB,CAAC,KAAc,EAAA;IACnD,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,70 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var dataLayer = require('@iblai/data-layer');
5
+ var sonner = require('sonner');
6
+ var context = require('../../i18n/context.js');
7
+ require('../../packages/i18n/dist/index.esm.js');
8
+ var pendingCreditTopUp = require('./pending-credit-top-up.js');
9
+
10
+ function formatUsd(amount) {
11
+ const num = parseFloat(amount);
12
+ return Number.isFinite(num) ? `$${num.toFixed(2)}` : `$${amount}`;
13
+ }
14
+ /**
15
+ * Finishes a credit top-up that was waiting for a payment method (see
16
+ * `pending-credit-top-up.ts`). Mount it on every surface that offers
17
+ * "Add Credits" — the Billing tab and the navbar credit dropdown — so whichever
18
+ * one is on the page Stripe returns to charges the saved card for the amount
19
+ * the person entered, adds the credits, and says so in a toast. The billing
20
+ * query is invalidated by the mutation, so the balance on screen updates too.
21
+ *
22
+ * Claiming deletes the stored record first, so with both surfaces mounted only
23
+ * the first effect to run charges; the other finds nothing. The return params
24
+ * are removed from the address bar either way so a reload can't replay them.
25
+ */
26
+ function useCompletePendingCreditTopUp({ tenant, enabled = true, }) {
27
+ const t = context.useT();
28
+ const [triggerAutoRecharge] = dataLayer.useTriggerAutoRechargeMutation();
29
+ const [isCompleting, setIsCompleting] = React.useState(false);
30
+ const startedRef = React.useRef(false);
31
+ React.useEffect(() => {
32
+ if (!enabled || !tenant || startedRef.current)
33
+ return;
34
+ if (typeof window === 'undefined')
35
+ return;
36
+ const currentUrl = window.location.href;
37
+ if (!pendingCreditTopUp.hasPendingCreditTopUpParams(currentUrl))
38
+ return;
39
+ startedRef.current = true;
40
+ const pending = pendingCreditTopUp.claimPendingCreditTopUp({ url: currentUrl, tenant });
41
+ // A null state lets Next's patched replaceState sync the app router (and
42
+ // useSearchParams) with the new URL. Handing window.history.state back
43
+ // carries Next's internal marker, which makes it skip that sync, and a
44
+ // later router.replace built from the stale params would put the nonce
45
+ // and amount back in the address bar.
46
+ window.history.replaceState(null, '', pendingCreditTopUp.stripPendingCreditTopUpParams(currentUrl));
47
+ if (!pending)
48
+ return;
49
+ setIsCompleting(true);
50
+ const toastId = sonner.toast.loading(t('profileAddCreditsModal.addingCredits'));
51
+ triggerAutoRecharge({ amount_usd: pending.amountUsd, platform_key: tenant })
52
+ .unwrap()
53
+ .then(() => {
54
+ sonner.toast.success(t('profileAddCreditsModal.creditsAddedAfterPayment', {
55
+ amount: formatUsd(pending.amountUsd),
56
+ }), { id: toastId });
57
+ })
58
+ .catch((error) => {
59
+ var _a;
60
+ sonner.toast.error((_a = pendingCreditTopUp.readTopUpErrorDetail(error)) !== null && _a !== void 0 ? _a : t('profileAddCreditsModal.failedToAddCreditsAfterPayment'), { id: toastId });
61
+ })
62
+ .finally(() => setIsCompleting(false));
63
+ // The claim is one-shot by design (startedRef): re-runs from a changed
64
+ // dependency find nothing left to do.
65
+ }, [enabled, tenant, t, triggerAutoRecharge]);
66
+ return { isCompleting };
67
+ }
68
+
69
+ exports.useCompletePendingCreditTopUp = useCompletePendingCreditTopUp;
70
+ //# 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":["useT","useTriggerAutoRechargeMutation","useState","useRef","useEffect","hasPendingCreditTopUpParams","claimPendingCreditTopUp","stripPendingCreditTopUpParams","toast","readTopUpErrorDetail"],"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,GAAG,IAAI,GAIf,EAAA;AACC,IAAA,MAAM,CAAC,GAAGA,YAAI,EAAE;AAChB,IAAA,MAAM,CAAC,mBAAmB,CAAC,GAAGC,wCAA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AC,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,121 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var React = require('react');
5
+ var reactRedux = require('react-redux');
6
+ var webUtils = require('@iblai/web-utils');
7
+ var context = require('../i18n/context.js');
8
+ require('../packages/i18n/dist/index.esm.js');
9
+ var index = require('./top-banner/index.js');
10
+
11
+ const byId = (selector) => document.querySelector(selector);
12
+ /**
13
+ * The credits banner across the top of the app ("You've run out of credits…"),
14
+ * driven by the `topBanner` slice the subscription flow writes to. A non-admin
15
+ * whose organization ran out gets `ContactAdminModal` instead. Its button does what
16
+ * `useTopBannerButtonHandler` maps the banner's trigger to. Shows only for a
17
+ * signed-in person on a tenant with billing on.
18
+ *
19
+ * While shown it shortens the sidebar shell (`[data-slot="sidebar-*"]`) and
20
+ * the main content container by its own height so nothing scrolls under it,
21
+ * and puts everything back when closed.
22
+ */
23
+ function SubscriptionTopBanner({ hidden = false, parentContainerSelector = webUtils.SUBSCRIPTION_BANNER_PARENT_SELECTOR, }) {
24
+ const t = context.useT();
25
+ const stripeActivated = webUtils.useIsStripeActivated();
26
+ const topBannerOptions = reactRedux.useSelector((state) => { var _a; return (_a = state.topBanner) === null || _a === void 0 ? void 0 : _a.topBannerOptions; });
27
+ const getTopBannerButtonHandler = webUtils.useTopBannerButtonHandler();
28
+ const [initialStyles, setInitialStyles] = React.useState({});
29
+ React.useEffect(() => {
30
+ const sideBarWrapper = byId('[data-slot="sidebar-wrapper"]');
31
+ const mainContentContainer = byId('#main-content-container > div');
32
+ const sidebarContainer = byId('[data-slot="sidebar-container"]');
33
+ const sidebarInset = byId('[data-slot="sidebar-inset"]');
34
+ const body = byId('body');
35
+ setInitialStyles({
36
+ sideBarWrapper: sideBarWrapper
37
+ ? {
38
+ maxHeight: sideBarWrapper.style.maxHeight,
39
+ top: sideBarWrapper.style.top,
40
+ position: sideBarWrapper.style.position,
41
+ }
42
+ : undefined,
43
+ mainContentContainer: mainContentContainer
44
+ ? {
45
+ position: mainContentContainer.style.position,
46
+ top: mainContentContainer.style.top,
47
+ }
48
+ : undefined,
49
+ sidebarContainer: sidebarContainer
50
+ ? { top: sidebarContainer.style.top, height: sidebarContainer.style.height }
51
+ : undefined,
52
+ sidebarInset: sidebarInset
53
+ ? { top: sidebarInset.style.top, height: sidebarInset.style.height }
54
+ : undefined,
55
+ body: body ? { overflow: body.style.overflow } : undefined,
56
+ });
57
+ }, []);
58
+ const handleTopBannerLoad = (bannerRef) => {
59
+ if (!bannerRef)
60
+ return;
61
+ const bannerHeight = bannerRef.clientHeight;
62
+ const sideBarWrapper = byId('[data-slot="sidebar-wrapper"]');
63
+ if (sideBarWrapper) {
64
+ sideBarWrapper.style.maxHeight = `calc(100vh - ${bannerHeight}px)`;
65
+ sideBarWrapper.style.top = '3px';
66
+ sideBarWrapper.style.position = 'relative';
67
+ }
68
+ const mainContentContainer = byId('#main-content-container > div');
69
+ if (mainContentContainer) {
70
+ mainContentContainer.style.position = 'relative';
71
+ mainContentContainer.style.top = '-12px';
72
+ }
73
+ const sidebarContainer = byId('[data-slot="sidebar-container"]');
74
+ if (sidebarContainer) {
75
+ sidebarContainer.style.top = '48px';
76
+ sidebarContainer.style.height = `calc(100% - ${bannerHeight}px)`;
77
+ }
78
+ const sidebarInset = byId('[data-slot="sidebar-inset"]');
79
+ if (sidebarInset) {
80
+ sidebarInset.style.height = `calc(100dvh - ${bannerHeight}px)`;
81
+ }
82
+ const body = byId('body');
83
+ if (body) {
84
+ body.style.overflow = 'hidden';
85
+ }
86
+ };
87
+ const handleTopBannerClose = () => {
88
+ var _a;
89
+ const sideBarWrapper = byId('[data-slot="sidebar-wrapper"]');
90
+ if (sideBarWrapper && initialStyles.sideBarWrapper) {
91
+ sideBarWrapper.style.maxHeight = initialStyles.sideBarWrapper.maxHeight;
92
+ sideBarWrapper.style.top = initialStyles.sideBarWrapper.top;
93
+ sideBarWrapper.style.position = initialStyles.sideBarWrapper.position;
94
+ }
95
+ const mainContentContainer = byId('#main-content-container > div');
96
+ if (mainContentContainer && initialStyles.mainContentContainer) {
97
+ mainContentContainer.style.position = initialStyles.mainContentContainer.position;
98
+ mainContentContainer.style.top = initialStyles.mainContentContainer.top;
99
+ }
100
+ const sidebarContainer = byId('[data-slot="sidebar-container"]');
101
+ if (sidebarContainer && initialStyles.sidebarContainer) {
102
+ sidebarContainer.style.top = initialStyles.sidebarContainer.top;
103
+ sidebarContainer.style.height = initialStyles.sidebarContainer.height;
104
+ }
105
+ const sidebarInset = byId('[data-slot="sidebar-inset"]');
106
+ if (sidebarInset && initialStyles.sidebarInset) {
107
+ sidebarInset.style.height = initialStyles.sidebarInset.height;
108
+ }
109
+ const body = byId('body');
110
+ if (body) {
111
+ body.style.overflow = ((_a = initialStyles.body) === null || _a === void 0 ? void 0 : _a.overflow) || 'auto';
112
+ }
113
+ };
114
+ if (hidden || !(topBannerOptions === null || topBannerOptions === void 0 ? void 0 : topBannerOptions.enabled) || !stripeActivated || !webUtils.isLoggedIn()) {
115
+ return null;
116
+ }
117
+ return (jsxRuntime.jsx(index.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 }));
118
+ }
119
+
120
+ exports.SubscriptionTopBanner = SubscriptionTopBanner;
121
+ //# 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":["SUBSCRIPTION_BANNER_PARENT_SELECTOR","useT","useIsStripeActivated","useSelector","useTopBannerButtonHandler","useState","useEffect","isLoggedIn","_jsx","TopBanner"],"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,GAAGA,4CAAmC,GAClC,EAAA;AAC3B,IAAA,MAAM,CAAC,GAAGC,YAAI,EAAE;AAChB,IAAA,MAAM,eAAe,GAAGC,6BAAoB,EAAE;AAC9C,IAAA,MAAM,gBAAgB,GAAGC,sBAAW,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,GAAGC,kCAAyB,EAAE;IAC7D,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAGC,cAAQ,CAAe,EAAE,CAAC;IAEpEC,eAAS,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,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AChD,UAAU,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;;;;"}
@@ -140,7 +140,15 @@ const MENTOR_MESSAGES = [
140
140
  const NODE_LOCATION = / at nodes\[(\d+)\](\.data)?(?: \(field: ([^()]+)\))?$/;
141
141
  const WORKFLOW_LOCATION = / at workflow_\w+(?: \(field: [^()]+\))?$/;
142
142
  const QUOTED = /'([^'\s]+)'/g;
143
- function problemTarget(message, steps, locationOnly = false) {
143
+ function problemTarget(message, steps, locationOnly = false, nodeId) {
144
+ const target = textTarget(message, steps, locationOnly);
145
+ // The step the backend names beats one read from the text, which can quote
146
+ // another step; only the text says which field to focus.
147
+ if (!nodeId || !steps.find(nodeId))
148
+ return target;
149
+ return target.stepId === nodeId ? target : { stepId: nodeId };
150
+ }
151
+ function textTarget(message, steps, locationOnly) {
144
152
  if (WORKFLOW_LOCATION.test(message))
145
153
  return {};
146
154
  // The location names the step at fault; a quoted id in the same message can
@@ -162,7 +170,7 @@ function problemTarget(message, steps, locationOnly = false) {
162
170
  }
163
171
  return {};
164
172
  }
165
- function toProblem(message, t, steps) {
173
+ function toProblem({ message, nodeId }, t, steps) {
166
174
  for (const { pattern, key, params, aboutEveryStep, locationOnly } of MENTOR_MESSAGES) {
167
175
  const match = pattern.exec(message);
168
176
  if (!match)
@@ -171,10 +179,21 @@ function toProblem(message, t, steps) {
171
179
  if (values === null)
172
180
  continue;
173
181
  const text = t(key, values);
174
- return aboutEveryStep ? { text } : { text, ...problemTarget(message, steps, locationOnly) };
182
+ return aboutEveryStep
183
+ ? { text }
184
+ : { text, ...problemTarget(message, steps, locationOnly, nodeId) };
175
185
  }
176
- return { text: message, ...problemTarget(message, steps) };
186
+ return { text: message, ...problemTarget(message, steps, false, nodeId) };
177
187
  }
188
+ // iblai-dm-pro#3218 lists each message again in error_details /
189
+ // warning_details, in the same order, with the step it is about, and drops the
190
+ // " at nodes[<index>]" ending. A detail whose text differs is not trusted.
191
+ const issuesOf = (messages, details = []) => messages.map((message, index) => {
192
+ const detail = details[index];
193
+ return (detail === null || detail === void 0 ? void 0 : detail.message) === message && detail.node_id
194
+ ? { message, nodeId: detail.node_id }
195
+ : { message };
196
+ });
178
197
  const distinct = (lines) => Array.from(new Set(lines));
179
198
  // A repeated line shows once and goes to the first step it was reported for;
180
199
  // once that step is fixed, the next check moves it to the next one.
@@ -455,9 +474,10 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
455
474
  // locates problems by position in it.
456
475
  const showValidation = (result, nodes) => {
457
476
  const steps = stepsOf(nodes);
458
- const problems = (messages) => distinctProblems(messages.map((message) => toProblem(message, t, steps)));
459
- const errors = problems(result.errors);
460
- const warnings = problems(workflowDefinition.withoutNoteConnectivityWarnings(result.warnings, nodes));
477
+ const problems = (issues) => distinctProblems(issues.map((issue) => toProblem(issue, t, steps)));
478
+ const errors = problems(issuesOf(result.errors, result.error_details));
479
+ const kept = new Set(workflowDefinition.withoutNoteConnectivityWarnings(result.warnings, nodes));
480
+ const warnings = problems(issuesOf(result.warnings, result.warning_details).filter(({ message }) => kept.has(message)));
461
481
  if (errors.length === 0 && warnings.length === 0) {
462
482
  setValidationResult(null);
463
483
  return;
@@ -859,7 +879,7 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
859
879
  const step = stepId ? shownSteps.find(stepId) : undefined;
860
880
  if (!step)
861
881
  return jsxRuntime.jsx("span", { children: text });
862
- return (jsxRuntime.jsx(actionTooltip.ActionTooltip, { label: t('workflowsWorkflowEditor.goToStep', { name: ((_a = step.data) === null || _a === void 0 ? void 0 : _a.label) || step.id }), children: jsxRuntime.jsx("button", { type: "button", className: PROBLEM_LINK, onClick: () => handleShowStep(step.id, field), children: text }) }));
882
+ return (jsxRuntime.jsx(actionTooltip.ActionTooltip, { label: t('workflowsWorkflowEditor.goToStep', { name: ((_a = step.data) === null || _a === void 0 ? void 0 : _a.label) || step.id }), children: jsxRuntime.jsx("button", { type: "button", "data-step-id": step.id, className: PROBLEM_LINK, onClick: () => handleShowStep(step.id, field), children: text }) }));
863
883
  };
864
884
  canvasShownRef.current = true;
865
885
  return (