@burdenoff/microfe-subscriberbot 2026.1107.5 → 2026.1107.7
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/stories/pages/BankConnectionsPage.stories.d.ts +2 -0
- package/dist/stories/pages/BankConnectionsPage.stories.d.ts.map +1 -1
- package/dist/stories/support/bankingFixtures.d.ts.map +1 -1
- package/dist/subscriberbot/components/EmptyState.d.ts +7 -6
- package/dist/subscriberbot/components/EmptyState.d.ts.map +1 -1
- package/dist/subscriberbot/components/EmptyState.js.map +1 -1
- package/dist/subscriberbot/components/index.d.ts +1 -0
- package/dist/subscriberbot/components/index.d.ts.map +1 -1
- package/dist/subscriberbot/hooks/useBankingApi.d.ts +1 -0
- package/dist/subscriberbot/hooks/useBankingApi.d.ts.map +1 -1
- package/dist/subscriberbot/hooks/useBankingApi.js +3 -3
- package/dist/subscriberbot/hooks/useBankingApi.js.map +1 -1
- package/dist/subscriberbot/pages/DashboardPage.js +1 -1
- package/dist/subscriberbot/pages/DashboardPage.js.map +1 -1
- package/dist/subscriberbot/pages/InboxPage.js +1 -1
- package/dist/subscriberbot/pages/InboxPage.js.map +1 -1
- package/dist/subscriberbot/pages/banking/BankConnectionsPage.d.ts.map +1 -1
- package/dist/subscriberbot/pages/banking/BankConnectionsPage.js +402 -299
- package/dist/subscriberbot/pages/banking/BankConnectionsPage.js.map +1 -1
- package/dist/subscriberbot/pages/banking/ConnectBankModal.d.ts +17 -0
- package/dist/subscriberbot/pages/banking/ConnectBankModal.d.ts.map +1 -0
- package/dist/subscriberbot/pages/banking/ConnectBankModal.js +156 -0
- package/dist/subscriberbot/pages/banking/ConnectBankModal.js.map +1 -0
- package/dist/subscriberbot/pages/relationships/RelationshipDetailPage.js +1 -1
- package/dist/subscriberbot/pages/relationships/RelationshipDetailPage.js.map +1 -1
- package/dist/subscriberbot/types/banking.d.ts +12 -1
- package/dist/subscriberbot/types/banking.d.ts.map +1 -1
- package/dist/subscriberbot/utils/bankRedirectLink.d.ts +27 -0
- package/dist/subscriberbot/utils/bankRedirectLink.d.ts.map +1 -0
- package/dist/subscriberbot/utils/bankRedirectLink.js +68 -0
- package/dist/subscriberbot/utils/bankRedirectLink.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipDetailPage.js","names":[],"sources":["../../../../src/subscriberbot/pages/relationships/RelationshipDetailPage.tsx"],"sourcesContent":["import { useFormatters } from '../../hooks/useFormatters';\nimport { useFormError } from '../../hooks/useFormError';\n/**\n * Relationship detail\n * @module subscriberbot/pages/relationships\n *\n * Full per-relationship view: plan, price, billing period, next renewal,\n * health score, entitlements, attached assets and renewal events — plus\n * lifecycle transitions (validated server-side), edit, and cancel.\n * Reads `subRelationship(id)`; writes `subTransitionRelationship`,\n * `subCancelRelationship`, `subUpdateRelationship`, `subCreateEntitlement`,\n * `subCreateAsset`.\n */\n\nimport { useState, type ReactNode } from 'react';\nimport { useParams } from 'react-router';\nimport {\n ArrowLeft,\n Briefcase,\n CreditCard,\n Wallet,\n ShieldCheck,\n CalendarClock,\n Paperclip,\n Activity,\n Tag,\n Pencil,\n Handshake,\n Plus,\n Pause,\n Play,\n Ban,\n Download,\n} from 'lucide-react';\nimport { GlassCard } from '@burdenoff/fe-libs/ui';\nimport { PageLayout } from '../../components/PageLayout';\nimport { StatusBadge } from '../../components/StatusBadge';\nimport { EmptyState } from '../../components/EmptyState';\nimport { Modal } from '../../components/Modal';\nimport { LoadingView, ErrorView, Section } from '../../components/StateViews';\nimport { AiDisclaimer, DecisionCard } from '../../components/decisions';\nimport { Gauge, Timeline, MiniProgress } from '../../components';\nimport type { TimelineItem } from '../../components';\nimport { useSubscriberBot } from '../../context/SubscriberBotContext';\nimport {\n useRelationship,\n useTransitionRelationship,\n useCancelRelationship,\n useUpdateRelationship,\n useCreateEntitlement,\n useCreateAsset,\n useUploadFile,\n useFileDownloadUrl,\n useProviders,\n usePlans,\n useDecisions,\n useInvoices,\n} from '../../hooks/useSubscriberBotApi';\n\nimport { useTr } from '../../hooks/useTr';\nimport { canTransition } from '../../utils/portfolio';\nimport type {\n SubAssetType,\n SubBillingInterval,\n SubEntitlementType,\n SubInvoice,\n SubRelationship,\n SubRelationshipKind,\n SubRelationshipStatus,\n SubUpdateRelationshipInput,\n} from '../../types';\n\nconst inputCls =\n 'w-full rounded-lg border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\nconst labelCls = 'mb-1 block text-xs font-medium text-text-secondary';\n\nconst INTERVALS: SubBillingInterval[] = [\n 'MONTHLY',\n 'YEARLY',\n 'QUARTERLY',\n 'WEEKLY',\n 'DAILY',\n 'USAGE_BASED',\n 'LIFETIME',\n 'FREE',\n];\n\nconst ENTITLEMENT_TYPES: SubEntitlementType[] = [\n 'FEATURE_ACCESS',\n 'SEAT',\n 'USAGE_QUOTA',\n 'CONTENT',\n 'DISCOUNT',\n 'SUPPORT_TIER',\n];\n\nconst ASSET_TYPES: SubAssetType[] = [\n 'RECEIPT',\n 'INVOICE',\n 'CONTRACT',\n 'LICENSE_KEY',\n 'CREDENTIAL',\n 'CERTIFICATE',\n 'WARRANTY',\n 'DOMAIN',\n];\n\nconst KIND_KEY: Record<SubRelationshipKind, string> = {\n SUBSCRIPTION: 'relationships.kinds.subscription',\n MEMBERSHIP: 'relationships.kinds.membership',\n LICENSE: 'relationships.kinds.license',\n CONTRACT: 'relationships.kinds.contract',\n NEWSLETTER: 'relationships.kinds.newsletter',\n RECURRING_PAYMENT: 'relationships.kinds.recurringPayment',\n ENROLLMENT: 'relationships.kinds.enrollment',\n TRIAL: 'relationships.kinds.trial',\n};\n\n// Lifecycle actions surfaced as buttons; the server validates the transition.\nconst TRANSITIONS: Array<{\n status: SubRelationshipStatus;\n labelKey: string;\n defaultLabel: string;\n icon: typeof Play;\n}> = [\n {\n status: 'ACTIVE',\n labelKey: 'relationships.detail.actions.activate',\n defaultLabel: 'Activate',\n icon: Play,\n },\n {\n status: 'PAUSED',\n labelKey: 'relationships.detail.actions.pause',\n defaultLabel: 'Pause',\n icon: Pause,\n },\n {\n status: 'EXPIRED',\n labelKey: 'relationships.detail.actions.markExpired',\n defaultLabel: 'Mark expired',\n icon: Ban,\n },\n];\n\n/** Compact label/value row for the detail info cards. */\nfunction InfoRow({ label, value }: { label: string; value: ReactNode }) {\n return (\n <div className=\"flex items-center justify-between gap-3 border-b border-border-subtle/60 py-2.5 last:border-0 last:pb-0\">\n <span className=\"shrink-0 text-sm text-text-secondary\">{label}</span>\n <span className=\"min-w-0 truncate text-end text-sm font-medium text-text-primary\">\n {value}\n </span>\n </div>\n );\n}\n\n/** Map a 0–100 health score onto a MiniProgress tone. */\nfunction healthTone(\n score: number | null | undefined\n): 'positive' | 'accent' | 'warning' | 'negative' {\n if (score == null) return 'accent';\n if (score >= 66) return 'positive';\n if (score >= 33) return 'warning';\n return 'negative';\n}\n\n/** ISO string → yyyy-mm-dd for a native <input type=\"date\">. */\nfunction toDateInputValue(iso: string | null | undefined): string {\n if (!iso) return '';\n const d = new Date(iso);\n if (Number.isNaN(d.getTime())) return '';\n return d.toISOString().slice(0, 10);\n}\n\n// ---------------------------------------------------------------------------\n// Edit relationship modal → subUpdateRelationship\n// ---------------------------------------------------------------------------\n\nfunction RelationshipEditModal({\n relationship,\n onClose,\n}: {\n relationship: SubRelationship;\n onClose: () => void;\n}) {\n const tr = useTr();\n const update = useUpdateRelationship();\n const providersQ = useProviders({ pagination: { limit: 100, offset: 0 } });\n\n const [label, setLabel] = useState(relationship.label);\n const [providerId, setProviderId] = useState(relationship.providerId ?? '');\n const [planId, setPlanId] = useState(relationship.planId ?? '');\n const [amount, setAmount] = useState(String(relationship.amount ?? ''));\n const [currency, setCurrency] = useState(relationship.currency);\n const [interval, setInterval] = useState<SubBillingInterval>(relationship.interval);\n const [renewsAt, setRenewsAt] = useState(toDateInputValue(relationship.renewsAt));\n const [autoRenew, setAutoRenew] = useState(relationship.autoRenew);\n const [notes, setNotes] = useState(relationship.notes ?? '');\n const [department, setDepartment] = useState(relationship.department ?? '');\n const [formError, setFormError, fieldErrorProps, formErrorId] = useFormError();\n\n const plansQ = usePlans(providerId || undefined);\n\n // Ensure the currently-linked provider is always selectable even if it isn't\n // in the first page of the registry.\n const providerOptions = (() => {\n const list = providersQ.data?.items ?? [];\n if (relationship.provider && !list.some((p) => p.id === relationship.provider?.id)) {\n return [relationship.provider, ...list];\n }\n return list;\n })();\n const plans = plansQ.data ?? [];\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n setFormError(null);\n if (!label.trim()) {\n setFormError(\n tr('relationships.detail.editModal.labelRequired', 'A label is required.'),\n 'edit-label'\n );\n return;\n }\n const input: SubUpdateRelationshipInput = {\n label: label.trim(),\n interval,\n autoRenew,\n currency: currency.trim() || 'USD',\n notes: notes.trim(),\n // Always sent: an empty string clears the department allocation.\n department: department.trim(),\n ...(providerId ? { providerId } : {}),\n ...(planId ? { planId } : {}),\n ...(amount.trim() ? { amount: Number(amount) } : {}),\n ...(renewsAt ? { renewsAt: new Date(renewsAt).toISOString() } : {}),\n };\n update.mutate(\n { id: relationship.id, input },\n {\n onSuccess: () => onClose(),\n onError: (err) =>\n setFormError(\n err instanceof Error\n ? err.message\n : tr('relationships.detail.editModal.error', 'Could not update relationship.')\n ),\n }\n );\n };\n\n return (\n <Modal\n title={tr('relationships.detail.editModal.title', 'Edit relationship')}\n onClose={onClose}\n maxWidthClassName=\"max-w-2xl\"\n >\n <form onSubmit={handleSubmit} className=\"space-y-4\">\n {formError && (\n <div\n id={formErrorId}\n tabIndex={-1}\n role=\"alert\"\n className=\"rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\"\n >\n {formError}\n </div>\n )}\n\n <div>\n <label htmlFor=\"edit-label\" className={labelCls}>\n {tr('relationships.detail.editModal.labelLabel', 'Label')}{' '}\n <span className=\"text-status-error-text\">*</span>\n </label>\n <input\n {...fieldErrorProps('edit-label')}\n id=\"edit-label\"\n type=\"text\"\n value={label}\n onChange={(e) => setLabel(e.target.value)}\n className={inputCls}\n required\n />\n </div>\n\n <div>\n <label htmlFor=\"edit-department\" className={labelCls}>\n {tr('relationships.detail.editModal.departmentLabel', 'Department or team')}\n </label>\n <input\n {...fieldErrorProps('edit-department')}\n id=\"edit-department\"\n type=\"text\"\n maxLength={120}\n value={department}\n onChange={(e) => setDepartment(e.target.value)}\n placeholder={tr(\n 'relationships.detail.editModal.departmentPlaceholder',\n 'e.g. Engineering, Marketing'\n )}\n className={inputCls}\n />\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"edit-provider\" className={labelCls}>\n {tr('relationships.detail.editModal.providerLabel', 'Provider')}\n </label>\n <select\n {...fieldErrorProps('edit-provider')}\n id=\"edit-provider\"\n value={providerId}\n onChange={(e) => {\n setProviderId(e.target.value);\n setPlanId('');\n }}\n className={inputCls}\n >\n <option value=\"\">\n {tr('relationships.detail.editModal.providerNone', '— None —')}\n </option>\n {providerOptions.map((p) => (\n <option key={p.id} value={p.id}>\n {p.name}\n </option>\n ))}\n </select>\n </div>\n <div>\n <label htmlFor=\"edit-plan\" className={labelCls}>\n {tr('relationships.detail.editModal.planLabel', 'Plan')}\n </label>\n <select\n {...fieldErrorProps('edit-plan')}\n id=\"edit-plan\"\n value={planId}\n onChange={(e) => setPlanId(e.target.value)}\n className={inputCls}\n disabled={!providerId || plans.length === 0}\n >\n <option value=\"\">{tr('relationships.detail.editModal.planNone', '— None —')}</option>\n {plans.map((pl) => (\n <option key={pl.id} value={pl.id}>\n {pl.name}\n </option>\n ))}\n </select>\n </div>\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-3\">\n <div>\n <label htmlFor=\"edit-amount\" className={labelCls}>\n {tr('relationships.detail.editModal.amountLabel', 'Amount')}\n </label>\n <input\n {...fieldErrorProps('edit-amount')}\n id=\"edit-amount\"\n type=\"number\"\n min=\"0\"\n step=\"0.01\"\n value={amount}\n onChange={(e) => setAmount(e.target.value)}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"edit-currency\" className={labelCls}>\n {tr('relationships.detail.editModal.currencyLabel', 'Currency')}\n </label>\n <input\n {...fieldErrorProps('edit-currency')}\n id=\"edit-currency\"\n type=\"text\"\n value={currency}\n onChange={(e) => setCurrency(e.target.value.toUpperCase())}\n maxLength={3}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"edit-interval\" className={labelCls}>\n {tr('relationships.detail.editModal.intervalLabel', 'Billing interval')}\n </label>\n <select\n {...fieldErrorProps('edit-interval')}\n id=\"edit-interval\"\n value={interval}\n onChange={(e) => setInterval(e.target.value as SubBillingInterval)}\n className={inputCls}\n >\n {INTERVALS.map((i) => (\n <option key={i} value={i}>\n {i.replace(/_/g, ' ')}\n </option>\n ))}\n </select>\n </div>\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-3\">\n <div>\n <label htmlFor=\"edit-renews\" className={labelCls}>\n {tr('relationships.detail.editModal.renewsOnLabel', 'Renews on')}\n </label>\n <input\n {...fieldErrorProps('edit-renews')}\n id=\"edit-renews\"\n type=\"date\"\n value={renewsAt}\n onChange={(e) => setRenewsAt(e.target.value)}\n className={inputCls}\n />\n </div>\n <div className=\"flex items-end\">\n <label className=\"flex items-center gap-2 text-sm text-text-primary\">\n <input\n type=\"checkbox\"\n checked={autoRenew}\n onChange={(e) => setAutoRenew(e.target.checked)}\n className=\"size-4 rounded border-border-subtle\"\n />\n {tr('relationships.detail.editModal.autoRenews', 'Auto-renews')}\n </label>\n </div>\n </div>\n\n <div>\n <label htmlFor=\"edit-notes\" className={labelCls}>\n {tr('relationships.detail.editModal.notesLabel', 'Notes')}\n </label>\n <textarea\n {...fieldErrorProps('edit-notes')}\n id=\"edit-notes\"\n value={notes}\n onChange={(e) => setNotes(e.target.value)}\n rows={3}\n className={inputCls}\n />\n </div>\n\n <div className=\"flex justify-end gap-3\">\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n {tr('relationships.detail.editModal.cancel', 'Cancel')}\n </button>\n <button\n type=\"submit\"\n disabled={update.isPending}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90 disabled:opacity-50\"\n >\n {update.isPending\n ? tr('relationships.detail.editModal.saving', 'Saving…')\n : tr('relationships.detail.editModal.submit', 'Save changes')}\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Add entitlement modal → subCreateEntitlement\n// ---------------------------------------------------------------------------\n\nfunction AddEntitlementModal({\n relationshipId,\n onClose,\n}: {\n relationshipId: string;\n onClose: () => void;\n}) {\n const tr = useTr();\n const create = useCreateEntitlement();\n const [name, setName] = useState('');\n const [type, setType] = useState<SubEntitlementType>('FEATURE_ACCESS');\n const [quota, setQuota] = useState('');\n const [unit, setUnit] = useState('');\n const [description, setDescription] = useState('');\n const [formError, setFormError, fieldErrorProps, formErrorId] = useFormError();\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n setFormError(null);\n if (!name.trim()) {\n setFormError(\n tr(\n 'relationships.detail.addEntitlementModal.nameRequired',\n 'An entitlement name is required.'\n ),\n 'ent-name'\n );\n return;\n }\n create.mutate(\n {\n relationshipId,\n name: name.trim(),\n type,\n ...(quota.trim() ? { quota: Number(quota) } : {}),\n ...(unit.trim() ? { unit: unit.trim() } : {}),\n ...(description.trim() ? { description: description.trim() } : {}),\n },\n {\n onSuccess: () => onClose(),\n onError: (err) =>\n setFormError(\n err instanceof Error\n ? err.message\n : tr('relationships.detail.addEntitlementModal.error', 'Could not add entitlement.')\n ),\n }\n );\n };\n\n return (\n <Modal\n title={tr('relationships.detail.addEntitlementModal.title', 'Add entitlement')}\n onClose={onClose}\n >\n <form onSubmit={handleSubmit} className=\"space-y-4\">\n {formError && (\n <div\n id={formErrorId}\n tabIndex={-1}\n role=\"alert\"\n className=\"rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\"\n >\n {formError}\n </div>\n )}\n <div>\n <label htmlFor=\"ent-name\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.nameLabel', 'Name')}{' '}\n <span className=\"text-status-error-text\">*</span>\n </label>\n <input\n {...fieldErrorProps('ent-name')}\n id=\"ent-name\"\n type=\"text\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder={tr(\n 'relationships.detail.addEntitlementModal.namePlaceholder',\n 'e.g. Seats, API calls, Priority support'\n )}\n className={inputCls}\n required\n />\n </div>\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-3\">\n <div>\n <label htmlFor=\"ent-type\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.typeLabel', 'Type')}\n </label>\n <select\n {...fieldErrorProps('ent-type')}\n id=\"ent-type\"\n value={type}\n onChange={(e) => setType(e.target.value as SubEntitlementType)}\n className={inputCls}\n >\n {ENTITLEMENT_TYPES.map((t) => (\n <option key={t} value={t}>\n {t.replace(/_/g, ' ')}\n </option>\n ))}\n </select>\n </div>\n <div>\n <label htmlFor=\"ent-quota\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.quotaLabel', 'Quota')}\n </label>\n <input\n {...fieldErrorProps('ent-quota')}\n id=\"ent-quota\"\n type=\"number\"\n min=\"0\"\n value={quota}\n onChange={(e) => setQuota(e.target.value)}\n placeholder={tr(\n 'relationships.detail.addEntitlementModal.quotaPlaceholder',\n 'e.g. 5'\n )}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"ent-unit\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.unitLabel', 'Unit')}\n </label>\n <input\n {...fieldErrorProps('ent-unit')}\n id=\"ent-unit\"\n type=\"text\"\n value={unit}\n onChange={(e) => setUnit(e.target.value)}\n placeholder={tr(\n 'relationships.detail.addEntitlementModal.unitPlaceholder',\n 'e.g. seats, GB'\n )}\n className={inputCls}\n />\n </div>\n </div>\n <div>\n <label htmlFor=\"ent-desc\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.descriptionLabel', 'Description')}\n </label>\n <textarea\n {...fieldErrorProps('ent-desc')}\n id=\"ent-desc\"\n value={description}\n onChange={(e) => setDescription(e.target.value)}\n rows={2}\n className={inputCls}\n />\n </div>\n <div className=\"flex justify-end gap-3\">\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n {tr('relationships.detail.addEntitlementModal.cancel', 'Cancel')}\n </button>\n <button\n type=\"submit\"\n disabled={create.isPending}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90 disabled:opacity-50\"\n >\n {create.isPending\n ? tr('relationships.detail.addEntitlementModal.adding', 'Adding…')\n : tr('relationships.detail.addEntitlementModal.submit', 'Add entitlement')}\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Attach asset modal → upload to files-svc, then subCreateAsset\n// ---------------------------------------------------------------------------\n\nfunction AttachAssetModal({\n relationshipId,\n onClose,\n}: {\n relationshipId: string;\n onClose: () => void;\n}) {\n const tr = useTr();\n const create = useCreateAsset();\n const { uploadFile, progress, isUploading } = useUploadFile();\n const [name, setName] = useState('');\n const [type, setType] = useState<SubAssetType>('RECEIPT');\n const [file, setFile] = useState<File | null>(null);\n const [expiresAt, setExpiresAt] = useState('');\n const [formError, setFormError, fieldErrorProps, formErrorId] = useFormError();\n\n const busy = isUploading || create.isPending;\n\n const handleSubmit = async (e: React.FormEvent) => {\n e.preventDefault();\n setFormError(null);\n if (!file) {\n setFormError(\n tr('relationships.detail.attachAssetModal.chooseFile', 'Choose a file to attach.'),\n 'asset-file'\n );\n return;\n }\n try {\n const { fileId, fileName } = await uploadFile(file);\n await create.mutateAsync({\n relationshipId,\n name: name.trim() || fileName,\n type,\n fileId,\n ...(expiresAt ? { expiresAt: new Date(expiresAt).toISOString() } : {}),\n });\n onClose();\n } catch (err) {\n setFormError(\n err instanceof Error\n ? err.message\n : tr('relationships.detail.attachAssetModal.error', 'Could not attach the asset.')\n );\n }\n };\n\n return (\n <Modal\n title={tr('relationships.detail.attachAssetModal.title', 'Attach asset')}\n onClose={onClose}\n >\n <form onSubmit={handleSubmit} className=\"space-y-4\">\n {formError && (\n <div\n id={formErrorId}\n tabIndex={-1}\n role=\"alert\"\n className=\"rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\"\n >\n {formError}\n </div>\n )}\n <div>\n <label htmlFor=\"asset-file\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.fileLabel', 'File')}{' '}\n <span className=\"text-status-error-text\">*</span>\n </label>\n <input\n {...fieldErrorProps('asset-file')}\n id=\"asset-file\"\n type=\"file\"\n onChange={(e) => {\n const f = e.target.files?.[0] ?? null;\n setFile(f);\n if (f && !name.trim()) setName(f.name);\n }}\n className=\"w-full text-sm text-text-secondary file:me-3 file:rounded-lg file:border file:border-border-subtle file:bg-bg-surface file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-text-primary hover:file:bg-bg-sunken\"\n />\n <p className=\"mt-1 text-xs text-text-secondary\">\n {tr(\n 'relationships.detail.attachAssetModal.fileHint',\n 'Stored securely in files — only a reference is kept here.'\n )}\n </p>\n </div>\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"asset-name\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.nameLabel', 'Name')}\n </label>\n <input\n {...fieldErrorProps('asset-name')}\n id=\"asset-name\"\n type=\"text\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder={tr(\n 'relationships.detail.attachAssetModal.namePlaceholder',\n 'Defaults to the file name'\n )}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"asset-type\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.typeLabel', 'Type')}\n </label>\n <select\n {...fieldErrorProps('asset-type')}\n id=\"asset-type\"\n value={type}\n onChange={(e) => setType(e.target.value as SubAssetType)}\n className={inputCls}\n >\n {ASSET_TYPES.map((t) => (\n <option key={t} value={t}>\n {t.replace(/_/g, ' ')}\n </option>\n ))}\n </select>\n </div>\n </div>\n <div>\n <label htmlFor=\"asset-expires\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.expiresOnLabel', 'Expires on')}\n </label>\n <input\n {...fieldErrorProps('asset-expires')}\n id=\"asset-expires\"\n type=\"date\"\n value={expiresAt}\n onChange={(e) => setExpiresAt(e.target.value)}\n className={inputCls}\n />\n </div>\n {isUploading && (\n <p className=\"text-xs text-text-secondary\">\n {tr('relationships.detail.attachAssetModal.uploading', 'Uploading… {{progress}}%', {\n progress,\n })}\n </p>\n )}\n <div className=\"flex justify-end gap-3\">\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n {tr('relationships.detail.attachAssetModal.cancel', 'Cancel')}\n </button>\n <button\n type=\"submit\"\n disabled={busy}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90 disabled:opacity-50\"\n >\n {busy\n ? tr('relationships.detail.attachAssetModal.attaching', 'Attaching…')\n : tr('relationships.detail.attachAssetModal.submit', 'Attach asset')}\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Asset row — resolves a presigned download URL on demand\n// ---------------------------------------------------------------------------\n\nfunction AssetRow({ asset }: { asset: NonNullable<SubRelationship['assets']>[number] }) {\n const { formatDate, formatEnumLabel } = useFormatters();\n\n const tr = useTr();\n const getDownloadUrl = useFileDownloadUrl();\n const [downloading, setDownloading] = useState(false);\n\n const handleDownload = async () => {\n if (!asset.file?.id) return;\n setDownloading(true);\n try {\n const url = await getDownloadUrl(asset.file.id);\n window.open(url, '_blank', 'noopener,noreferrer');\n } catch {\n // Non-fatal: a broken/expired file reference just can't be downloaded.\n } finally {\n setDownloading(false);\n }\n };\n\n return (\n <div className=\"flex items-center justify-between gap-3 p-3\">\n <div className=\"flex min-w-0 items-center gap-2\">\n <Paperclip className=\"h-4 w-4 shrink-0 text-text-secondary\" />\n <div className=\"min-w-0\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{asset.name}</p>\n <p className=\"text-xs text-text-secondary\">{formatEnumLabel(asset.type)}</p>\n </div>\n </div>\n <div className=\"flex shrink-0 items-center gap-3\">\n {asset.expiresAt && (\n <span className=\"text-xs text-text-secondary\">\n {tr('relationships.detail.assetRow.expires', 'Expires {{date}}', {\n date: formatDate(asset.expiresAt),\n })}\n </span>\n )}\n {asset.file?.id && (\n <button\n type=\"button\"\n onClick={handleDownload}\n disabled={downloading}\n className=\"inline-flex items-center gap-1 rounded-lg border border-border-subtle px-2.5 py-1 text-xs font-medium text-text-primary hover:bg-bg-sunken disabled:opacity-50\"\n >\n <Download className=\"h-3.5 w-3.5\" />{' '}\n {downloading\n ? tr('relationships.detail.assetRow.opening', 'Opening…')\n : tr('relationships.detail.assetRow.download', 'Download')}\n </button>\n )}\n </div>\n </div>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Invoice row (BOFF-8659) — every invoice linked to this relationship via\n// `SubInvoice.relationshipId` is shown in the Assets section alongside any\n// file-based assets, so users don't have to leave the relationship page to\n// discover that they have an outstanding invoice tied to it.\n// ---------------------------------------------------------------------------\n\nfunction InvoiceRow({ invoice }: { invoice: SubInvoice }) {\n const { formatCurrency, formatDate, formatEnumLabel } = useFormatters();\n\n const tr = useTr();\n // Each invoice appears once, grouped by the (most-recent) due or issue\n // date and labelled with number · status, then a right-aligned total that\n // matches the Invoices list currency formatting.\n const label =\n invoice.number ?? tr('relationships.detail.invoiceRow.unnumbered', 'Unnumbered invoice');\n return (\n <div className=\"flex items-center justify-between gap-3 p-3\">\n <div className=\"flex min-w-0 items-center gap-2\">\n <CreditCard className=\"h-4 w-4 shrink-0 text-text-secondary\" />\n <div className=\"min-w-0\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{label}</p>\n <p className=\"text-xs text-text-secondary\">\n {formatEnumLabel(invoice.status)}\n {invoice.dueDate\n ? ` · ${tr('relationships.detail.invoiceRow.due', 'due {{date}}', {\n date: formatDate(invoice.dueDate),\n })}`\n : invoice.issueDate\n ? ` · ${formatDate(invoice.issueDate)}`\n : ''}\n </p>\n </div>\n </div>\n <span className=\"shrink-0 text-sm font-medium tabular-nums text-text-primary\">\n {formatCurrency(invoice.total, invoice.currency)}\n </span>\n </div>\n );\n}\n\nexport function RelationshipDetailPage() {\n const { formatCurrency, formatDate, formatEnumLabel, formatIntervalSuffix } = useFormatters();\n\n const tr = useTr();\n const { id } = useParams<{ id: string }>();\n const { navigateTo } = useSubscriberBot();\n const { data: relationship, isLoading, isError, refetch } = useRelationship(id);\n const transition = useTransitionRelationship();\n const cancel = useCancelRelationship();\n const [actionError, setActionError] = useState<string | null>(null);\n const [showEdit, setShowEdit] = useState(false);\n const [showAddEntitlement, setShowAddEntitlement] = useState(false);\n const [showAttachAsset, setShowAttachAsset] = useState(false);\n // Open AI recommendations about this subscription (BOFF-3663). Best effort:\n // if the decision engine is unavailable the section is simply omitted, and\n // every change it could propose stays available through the actions above.\n // Invoices linked through SubInvoice.relationshipId (BOFF-8659). The svc\n // exposes them through subListInvoices(relationshipId), not as a field on\n // SubRelationship, so they are read with their own query.\n const relationshipInvoices = useInvoices(\n { relationshipId: id, pagination: { limit: 50, offset: 0 } },\n { enabled: Boolean(id) }\n );\n const openDecisions = useDecisions(\n { relationshipId: id, status: 'PROPOSED' },\n { enabled: Boolean(id) }\n );\n\n if (isLoading) {\n return (\n <PageLayout title={tr('relationships.title', 'Relationship')}>\n <LoadingView label={tr('relationships.detail.loading', 'Loading relationship…')} />\n </PageLayout>\n );\n }\n\n if (isError) {\n return (\n <PageLayout title={tr('relationships.title', 'Relationship')}>\n <ErrorView\n message={tr('relationships.detail.error', 'Could not load this relationship.')}\n onRetry={() => void refetch()}\n />\n </PageLayout>\n );\n }\n\n if (!relationship) {\n return (\n <PageLayout title={tr('relationships.title', 'Relationship')}>\n <EmptyState\n illustration=\"empty-data\"\n title={tr('relationships.detail.notFoundTitle', 'Relationship not found')}\n description={tr(\n 'relationships.detail.notFoundDescription',\n 'It may have been removed, or you may not have access to it.'\n )}\n action={\n <button\n type=\"button\"\n onClick={() => navigateTo('/relationships')}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90\"\n >\n {tr('relationships.detail.backToRelationships', 'Back to relationships')}\n </button>\n }\n />\n </PageLayout>\n );\n }\n\n const r = relationship;\n const isBusy = transition.isPending || cancel.isPending;\n\n const runTransition = (status: SubRelationshipStatus) => {\n setActionError(null);\n transition.mutate(\n { id: r.id, status },\n {\n onError: (e) =>\n setActionError(\n e instanceof Error\n ? e.message\n : tr('relationships.detail.transitionError', 'Transition failed')\n ),\n }\n );\n };\n\n const runCancel = () => {\n setActionError(null);\n cancel.mutate(r.id, {\n onError: (e) =>\n setActionError(\n e instanceof Error ? e.message : tr('relationships.detail.cancelError', 'Cancel failed')\n ),\n });\n };\n\n // Renewal timeline — built entirely from the real renewalEvents, oldest → newest.\n const renewalTimeline: TimelineItem[] = [...(r.renewalEvents ?? [])]\n .sort((a, b) => new Date(a.occursAt).getTime() - new Date(b.occursAt).getTime())\n .map((event) => {\n const ts = new Date(event.occursAt).getTime();\n const isFuture = !Number.isNaN(ts) && ts > Date.now();\n return {\n title: formatEnumLabel(event.eventType),\n sub: `${formatDate(event.occursAt)}${event.detail ? ` · ${event.detail}` : ''}`,\n meta:\n event.amount != null\n ? formatCurrency(event.amount, event.currency ?? r.currency)\n : undefined,\n tone: isFuture ? 'warning' : 'muted',\n };\n });\n\n const autoRenewPill = r.autoRenew ? (\n <span className=\"inline-flex items-center rounded-full bg-status-success-bg-subtle px-2 py-0.5 text-xs font-medium text-status-success-text\">\n {tr('relationships.detail.autoRenewOn', 'On')}\n </span>\n ) : (\n <span className=\"inline-flex items-center rounded-full bg-bg-sunken px-2 py-0.5 text-xs font-medium text-text-secondary\">\n {tr('relationships.detail.autoRenewOff', 'Off')}\n </span>\n );\n\n // Only offer transitions the svc state machine accepts from the current\n // status (a cancelled relationship no longer shows Activate / Pause).\n const availableTransitions = TRANSITIONS.filter((t) => canTransition(r.status, t.status));\n const planFeatures = r.plan?.features ?? [];\n\n return (\n <PageLayout\n title={r.label}\n description={r.provider?.name ?? tr(KIND_KEY[r.kind], formatEnumLabel(r.kind))}\n actions={\n <div className=\"flex flex-wrap items-center gap-2\">\n <button\n type=\"button\"\n onClick={() => setShowEdit(true)}\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Pencil className=\"h-4 w-4\" /> {tr('relationships.detail.edit', 'Edit')}\n </button>\n <button\n type=\"button\"\n data-testid=\"negotiate-bill\"\n onClick={() =>\n navigateTo(`/negotiations/new?relationshipId=${encodeURIComponent(r.id)}`)\n }\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Handshake className=\"h-4 w-4\" />{' '}\n {tr('relationships.detail.negotiate', 'Negotiate this bill')}\n </button>\n <button\n type=\"button\"\n data-testid=\"request-procurement\"\n onClick={() =>\n navigateTo(`/procurement/new?relationshipId=${encodeURIComponent(r.id)}`)\n }\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Briefcase className=\"h-4 w-4\" />{' '}\n {tr('relationships.detail.procurement', 'Ask an expert to negotiate')}\n </button>\n <button\n type=\"button\"\n onClick={() => navigateTo('/relationships')}\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <ArrowLeft className=\"rtl:rotate-180 h-4 w-4\" />{' '}\n {tr('relationships.detail.back', 'Back')}\n </button>\n </div>\n }\n >\n {/* Hero summary + lifecycle actions */}\n <GlassCard treatment=\"glass\" glow className=\"p-5 sm:p-6\">\n <div className=\"flex flex-col gap-5 lg:flex-row lg:items-start lg:justify-between\">\n <div className=\"min-w-0\">\n <p className=\"text-xs font-medium uppercase tracking-wide text-text-secondary\">\n {tr(KIND_KEY[r.kind], formatEnumLabel(r.kind))}\n </p>\n <div className=\"mt-2 flex flex-wrap items-center gap-3\">\n <span className=\"text-3xl font-bold tabular-nums text-text-primary\">\n {formatCurrency(r.amount, r.currency)}\n <span className=\"text-base font-normal text-text-secondary\">\n {formatIntervalSuffix(r.interval)}\n </span>\n </span>\n <StatusBadge status={r.status} />\n </div>\n <div className=\"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm text-text-secondary\">\n <span className=\"inline-flex items-center gap-1.5\">\n <CalendarClock className=\"h-3.5 w-3.5\" />\n {r.renewsAt\n ? tr('relationships.detail.renews', 'Renews {{date}}', {\n date: formatDate(r.renewsAt),\n })\n : tr('relationships.detail.noRenewalScheduled', 'No renewal scheduled')}\n </span>\n <span className=\"inline-flex items-center gap-1.5\">\n <ShieldCheck className=\"h-3.5 w-3.5\" />\n {formatEnumLabel(r.discoverySource)}\n </span>\n <span className=\"inline-flex items-center gap-1.5\">\n {tr('relationships.detail.autoRenew', 'Auto-renew')} {autoRenewPill}\n </span>\n </div>\n {r.tags.length > 0 && (\n <div className=\"mt-3 flex flex-wrap items-center gap-2\">\n <Tag className=\"h-3.5 w-3.5 text-text-secondary\" />\n {r.tags.map((tag) => (\n <span\n key={tag}\n className=\"rounded-full bg-bg-sunken px-2.5 py-0.5 text-xs text-text-secondary\"\n >\n {tag}\n </span>\n ))}\n </div>\n )}\n </div>\n\n {/* Lifecycle actions */}\n <div className=\"grid shrink-0 grid-cols-2 gap-2 sm:flex sm:flex-wrap lg:flex-col lg:items-stretch\">\n {availableTransitions.map((t) => {\n const Icon = t.icon;\n return (\n <button\n key={t.status}\n type=\"button\"\n disabled={isBusy}\n onClick={() => runTransition(t.status)}\n className=\"inline-flex min-h-11 items-center justify-center gap-1.5 rounded-lg border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm sm:min-h-0 sm:text-xs font-medium text-text-primary hover:bg-bg-sunken disabled:opacity-50\"\n >\n <Icon className=\"h-3.5 w-3.5\" /> {tr(t.labelKey, t.defaultLabel)}\n </button>\n );\n })}\n {canTransition(r.status, 'CANCELLED') && (\n <button\n type=\"button\"\n disabled={isBusy}\n onClick={runCancel}\n className=\"inline-flex min-h-11 items-center justify-center gap-1.5 rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-3 py-1.5 text-sm sm:min-h-0 sm:text-xs font-medium text-status-error-text hover:opacity-90 disabled:opacity-50\"\n >\n <Ban className=\"h-3.5 w-3.5\" />{' '}\n {tr('relationships.detail.actions.cancel', 'Cancel')}\n </button>\n )}\n </div>\n </div>\n </GlassCard>\n\n {actionError && (\n <div className=\"mt-4 rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\">\n {actionError}\n </div>\n )}\n\n {/* Main layout: details (left) + health & timeline rail (right) */}\n <div className=\"mt-6 grid grid-cols-1 gap-4 lg:grid-cols-3\">\n <div className=\"space-y-4 lg:col-span-2\">\n <div className=\"grid grid-cols-1 gap-4 md:grid-cols-2\">\n {/* Plan & pricing */}\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <CreditCard className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.planPricing', 'Plan & pricing')}\n </div>\n <div className=\"mt-3\">\n <InfoRow\n label={tr('relationships.detail.info.plan', 'Plan')}\n value={r.plan?.name ?? '—'}\n />\n <InfoRow\n label={tr('relationships.detail.info.price', 'Price')}\n value={\n <>\n {formatCurrency(r.amount, r.currency)}\n <span className=\"font-normal text-text-secondary\">\n {formatIntervalSuffix(r.interval)}\n </span>\n </>\n }\n />\n <InfoRow\n label={tr('relationships.detail.info.billingInterval', 'Billing interval')}\n value={formatEnumLabel(r.interval)}\n />\n <InfoRow\n label={tr('relationships.detail.info.provider', 'Provider')}\n value={r.provider?.name ?? '—'}\n />\n </div>\n {planFeatures.length > 0 && (\n <div className=\"mt-3 flex flex-wrap gap-1.5\">\n {planFeatures.map((f) => (\n <span\n key={f}\n className=\"rounded-full bg-bg-sunken px-2.5 py-0.5 text-xs text-text-secondary\"\n >\n {f}\n </span>\n ))}\n </div>\n )}\n </GlassCard>\n\n {/* Payment & billing */}\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Wallet className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.paymentBilling', 'Payment & billing')}\n </div>\n <div className=\"mt-3\">\n <InfoRow\n label={tr('relationships.detail.info.currency', 'Currency')}\n value={r.currency}\n />\n <InfoRow\n label={tr('relationships.detail.info.autoRenew', 'Auto-renew')}\n value={autoRenewPill}\n />\n <InfoRow\n label={tr('relationships.detail.info.nextRenewal', 'Next renewal')}\n value={r.renewsAt ? formatDate(r.renewsAt) : '—'}\n />\n <InfoRow\n label={tr('relationships.detail.info.started', 'Started')}\n value={r.startedAt ? formatDate(r.startedAt) : '—'}\n />\n {r.trialEndsAt && (\n <InfoRow\n label={tr('relationships.detail.info.trialEnds', 'Trial ends')}\n value={formatDate(r.trialEndsAt)}\n />\n )}\n </div>\n </GlassCard>\n </div>\n\n {/* Open AI recommendations for this subscription */}\n {(openDecisions.data?.items.length ?? 0) > 0 && (\n <Section\n className=\"mt-0\"\n title={tr('relationships.detail.sections.aiRecommendations', 'AI recommendations')}\n description={tr(\n 'relationships.detail.sections.aiRecommendationsDescription',\n 'Open recommendations about this subscription. You can also make any of these changes by hand above.'\n )}\n >\n <AiDisclaimer className=\"mb-3\" />\n <div className=\"grid grid-cols-1 gap-3\" data-testid=\"relationship-decisions\">\n {openDecisions.data?.items.map((d) => (\n <DecisionCard key={d.id} decision={d} />\n ))}\n </div>\n </Section>\n )}\n\n {/* Entitlements */}\n <Section\n className=\"mt-0\"\n title={tr('relationships.detail.sections.entitlements', 'Entitlements')}\n description={tr(\n 'relationships.detail.sections.entitlementsDescription',\n 'What this relationship grants you'\n )}\n action={\n <button\n type=\"button\"\n onClick={() => setShowAddEntitlement(true)}\n className=\"inline-flex items-center gap-1.5 rounded-lg border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Plus className=\"h-3.5 w-3.5\" />{' '}\n {tr('relationships.detail.sections.addEntitlement', 'Add entitlement')}\n </button>\n }\n >\n {!r.entitlements || r.entitlements.length === 0 ? (\n <EmptyState\n illustration=\"empty-data\"\n title={tr('relationships.detail.empty.noEntitlementsTitle', 'No entitlements')}\n description={tr(\n 'relationships.detail.empty.noEntitlementsDescription',\n 'Entitlements (seats, quotas, feature access) will appear here.'\n )}\n />\n ) : (\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2\">\n {r.entitlements.map((e) => {\n const hasQuota = e.quota != null && e.quota > 0;\n return (\n <GlassCard key={e.id} treatment=\"plain\" className=\"p-4\">\n <div className=\"flex items-start justify-between gap-2\">\n <p className=\"min-w-0 truncate text-sm font-medium text-text-primary\">\n {e.name}\n </p>\n <StatusBadge status={e.isActive ? 'ACTIVE' : 'DISABLED'} />\n </div>\n <p className=\"mt-1 text-xs text-text-secondary\">{formatEnumLabel(e.type)}</p>\n {hasQuota && (\n <div className=\"mt-3\">\n <div className=\"flex items-center justify-between text-xs text-text-secondary\">\n <span>\n {e.used} / {e.quota}\n {e.unit ? ` ${e.unit}` : ''}\n </span>\n <span className=\"tabular-nums\">\n {Math.round((e.used / (e.quota as number)) * 100)}%\n </span>\n </div>\n <MiniProgress\n label={tr('common.quotaUtilization', 'Quota utilization')}\n value={e.used}\n max={e.quota as number}\n tone={\n e.used / (e.quota as number) >= 0.9\n ? 'negative'\n : e.used / (e.quota as number) >= 0.7\n ? 'warning'\n : 'accent'\n }\n className=\"mt-1.5\"\n />\n </div>\n )}\n </GlassCard>\n );\n })}\n </div>\n )}\n </Section>\n\n {/* Assets — file-based assets + relationship-owned invoices.\n BOFF-8659: invoices linked via `SubInvoice.relationshipId` are now\n shown here too, so the panel copy \"Invoices, contracts, licenses\n and credentials\" is honored for the cross-module Relationships ↔\n Invoices flow. */}\n <Section\n className=\"mt-0\"\n title={tr('relationships.detail.sections.assets', 'Assets')}\n description={tr(\n 'relationships.detail.sections.assetsDescription',\n 'Invoices, contracts, licenses and credentials'\n )}\n action={\n <button\n type=\"button\"\n onClick={() => setShowAttachAsset(true)}\n className=\"inline-flex items-center gap-1.5 rounded-lg border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Plus className=\"h-3.5 w-3.5\" />{' '}\n {tr('relationships.detail.sections.attachAsset', 'Attach asset')}\n </button>\n }\n >\n {(() => {\n const assets = r.assets ?? [];\n // BOFF-8659 — pull relationship-owned invoices into the same\n // Assets list, sorted next to file-based assets by their sort\n // time so invoices appear in the same order as the Invoices\n // list (newest first).\n const invoices: SubInvoice[] = relationshipInvoices.data?.items ?? [];\n const hasAny = assets.length > 0 || invoices.length > 0;\n if (!hasAny) {\n return (\n <EmptyState\n illustration=\"empty-data\"\n title={tr('relationships.detail.empty.noAssetsTitle', 'No assets attached')}\n description={tr(\n 'relationships.detail.empty.noAssetsDescription',\n 'Attach invoices, contracts, licenses or receipts to this relationship.'\n )}\n />\n );\n }\n type AssetLike =\n | {\n kind: 'asset';\n sort: number;\n asset: NonNullable<SubRelationship['assets']>[number];\n }\n | {\n kind: 'invoice';\n sort: number;\n invoice: SubInvoice;\n };\n const combined: AssetLike[] = [\n ...assets.map((a) => ({\n kind: 'asset' as const,\n sort: new Date(a.createdAt).getTime() || 0,\n asset: a,\n })),\n ...invoices.map((i) => ({\n kind: 'invoice' as const,\n sort: new Date(i.createdAt).getTime() || 0,\n invoice: i,\n })),\n ].sort((x, y) => y.sort - x.sort);\n return (\n <GlassCard treatment=\"plain\" className=\"divide-y divide-border-subtle p-0\">\n {combined.map((row) =>\n row.kind === 'asset' ? (\n <AssetRow key={`a-${row.asset.id}`} asset={row.asset} />\n ) : (\n <InvoiceRow key={`i-${row.invoice.id}`} invoice={row.invoice} />\n )\n )}\n </GlassCard>\n );\n })()}\n </Section>\n\n {r.notes && (\n <GlassCard treatment=\"plain\" className=\"p-4\">\n <p className=\"text-xs font-medium text-text-secondary\">\n {tr('relationships.detail.sections.notes', 'Notes')}\n </p>\n <p className=\"mt-1 whitespace-pre-wrap text-sm text-text-primary\">{r.notes}</p>\n </GlassCard>\n )}\n </div>\n\n {/* Right rail: health gauge + renewal timeline */}\n <div className=\"space-y-4\">\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Activity className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.healthScore', 'Health score')}\n </div>\n {r.healthScore != null ? (\n <div className=\"mt-4 flex flex-col items-center\">\n <Gauge\n value={r.healthScore}\n max={100}\n size={160}\n label={tr('relationships.detail.outOf100', 'of 100')}\n />\n <div className=\"mt-2 w-full\">\n <MiniProgress\n label={tr('common.healthScore', 'Health score')}\n value={r.healthScore}\n max={100}\n tone={healthTone(r.healthScore)}\n />\n </div>\n <p\n className=\"mt-3 text-center text-xs text-text-secondary\"\n data-testid=\"health-score-basis\"\n >\n {tr(\n 'relationships.detail.healthScoreBasis',\n 'Computed from usage, payment history, price stability and overlap with your other subscriptions.'\n )}\n </p>\n </div>\n ) : (\n <p className=\"mt-4 text-sm text-text-secondary\">\n {tr(\n 'relationships.detail.empty.noHealthScore',\n 'Not scored yet. A health score appears once Subscriber Bot has enough signal.'\n )}\n </p>\n )}\n </GlassCard>\n\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <CalendarClock className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.renewalTimeline', 'Renewal timeline')}\n </div>\n <p className=\"mt-0.5 text-xs text-text-secondary\">\n {tr(\n 'relationships.detail.sections.renewalTimelineDescription',\n 'Detected renewals and price changes'\n )}\n </p>\n {renewalTimeline.length === 0 ? (\n <div className=\"mt-4\">\n <EmptyState\n illustration=\"empty-calendar\"\n title={tr('relationships.detail.empty.noRenewalEventsTitle', 'No renewal events')}\n description={tr(\n 'relationships.detail.empty.noRenewalEventsDescription',\n \"Renewals and price changes will appear here as they're detected.\"\n )}\n />\n </div>\n ) : (\n <Timeline items={renewalTimeline} className=\"mt-4\" />\n )}\n </GlassCard>\n </div>\n </div>\n\n {showEdit && <RelationshipEditModal relationship={r} onClose={() => setShowEdit(false)} />}\n {showAddEntitlement && (\n <AddEntitlementModal relationshipId={r.id} onClose={() => setShowAddEntitlement(false)} />\n )}\n {showAttachAsset && (\n <AttachAssetModal relationshipId={r.id} onClose={() => setShowAttachAsset(false)} />\n )}\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwEA,IAAM,IACJ,wMACI,IAAW,sDAEX,IAAkC;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,IAA0C;CAC9C;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,IAA8B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,KAAgD;CACpD,cAAc;CACd,YAAY;CACZ,SAAS;CACT,UAAU;CACV,YAAY;CACZ,mBAAmB;CACnB,YAAY;CACZ,OAAO;AACT,GAGM,KAKD;CACH;EACE,QAAQ;EACR,UAAU;EACV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sB,EAAK;GAAI,CAAA;GAE1F,MACC,kBAAC,IAAD;IAAkB,gBAAgB,EAAE;IAAI,eAAe,EAAmB,EAAK;GAAI,CAAA;EAE3E;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"RelationshipDetailPage.js","names":[],"sources":["../../../../src/subscriberbot/pages/relationships/RelationshipDetailPage.tsx"],"sourcesContent":["import { useFormatters } from '../../hooks/useFormatters';\nimport { useFormError } from '../../hooks/useFormError';\n/**\n * Relationship detail\n * @module subscriberbot/pages/relationships\n *\n * Full per-relationship view: plan, price, billing period, next renewal,\n * health score, entitlements, attached assets and renewal events — plus\n * lifecycle transitions (validated server-side), edit, and cancel.\n * Reads `subRelationship(id)`; writes `subTransitionRelationship`,\n * `subCancelRelationship`, `subUpdateRelationship`, `subCreateEntitlement`,\n * `subCreateAsset`.\n */\n\nimport { useState, type ReactNode } from 'react';\nimport { useParams } from 'react-router';\nimport {\n ArrowLeft,\n Briefcase,\n CreditCard,\n Wallet,\n ShieldCheck,\n CalendarClock,\n Paperclip,\n Activity,\n Tag,\n Pencil,\n Handshake,\n Plus,\n Pause,\n Play,\n Ban,\n Download,\n} from 'lucide-react';\nimport { GlassCard } from '@burdenoff/fe-libs/ui';\nimport { PageLayout } from '../../components/PageLayout';\nimport { StatusBadge } from '../../components/StatusBadge';\nimport { EmptyState } from '../../components/EmptyState';\nimport { Modal } from '../../components/Modal';\nimport { LoadingView, ErrorView, Section } from '../../components/StateViews';\nimport { AiDisclaimer, DecisionCard } from '../../components/decisions';\nimport { Gauge, Timeline, MiniProgress } from '../../components';\nimport type { TimelineItem } from '../../components';\nimport { useSubscriberBot } from '../../context/SubscriberBotContext';\nimport {\n useRelationship,\n useTransitionRelationship,\n useCancelRelationship,\n useUpdateRelationship,\n useCreateEntitlement,\n useCreateAsset,\n useUploadFile,\n useFileDownloadUrl,\n useProviders,\n usePlans,\n useDecisions,\n useInvoices,\n} from '../../hooks/useSubscriberBotApi';\n\nimport { useTr } from '../../hooks/useTr';\nimport { canTransition } from '../../utils/portfolio';\nimport type {\n SubAssetType,\n SubBillingInterval,\n SubEntitlementType,\n SubInvoice,\n SubRelationship,\n SubRelationshipKind,\n SubRelationshipStatus,\n SubUpdateRelationshipInput,\n} from '../../types';\n\nconst inputCls =\n 'w-full rounded-lg border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\nconst labelCls = 'mb-1 block text-xs font-medium text-text-secondary';\n\nconst INTERVALS: SubBillingInterval[] = [\n 'MONTHLY',\n 'YEARLY',\n 'QUARTERLY',\n 'WEEKLY',\n 'DAILY',\n 'USAGE_BASED',\n 'LIFETIME',\n 'FREE',\n];\n\nconst ENTITLEMENT_TYPES: SubEntitlementType[] = [\n 'FEATURE_ACCESS',\n 'SEAT',\n 'USAGE_QUOTA',\n 'CONTENT',\n 'DISCOUNT',\n 'SUPPORT_TIER',\n];\n\nconst ASSET_TYPES: SubAssetType[] = [\n 'RECEIPT',\n 'INVOICE',\n 'CONTRACT',\n 'LICENSE_KEY',\n 'CREDENTIAL',\n 'CERTIFICATE',\n 'WARRANTY',\n 'DOMAIN',\n];\n\nconst KIND_KEY: Record<SubRelationshipKind, string> = {\n SUBSCRIPTION: 'relationships.kinds.subscription',\n MEMBERSHIP: 'relationships.kinds.membership',\n LICENSE: 'relationships.kinds.license',\n CONTRACT: 'relationships.kinds.contract',\n NEWSLETTER: 'relationships.kinds.newsletter',\n RECURRING_PAYMENT: 'relationships.kinds.recurringPayment',\n ENROLLMENT: 'relationships.kinds.enrollment',\n TRIAL: 'relationships.kinds.trial',\n};\n\n// Lifecycle actions surfaced as buttons; the server validates the transition.\nconst TRANSITIONS: Array<{\n status: SubRelationshipStatus;\n labelKey: string;\n defaultLabel: string;\n icon: typeof Play;\n}> = [\n {\n status: 'ACTIVE',\n labelKey: 'relationships.detail.actions.activate',\n defaultLabel: 'Activate',\n icon: Play,\n },\n {\n status: 'PAUSED',\n labelKey: 'relationships.detail.actions.pause',\n defaultLabel: 'Pause',\n icon: Pause,\n },\n {\n status: 'EXPIRED',\n labelKey: 'relationships.detail.actions.markExpired',\n defaultLabel: 'Mark expired',\n icon: Ban,\n },\n];\n\n/** Compact label/value row for the detail info cards. */\nfunction InfoRow({ label, value }: { label: string; value: ReactNode }) {\n return (\n <div className=\"flex items-center justify-between gap-3 border-b border-border-subtle/60 py-2.5 last:border-0 last:pb-0\">\n <span className=\"shrink-0 text-sm text-text-secondary\">{label}</span>\n <span className=\"min-w-0 truncate text-end text-sm font-medium text-text-primary\">\n {value}\n </span>\n </div>\n );\n}\n\n/** Map a 0–100 health score onto a MiniProgress tone. */\nfunction healthTone(\n score: number | null | undefined\n): 'positive' | 'accent' | 'warning' | 'negative' {\n if (score == null) return 'accent';\n if (score >= 66) return 'positive';\n if (score >= 33) return 'warning';\n return 'negative';\n}\n\n/** ISO string → yyyy-mm-dd for a native <input type=\"date\">. */\nfunction toDateInputValue(iso: string | null | undefined): string {\n if (!iso) return '';\n const d = new Date(iso);\n if (Number.isNaN(d.getTime())) return '';\n return d.toISOString().slice(0, 10);\n}\n\n// ---------------------------------------------------------------------------\n// Edit relationship modal → subUpdateRelationship\n// ---------------------------------------------------------------------------\n\nfunction RelationshipEditModal({\n relationship,\n onClose,\n}: {\n relationship: SubRelationship;\n onClose: () => void;\n}) {\n const tr = useTr();\n const update = useUpdateRelationship();\n const providersQ = useProviders({ pagination: { limit: 100, offset: 0 } });\n\n const [label, setLabel] = useState(relationship.label);\n const [providerId, setProviderId] = useState(relationship.providerId ?? '');\n const [planId, setPlanId] = useState(relationship.planId ?? '');\n const [amount, setAmount] = useState(String(relationship.amount ?? ''));\n const [currency, setCurrency] = useState(relationship.currency);\n const [interval, setInterval] = useState<SubBillingInterval>(relationship.interval);\n const [renewsAt, setRenewsAt] = useState(toDateInputValue(relationship.renewsAt));\n const [autoRenew, setAutoRenew] = useState(relationship.autoRenew);\n const [notes, setNotes] = useState(relationship.notes ?? '');\n const [department, setDepartment] = useState(relationship.department ?? '');\n const [formError, setFormError, fieldErrorProps, formErrorId] = useFormError();\n\n const plansQ = usePlans(providerId || undefined);\n\n // Ensure the currently-linked provider is always selectable even if it isn't\n // in the first page of the registry.\n const providerOptions = (() => {\n const list = providersQ.data?.items ?? [];\n if (relationship.provider && !list.some((p) => p.id === relationship.provider?.id)) {\n return [relationship.provider, ...list];\n }\n return list;\n })();\n const plans = plansQ.data ?? [];\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n setFormError(null);\n if (!label.trim()) {\n setFormError(\n tr('relationships.detail.editModal.labelRequired', 'A label is required.'),\n 'edit-label'\n );\n return;\n }\n const input: SubUpdateRelationshipInput = {\n label: label.trim(),\n interval,\n autoRenew,\n currency: currency.trim() || 'USD',\n notes: notes.trim(),\n // Always sent: an empty string clears the department allocation.\n department: department.trim(),\n ...(providerId ? { providerId } : {}),\n ...(planId ? { planId } : {}),\n ...(amount.trim() ? { amount: Number(amount) } : {}),\n ...(renewsAt ? { renewsAt: new Date(renewsAt).toISOString() } : {}),\n };\n update.mutate(\n { id: relationship.id, input },\n {\n onSuccess: () => onClose(),\n onError: (err) =>\n setFormError(\n err instanceof Error\n ? err.message\n : tr('relationships.detail.editModal.error', 'Could not update relationship.')\n ),\n }\n );\n };\n\n return (\n <Modal\n title={tr('relationships.detail.editModal.title', 'Edit relationship')}\n onClose={onClose}\n maxWidthClassName=\"max-w-2xl\"\n >\n <form onSubmit={handleSubmit} className=\"space-y-4\">\n {formError && (\n <div\n id={formErrorId}\n tabIndex={-1}\n role=\"alert\"\n className=\"rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\"\n >\n {formError}\n </div>\n )}\n\n <div>\n <label htmlFor=\"edit-label\" className={labelCls}>\n {tr('relationships.detail.editModal.labelLabel', 'Label')}{' '}\n <span className=\"text-status-error-text\">*</span>\n </label>\n <input\n {...fieldErrorProps('edit-label')}\n id=\"edit-label\"\n type=\"text\"\n value={label}\n onChange={(e) => setLabel(e.target.value)}\n className={inputCls}\n required\n />\n </div>\n\n <div>\n <label htmlFor=\"edit-department\" className={labelCls}>\n {tr('relationships.detail.editModal.departmentLabel', 'Department or team')}\n </label>\n <input\n {...fieldErrorProps('edit-department')}\n id=\"edit-department\"\n type=\"text\"\n maxLength={120}\n value={department}\n onChange={(e) => setDepartment(e.target.value)}\n placeholder={tr(\n 'relationships.detail.editModal.departmentPlaceholder',\n 'e.g. Engineering, Marketing'\n )}\n className={inputCls}\n />\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"edit-provider\" className={labelCls}>\n {tr('relationships.detail.editModal.providerLabel', 'Provider')}\n </label>\n <select\n {...fieldErrorProps('edit-provider')}\n id=\"edit-provider\"\n value={providerId}\n onChange={(e) => {\n setProviderId(e.target.value);\n setPlanId('');\n }}\n className={inputCls}\n >\n <option value=\"\">\n {tr('relationships.detail.editModal.providerNone', '— None —')}\n </option>\n {providerOptions.map((p) => (\n <option key={p.id} value={p.id}>\n {p.name}\n </option>\n ))}\n </select>\n </div>\n <div>\n <label htmlFor=\"edit-plan\" className={labelCls}>\n {tr('relationships.detail.editModal.planLabel', 'Plan')}\n </label>\n <select\n {...fieldErrorProps('edit-plan')}\n id=\"edit-plan\"\n value={planId}\n onChange={(e) => setPlanId(e.target.value)}\n className={inputCls}\n disabled={!providerId || plans.length === 0}\n >\n <option value=\"\">{tr('relationships.detail.editModal.planNone', '— None —')}</option>\n {plans.map((pl) => (\n <option key={pl.id} value={pl.id}>\n {pl.name}\n </option>\n ))}\n </select>\n </div>\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-3\">\n <div>\n <label htmlFor=\"edit-amount\" className={labelCls}>\n {tr('relationships.detail.editModal.amountLabel', 'Amount')}\n </label>\n <input\n {...fieldErrorProps('edit-amount')}\n id=\"edit-amount\"\n type=\"number\"\n min=\"0\"\n step=\"0.01\"\n value={amount}\n onChange={(e) => setAmount(e.target.value)}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"edit-currency\" className={labelCls}>\n {tr('relationships.detail.editModal.currencyLabel', 'Currency')}\n </label>\n <input\n {...fieldErrorProps('edit-currency')}\n id=\"edit-currency\"\n type=\"text\"\n value={currency}\n onChange={(e) => setCurrency(e.target.value.toUpperCase())}\n maxLength={3}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"edit-interval\" className={labelCls}>\n {tr('relationships.detail.editModal.intervalLabel', 'Billing interval')}\n </label>\n <select\n {...fieldErrorProps('edit-interval')}\n id=\"edit-interval\"\n value={interval}\n onChange={(e) => setInterval(e.target.value as SubBillingInterval)}\n className={inputCls}\n >\n {INTERVALS.map((i) => (\n <option key={i} value={i}>\n {i.replace(/_/g, ' ')}\n </option>\n ))}\n </select>\n </div>\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-3\">\n <div>\n <label htmlFor=\"edit-renews\" className={labelCls}>\n {tr('relationships.detail.editModal.renewsOnLabel', 'Renews on')}\n </label>\n <input\n {...fieldErrorProps('edit-renews')}\n id=\"edit-renews\"\n type=\"date\"\n value={renewsAt}\n onChange={(e) => setRenewsAt(e.target.value)}\n className={inputCls}\n />\n </div>\n <div className=\"flex items-end\">\n <label className=\"flex items-center gap-2 text-sm text-text-primary\">\n <input\n type=\"checkbox\"\n checked={autoRenew}\n onChange={(e) => setAutoRenew(e.target.checked)}\n className=\"size-4 rounded border-border-subtle\"\n />\n {tr('relationships.detail.editModal.autoRenews', 'Auto-renews')}\n </label>\n </div>\n </div>\n\n <div>\n <label htmlFor=\"edit-notes\" className={labelCls}>\n {tr('relationships.detail.editModal.notesLabel', 'Notes')}\n </label>\n <textarea\n {...fieldErrorProps('edit-notes')}\n id=\"edit-notes\"\n value={notes}\n onChange={(e) => setNotes(e.target.value)}\n rows={3}\n className={inputCls}\n />\n </div>\n\n <div className=\"flex justify-end gap-3\">\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n {tr('relationships.detail.editModal.cancel', 'Cancel')}\n </button>\n <button\n type=\"submit\"\n disabled={update.isPending}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90 disabled:opacity-50\"\n >\n {update.isPending\n ? tr('relationships.detail.editModal.saving', 'Saving…')\n : tr('relationships.detail.editModal.submit', 'Save changes')}\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Add entitlement modal → subCreateEntitlement\n// ---------------------------------------------------------------------------\n\nfunction AddEntitlementModal({\n relationshipId,\n onClose,\n}: {\n relationshipId: string;\n onClose: () => void;\n}) {\n const tr = useTr();\n const create = useCreateEntitlement();\n const [name, setName] = useState('');\n const [type, setType] = useState<SubEntitlementType>('FEATURE_ACCESS');\n const [quota, setQuota] = useState('');\n const [unit, setUnit] = useState('');\n const [description, setDescription] = useState('');\n const [formError, setFormError, fieldErrorProps, formErrorId] = useFormError();\n\n const handleSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n setFormError(null);\n if (!name.trim()) {\n setFormError(\n tr(\n 'relationships.detail.addEntitlementModal.nameRequired',\n 'An entitlement name is required.'\n ),\n 'ent-name'\n );\n return;\n }\n create.mutate(\n {\n relationshipId,\n name: name.trim(),\n type,\n ...(quota.trim() ? { quota: Number(quota) } : {}),\n ...(unit.trim() ? { unit: unit.trim() } : {}),\n ...(description.trim() ? { description: description.trim() } : {}),\n },\n {\n onSuccess: () => onClose(),\n onError: (err) =>\n setFormError(\n err instanceof Error\n ? err.message\n : tr('relationships.detail.addEntitlementModal.error', 'Could not add entitlement.')\n ),\n }\n );\n };\n\n return (\n <Modal\n title={tr('relationships.detail.addEntitlementModal.title', 'Add entitlement')}\n onClose={onClose}\n >\n <form onSubmit={handleSubmit} className=\"space-y-4\">\n {formError && (\n <div\n id={formErrorId}\n tabIndex={-1}\n role=\"alert\"\n className=\"rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\"\n >\n {formError}\n </div>\n )}\n <div>\n <label htmlFor=\"ent-name\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.nameLabel', 'Name')}{' '}\n <span className=\"text-status-error-text\">*</span>\n </label>\n <input\n {...fieldErrorProps('ent-name')}\n id=\"ent-name\"\n type=\"text\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder={tr(\n 'relationships.detail.addEntitlementModal.namePlaceholder',\n 'e.g. Seats, API calls, Priority support'\n )}\n className={inputCls}\n required\n />\n </div>\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-3\">\n <div>\n <label htmlFor=\"ent-type\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.typeLabel', 'Type')}\n </label>\n <select\n {...fieldErrorProps('ent-type')}\n id=\"ent-type\"\n value={type}\n onChange={(e) => setType(e.target.value as SubEntitlementType)}\n className={inputCls}\n >\n {ENTITLEMENT_TYPES.map((t) => (\n <option key={t} value={t}>\n {t.replace(/_/g, ' ')}\n </option>\n ))}\n </select>\n </div>\n <div>\n <label htmlFor=\"ent-quota\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.quotaLabel', 'Quota')}\n </label>\n <input\n {...fieldErrorProps('ent-quota')}\n id=\"ent-quota\"\n type=\"number\"\n min=\"0\"\n value={quota}\n onChange={(e) => setQuota(e.target.value)}\n placeholder={tr(\n 'relationships.detail.addEntitlementModal.quotaPlaceholder',\n 'e.g. 5'\n )}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"ent-unit\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.unitLabel', 'Unit')}\n </label>\n <input\n {...fieldErrorProps('ent-unit')}\n id=\"ent-unit\"\n type=\"text\"\n value={unit}\n onChange={(e) => setUnit(e.target.value)}\n placeholder={tr(\n 'relationships.detail.addEntitlementModal.unitPlaceholder',\n 'e.g. seats, GB'\n )}\n className={inputCls}\n />\n </div>\n </div>\n <div>\n <label htmlFor=\"ent-desc\" className={labelCls}>\n {tr('relationships.detail.addEntitlementModal.descriptionLabel', 'Description')}\n </label>\n <textarea\n {...fieldErrorProps('ent-desc')}\n id=\"ent-desc\"\n value={description}\n onChange={(e) => setDescription(e.target.value)}\n rows={2}\n className={inputCls}\n />\n </div>\n <div className=\"flex justify-end gap-3\">\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n {tr('relationships.detail.addEntitlementModal.cancel', 'Cancel')}\n </button>\n <button\n type=\"submit\"\n disabled={create.isPending}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90 disabled:opacity-50\"\n >\n {create.isPending\n ? tr('relationships.detail.addEntitlementModal.adding', 'Adding…')\n : tr('relationships.detail.addEntitlementModal.submit', 'Add entitlement')}\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Attach asset modal → upload to files-svc, then subCreateAsset\n// ---------------------------------------------------------------------------\n\nfunction AttachAssetModal({\n relationshipId,\n onClose,\n}: {\n relationshipId: string;\n onClose: () => void;\n}) {\n const tr = useTr();\n const create = useCreateAsset();\n const { uploadFile, progress, isUploading } = useUploadFile();\n const [name, setName] = useState('');\n const [type, setType] = useState<SubAssetType>('RECEIPT');\n const [file, setFile] = useState<File | null>(null);\n const [expiresAt, setExpiresAt] = useState('');\n const [formError, setFormError, fieldErrorProps, formErrorId] = useFormError();\n\n const busy = isUploading || create.isPending;\n\n const handleSubmit = async (e: React.FormEvent) => {\n e.preventDefault();\n setFormError(null);\n if (!file) {\n setFormError(\n tr('relationships.detail.attachAssetModal.chooseFile', 'Choose a file to attach.'),\n 'asset-file'\n );\n return;\n }\n try {\n const { fileId, fileName } = await uploadFile(file);\n await create.mutateAsync({\n relationshipId,\n name: name.trim() || fileName,\n type,\n fileId,\n ...(expiresAt ? { expiresAt: new Date(expiresAt).toISOString() } : {}),\n });\n onClose();\n } catch (err) {\n setFormError(\n err instanceof Error\n ? err.message\n : tr('relationships.detail.attachAssetModal.error', 'Could not attach the asset.')\n );\n }\n };\n\n return (\n <Modal\n title={tr('relationships.detail.attachAssetModal.title', 'Attach asset')}\n onClose={onClose}\n >\n <form onSubmit={handleSubmit} className=\"space-y-4\">\n {formError && (\n <div\n id={formErrorId}\n tabIndex={-1}\n role=\"alert\"\n className=\"rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\"\n >\n {formError}\n </div>\n )}\n <div>\n <label htmlFor=\"asset-file\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.fileLabel', 'File')}{' '}\n <span className=\"text-status-error-text\">*</span>\n </label>\n <input\n {...fieldErrorProps('asset-file')}\n id=\"asset-file\"\n type=\"file\"\n onChange={(e) => {\n const f = e.target.files?.[0] ?? null;\n setFile(f);\n if (f && !name.trim()) setName(f.name);\n }}\n className=\"w-full text-sm text-text-secondary file:me-3 file:rounded-lg file:border file:border-border-subtle file:bg-bg-surface file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-text-primary hover:file:bg-bg-sunken\"\n />\n <p className=\"mt-1 text-xs text-text-secondary\">\n {tr(\n 'relationships.detail.attachAssetModal.fileHint',\n 'Stored securely in files — only a reference is kept here.'\n )}\n </p>\n </div>\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"asset-name\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.nameLabel', 'Name')}\n </label>\n <input\n {...fieldErrorProps('asset-name')}\n id=\"asset-name\"\n type=\"text\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder={tr(\n 'relationships.detail.attachAssetModal.namePlaceholder',\n 'Defaults to the file name'\n )}\n className={inputCls}\n />\n </div>\n <div>\n <label htmlFor=\"asset-type\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.typeLabel', 'Type')}\n </label>\n <select\n {...fieldErrorProps('asset-type')}\n id=\"asset-type\"\n value={type}\n onChange={(e) => setType(e.target.value as SubAssetType)}\n className={inputCls}\n >\n {ASSET_TYPES.map((t) => (\n <option key={t} value={t}>\n {t.replace(/_/g, ' ')}\n </option>\n ))}\n </select>\n </div>\n </div>\n <div>\n <label htmlFor=\"asset-expires\" className={labelCls}>\n {tr('relationships.detail.attachAssetModal.expiresOnLabel', 'Expires on')}\n </label>\n <input\n {...fieldErrorProps('asset-expires')}\n id=\"asset-expires\"\n type=\"date\"\n value={expiresAt}\n onChange={(e) => setExpiresAt(e.target.value)}\n className={inputCls}\n />\n </div>\n {isUploading && (\n <p className=\"text-xs text-text-secondary\">\n {tr('relationships.detail.attachAssetModal.uploading', 'Uploading… {{progress}}%', {\n progress,\n })}\n </p>\n )}\n <div className=\"flex justify-end gap-3\">\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg border border-border-subtle px-4 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n {tr('relationships.detail.attachAssetModal.cancel', 'Cancel')}\n </button>\n <button\n type=\"submit\"\n disabled={busy}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90 disabled:opacity-50\"\n >\n {busy\n ? tr('relationships.detail.attachAssetModal.attaching', 'Attaching…')\n : tr('relationships.detail.attachAssetModal.submit', 'Attach asset')}\n </button>\n </div>\n </form>\n </Modal>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Asset row — resolves a presigned download URL on demand\n// ---------------------------------------------------------------------------\n\nfunction AssetRow({ asset }: { asset: NonNullable<SubRelationship['assets']>[number] }) {\n const { formatDate, formatEnumLabel } = useFormatters();\n\n const tr = useTr();\n const getDownloadUrl = useFileDownloadUrl();\n const [downloading, setDownloading] = useState(false);\n\n const handleDownload = async () => {\n if (!asset.file?.id) return;\n setDownloading(true);\n try {\n const url = await getDownloadUrl(asset.file.id);\n window.open(url, '_blank', 'noopener,noreferrer');\n } catch {\n // Non-fatal: a broken/expired file reference just can't be downloaded.\n } finally {\n setDownloading(false);\n }\n };\n\n return (\n <div className=\"flex items-center justify-between gap-3 p-3\">\n <div className=\"flex min-w-0 items-center gap-2\">\n <Paperclip className=\"h-4 w-4 shrink-0 text-text-secondary\" />\n <div className=\"min-w-0\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{asset.name}</p>\n <p className=\"text-xs text-text-secondary\">{formatEnumLabel(asset.type)}</p>\n </div>\n </div>\n <div className=\"flex shrink-0 items-center gap-3\">\n {asset.expiresAt && (\n <span className=\"text-xs text-text-secondary\">\n {tr('relationships.detail.assetRow.expires', 'Expires {{date}}', {\n date: formatDate(asset.expiresAt),\n })}\n </span>\n )}\n {asset.file?.id && (\n <button\n type=\"button\"\n onClick={handleDownload}\n disabled={downloading}\n className=\"inline-flex items-center gap-1 rounded-lg border border-border-subtle px-2.5 py-1 text-xs font-medium text-text-primary hover:bg-bg-sunken disabled:opacity-50\"\n >\n <Download className=\"h-3.5 w-3.5\" />{' '}\n {downloading\n ? tr('relationships.detail.assetRow.opening', 'Opening…')\n : tr('relationships.detail.assetRow.download', 'Download')}\n </button>\n )}\n </div>\n </div>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Invoice row (BOFF-8659) — every invoice linked to this relationship via\n// `SubInvoice.relationshipId` is shown in the Assets section alongside any\n// file-based assets, so users don't have to leave the relationship page to\n// discover that they have an outstanding invoice tied to it.\n// ---------------------------------------------------------------------------\n\nfunction InvoiceRow({ invoice }: { invoice: SubInvoice }) {\n const { formatCurrency, formatDate, formatEnumLabel } = useFormatters();\n\n const tr = useTr();\n // Each invoice appears once, grouped by the (most-recent) due or issue\n // date and labelled with number · status, then a right-aligned total that\n // matches the Invoices list currency formatting.\n const label =\n invoice.number ?? tr('relationships.detail.invoiceRow.unnumbered', 'Unnumbered invoice');\n return (\n <div className=\"flex items-center justify-between gap-3 p-3\">\n <div className=\"flex min-w-0 items-center gap-2\">\n <CreditCard className=\"h-4 w-4 shrink-0 text-text-secondary\" />\n <div className=\"min-w-0\">\n <p className=\"truncate text-sm font-medium text-text-primary\">{label}</p>\n <p className=\"text-xs text-text-secondary\">\n {formatEnumLabel(invoice.status)}\n {invoice.dueDate\n ? ` · ${tr('relationships.detail.invoiceRow.due', 'due {{date}}', {\n date: formatDate(invoice.dueDate),\n })}`\n : invoice.issueDate\n ? ` · ${formatDate(invoice.issueDate)}`\n : ''}\n </p>\n </div>\n </div>\n <span className=\"shrink-0 text-sm font-medium tabular-nums text-text-primary\">\n {formatCurrency(invoice.total, invoice.currency)}\n </span>\n </div>\n );\n}\n\nexport function RelationshipDetailPage() {\n const { formatCurrency, formatDate, formatEnumLabel, formatIntervalSuffix } = useFormatters();\n\n const tr = useTr();\n const { id } = useParams<{ id: string }>();\n const { navigateTo } = useSubscriberBot();\n const { data: relationship, isLoading, isError, refetch } = useRelationship(id);\n const transition = useTransitionRelationship();\n const cancel = useCancelRelationship();\n const [actionError, setActionError] = useState<string | null>(null);\n const [showEdit, setShowEdit] = useState(false);\n const [showAddEntitlement, setShowAddEntitlement] = useState(false);\n const [showAttachAsset, setShowAttachAsset] = useState(false);\n // Open AI recommendations about this subscription (BOFF-3663). Best effort:\n // if the decision engine is unavailable the section is simply omitted, and\n // every change it could propose stays available through the actions above.\n // Invoices linked through SubInvoice.relationshipId (BOFF-8659). The svc\n // exposes them through subListInvoices(relationshipId), not as a field on\n // SubRelationship, so they are read with their own query.\n const relationshipInvoices = useInvoices(\n { relationshipId: id, pagination: { limit: 50, offset: 0 } },\n { enabled: Boolean(id) }\n );\n const openDecisions = useDecisions(\n { relationshipId: id, status: 'PROPOSED' },\n { enabled: Boolean(id) }\n );\n\n if (isLoading) {\n return (\n <PageLayout title={tr('relationships.title', 'Relationship')}>\n <LoadingView label={tr('relationships.detail.loading', 'Loading relationship…')} />\n </PageLayout>\n );\n }\n\n if (isError) {\n return (\n <PageLayout title={tr('relationships.title', 'Relationship')}>\n <ErrorView\n message={tr('relationships.detail.error', 'Could not load this relationship.')}\n onRetry={() => void refetch()}\n />\n </PageLayout>\n );\n }\n\n if (!relationship) {\n return (\n <PageLayout title={tr('relationships.title', 'Relationship')}>\n <EmptyState\n illustration=\"empty-data\"\n title={tr('relationships.detail.notFoundTitle', 'Relationship not found')}\n description={tr(\n 'relationships.detail.notFoundDescription',\n 'It may have been removed, or you may not have access to it.'\n )}\n action={\n <button\n type=\"button\"\n onClick={() => navigateTo('/relationships')}\n className=\"rounded-lg bg-action-primary-bg px-4 py-2 text-sm font-medium text-action-primary-text hover:opacity-90\"\n >\n {tr('relationships.detail.backToRelationships', 'Back to relationships')}\n </button>\n }\n />\n </PageLayout>\n );\n }\n\n const r = relationship;\n const isBusy = transition.isPending || cancel.isPending;\n\n const runTransition = (status: SubRelationshipStatus) => {\n setActionError(null);\n transition.mutate(\n { id: r.id, status },\n {\n onError: (e) =>\n setActionError(\n e instanceof Error\n ? e.message\n : tr('relationships.detail.transitionError', 'Transition failed')\n ),\n }\n );\n };\n\n const runCancel = () => {\n setActionError(null);\n cancel.mutate(r.id, {\n onError: (e) =>\n setActionError(\n e instanceof Error ? e.message : tr('relationships.detail.cancelError', 'Cancel failed')\n ),\n });\n };\n\n // Renewal timeline — built entirely from the real renewalEvents, oldest → newest.\n const renewalTimeline: TimelineItem[] = [...(r.renewalEvents ?? [])]\n .sort((a, b) => new Date(a.occursAt).getTime() - new Date(b.occursAt).getTime())\n .map((event) => {\n const ts = new Date(event.occursAt).getTime();\n const isFuture = !Number.isNaN(ts) && ts > Date.now();\n return {\n title: formatEnumLabel(event.eventType),\n sub: `${formatDate(event.occursAt)}${event.detail ? ` · ${event.detail}` : ''}`,\n meta:\n event.amount != null\n ? formatCurrency(event.amount, event.currency ?? r.currency)\n : undefined,\n tone: isFuture ? 'warning' : 'muted',\n };\n });\n\n const autoRenewPill = r.autoRenew ? (\n <span className=\"inline-flex items-center rounded-full bg-status-success-bg-subtle px-2 py-0.5 text-xs font-medium text-status-success-text\">\n {tr('relationships.detail.autoRenewOn', 'On')}\n </span>\n ) : (\n <span className=\"inline-flex items-center rounded-full bg-bg-sunken px-2 py-0.5 text-xs font-medium text-text-secondary\">\n {tr('relationships.detail.autoRenewOff', 'Off')}\n </span>\n );\n\n // Only offer transitions the svc state machine accepts from the current\n // status (a cancelled relationship no longer shows Activate / Pause).\n const availableTransitions = TRANSITIONS.filter((t) => canTransition(r.status, t.status));\n const planFeatures = r.plan?.features ?? [];\n\n return (\n <PageLayout\n title={r.label}\n description={r.provider?.name ?? tr(KIND_KEY[r.kind], formatEnumLabel(r.kind))}\n actions={\n <div className=\"flex flex-wrap items-center gap-2\">\n <button\n type=\"button\"\n onClick={() => setShowEdit(true)}\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Pencil className=\"h-4 w-4\" /> {tr('relationships.detail.edit', 'Edit')}\n </button>\n <button\n type=\"button\"\n data-testid=\"negotiate-bill\"\n onClick={() =>\n navigateTo(`/negotiations/new?relationshipId=${encodeURIComponent(r.id)}`)\n }\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Handshake className=\"h-4 w-4\" />{' '}\n {tr('relationships.detail.negotiate', 'Negotiate this bill')}\n </button>\n <button\n type=\"button\"\n data-testid=\"request-procurement\"\n onClick={() =>\n navigateTo(`/procurement/new?relationshipId=${encodeURIComponent(r.id)}`)\n }\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Briefcase className=\"h-4 w-4\" />{' '}\n {tr('relationships.detail.procurement', 'Ask an expert to negotiate')}\n </button>\n <button\n type=\"button\"\n onClick={() => navigateTo('/relationships')}\n className=\"inline-flex items-center gap-2 whitespace-nowrap rounded-lg border border-border-subtle px-3 py-2 text-sm font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <ArrowLeft className=\"rtl:rotate-180 h-4 w-4\" />{' '}\n {tr('relationships.detail.back', 'Back')}\n </button>\n </div>\n }\n >\n {/* Hero summary + lifecycle actions */}\n <GlassCard treatment=\"glass\" glow className=\"p-5 sm:p-6\">\n <div className=\"flex flex-col gap-5 lg:flex-row lg:items-start lg:justify-between\">\n <div className=\"min-w-0\">\n <p className=\"text-xs font-medium uppercase tracking-wide text-text-secondary\">\n {tr(KIND_KEY[r.kind], formatEnumLabel(r.kind))}\n </p>\n <div className=\"mt-2 flex flex-wrap items-center gap-3\">\n <span className=\"text-3xl font-bold tabular-nums text-text-primary\">\n {formatCurrency(r.amount, r.currency)}\n <span className=\"text-base font-normal text-text-secondary\">\n {formatIntervalSuffix(r.interval)}\n </span>\n </span>\n <StatusBadge status={r.status} />\n </div>\n <div className=\"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm text-text-secondary\">\n <span className=\"inline-flex items-center gap-1.5\">\n <CalendarClock className=\"h-3.5 w-3.5\" />\n {r.renewsAt\n ? tr('relationships.detail.renews', 'Renews {{date}}', {\n date: formatDate(r.renewsAt),\n })\n : tr('relationships.detail.noRenewalScheduled', 'No renewal scheduled')}\n </span>\n <span className=\"inline-flex items-center gap-1.5\">\n <ShieldCheck className=\"h-3.5 w-3.5\" />\n {formatEnumLabel(r.discoverySource)}\n </span>\n <span className=\"inline-flex items-center gap-1.5\">\n {tr('relationships.detail.autoRenew', 'Auto-renew')} {autoRenewPill}\n </span>\n </div>\n {r.tags.length > 0 && (\n <div className=\"mt-3 flex flex-wrap items-center gap-2\">\n <Tag className=\"h-3.5 w-3.5 text-text-secondary\" />\n {r.tags.map((tag) => (\n <span\n key={tag}\n className=\"rounded-full bg-bg-sunken px-2.5 py-0.5 text-xs text-text-secondary\"\n >\n {tag}\n </span>\n ))}\n </div>\n )}\n </div>\n\n {/* Lifecycle actions */}\n <div className=\"grid shrink-0 grid-cols-2 gap-2 sm:flex sm:flex-wrap lg:flex-col lg:items-stretch\">\n {availableTransitions.map((t) => {\n const Icon = t.icon;\n return (\n <button\n key={t.status}\n type=\"button\"\n disabled={isBusy}\n onClick={() => runTransition(t.status)}\n className=\"inline-flex min-h-11 items-center justify-center gap-1.5 rounded-lg border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm sm:min-h-0 sm:text-xs font-medium text-text-primary hover:bg-bg-sunken disabled:opacity-50\"\n >\n <Icon className=\"h-3.5 w-3.5\" /> {tr(t.labelKey, t.defaultLabel)}\n </button>\n );\n })}\n {canTransition(r.status, 'CANCELLED') && (\n <button\n type=\"button\"\n disabled={isBusy}\n onClick={runCancel}\n className=\"inline-flex min-h-11 items-center justify-center gap-1.5 rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-3 py-1.5 text-sm sm:min-h-0 sm:text-xs font-medium text-status-error-text hover:opacity-90 disabled:opacity-50\"\n >\n <Ban className=\"h-3.5 w-3.5\" />{' '}\n {tr('relationships.detail.actions.cancel', 'Cancel')}\n </button>\n )}\n </div>\n </div>\n </GlassCard>\n\n {actionError && (\n <div className=\"mt-4 rounded-lg border border-status-error-text/30 bg-status-error-bg-subtle px-4 py-2 text-sm text-status-error-text\">\n {actionError}\n </div>\n )}\n\n {/* Main layout: details (left) + health & timeline rail (right) */}\n <div className=\"mt-6 grid grid-cols-1 gap-4 lg:grid-cols-3\">\n <div className=\"space-y-4 lg:col-span-2\">\n <div className=\"grid grid-cols-1 gap-4 md:grid-cols-2\">\n {/* Plan & pricing */}\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <CreditCard className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.planPricing', 'Plan & pricing')}\n </div>\n <div className=\"mt-3\">\n <InfoRow\n label={tr('relationships.detail.info.plan', 'Plan')}\n value={r.plan?.name ?? '—'}\n />\n <InfoRow\n label={tr('relationships.detail.info.price', 'Price')}\n value={\n <>\n {formatCurrency(r.amount, r.currency)}\n <span className=\"font-normal text-text-secondary\">\n {formatIntervalSuffix(r.interval)}\n </span>\n </>\n }\n />\n <InfoRow\n label={tr('relationships.detail.info.billingInterval', 'Billing interval')}\n value={formatEnumLabel(r.interval)}\n />\n <InfoRow\n label={tr('relationships.detail.info.provider', 'Provider')}\n value={r.provider?.name ?? '—'}\n />\n </div>\n {planFeatures.length > 0 && (\n <div className=\"mt-3 flex flex-wrap gap-1.5\">\n {planFeatures.map((f) => (\n <span\n key={f}\n className=\"rounded-full bg-bg-sunken px-2.5 py-0.5 text-xs text-text-secondary\"\n >\n {f}\n </span>\n ))}\n </div>\n )}\n </GlassCard>\n\n {/* Payment & billing */}\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Wallet className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.paymentBilling', 'Payment & billing')}\n </div>\n <div className=\"mt-3\">\n <InfoRow\n label={tr('relationships.detail.info.currency', 'Currency')}\n value={r.currency}\n />\n <InfoRow\n label={tr('relationships.detail.info.autoRenew', 'Auto-renew')}\n value={autoRenewPill}\n />\n <InfoRow\n label={tr('relationships.detail.info.nextRenewal', 'Next renewal')}\n value={r.renewsAt ? formatDate(r.renewsAt) : '—'}\n />\n <InfoRow\n label={tr('relationships.detail.info.started', 'Started')}\n value={r.startedAt ? formatDate(r.startedAt) : '—'}\n />\n {r.trialEndsAt && (\n <InfoRow\n label={tr('relationships.detail.info.trialEnds', 'Trial ends')}\n value={formatDate(r.trialEndsAt)}\n />\n )}\n </div>\n </GlassCard>\n </div>\n\n {/* Open AI recommendations for this subscription */}\n {(openDecisions.data?.items.length ?? 0) > 0 && (\n <Section\n className=\"mt-0\"\n title={tr('relationships.detail.sections.aiRecommendations', 'AI recommendations')}\n description={tr(\n 'relationships.detail.sections.aiRecommendationsDescription',\n 'Open recommendations about this subscription. You can also make any of these changes by hand above.'\n )}\n >\n <AiDisclaimer className=\"mb-3\" />\n <div className=\"grid grid-cols-1 gap-3\" data-testid=\"relationship-decisions\">\n {openDecisions.data?.items.map((d) => (\n <DecisionCard key={d.id} decision={d} />\n ))}\n </div>\n </Section>\n )}\n\n {/* Entitlements */}\n <Section\n className=\"mt-0\"\n title={tr('relationships.detail.sections.entitlements', 'Entitlements')}\n description={tr(\n 'relationships.detail.sections.entitlementsDescription',\n 'What this relationship grants you'\n )}\n action={\n <button\n type=\"button\"\n onClick={() => setShowAddEntitlement(true)}\n className=\"inline-flex items-center gap-1.5 rounded-lg border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Plus className=\"h-3.5 w-3.5\" />{' '}\n {tr('relationships.detail.sections.addEntitlement', 'Add entitlement')}\n </button>\n }\n >\n {!r.entitlements || r.entitlements.length === 0 ? (\n <EmptyState\n illustration=\"empty-data\"\n title={tr('relationships.detail.empty.noEntitlementsTitle', 'No entitlements')}\n description={tr(\n 'relationships.detail.empty.noEntitlementsDescription',\n 'Entitlements (seats, quotas, feature access) will appear here.'\n )}\n />\n ) : (\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2\">\n {r.entitlements.map((e) => {\n const hasQuota = e.quota != null && e.quota > 0;\n return (\n <GlassCard key={e.id} treatment=\"plain\" className=\"p-4\">\n <div className=\"flex items-start justify-between gap-2\">\n <p className=\"min-w-0 truncate text-sm font-medium text-text-primary\">\n {e.name}\n </p>\n <StatusBadge status={e.isActive ? 'ACTIVE' : 'DISABLED'} />\n </div>\n <p className=\"mt-1 text-xs text-text-secondary\">{formatEnumLabel(e.type)}</p>\n {hasQuota && (\n <div className=\"mt-3\">\n <div className=\"flex items-center justify-between text-xs text-text-secondary\">\n <span>\n {e.used} / {e.quota}\n {e.unit ? ` ${e.unit}` : ''}\n </span>\n <span className=\"tabular-nums\">\n {Math.round((e.used / (e.quota as number)) * 100)}%\n </span>\n </div>\n <MiniProgress\n label={tr('common.quotaUtilization', 'Quota utilization')}\n value={e.used}\n max={e.quota as number}\n tone={\n e.used / (e.quota as number) >= 0.9\n ? 'negative'\n : e.used / (e.quota as number) >= 0.7\n ? 'warning'\n : 'accent'\n }\n className=\"mt-1.5\"\n />\n </div>\n )}\n </GlassCard>\n );\n })}\n </div>\n )}\n </Section>\n\n {/* Assets — file-based assets + relationship-owned invoices.\n BOFF-8659: invoices linked via `SubInvoice.relationshipId` are now\n shown here too, so the panel copy \"Invoices, contracts, licenses\n and credentials\" is honored for the cross-module Relationships ↔\n Invoices flow. */}\n <Section\n className=\"mt-0\"\n title={tr('relationships.detail.sections.assets', 'Assets')}\n description={tr(\n 'relationships.detail.sections.assetsDescription',\n 'Invoices, contracts, licenses and credentials'\n )}\n action={\n <button\n type=\"button\"\n onClick={() => setShowAttachAsset(true)}\n className=\"inline-flex items-center gap-1.5 rounded-lg border border-border-subtle px-3 py-1.5 text-xs font-medium text-text-primary hover:bg-bg-sunken\"\n >\n <Plus className=\"h-3.5 w-3.5\" />{' '}\n {tr('relationships.detail.sections.attachAsset', 'Attach asset')}\n </button>\n }\n >\n {(() => {\n const assets = r.assets ?? [];\n // BOFF-8659 — pull relationship-owned invoices into the same\n // Assets list, sorted next to file-based assets by their sort\n // time so invoices appear in the same order as the Invoices\n // list (newest first).\n const invoices: SubInvoice[] = relationshipInvoices.data?.items ?? [];\n const hasAny = assets.length > 0 || invoices.length > 0;\n if (!hasAny) {\n return (\n <EmptyState\n illustration=\"empty-data\"\n title={tr('relationships.detail.empty.noAssetsTitle', 'No assets attached')}\n description={tr(\n 'relationships.detail.empty.noAssetsDescription',\n 'Attach invoices, contracts, licenses or receipts to this relationship.'\n )}\n />\n );\n }\n type AssetLike =\n | {\n kind: 'asset';\n sort: number;\n asset: NonNullable<SubRelationship['assets']>[number];\n }\n | {\n kind: 'invoice';\n sort: number;\n invoice: SubInvoice;\n };\n const combined: AssetLike[] = [\n ...assets.map((a) => ({\n kind: 'asset' as const,\n sort: new Date(a.createdAt).getTime() || 0,\n asset: a,\n })),\n ...invoices.map((i) => ({\n kind: 'invoice' as const,\n sort: new Date(i.createdAt).getTime() || 0,\n invoice: i,\n })),\n ].sort((x, y) => y.sort - x.sort);\n return (\n <GlassCard treatment=\"plain\" className=\"divide-y divide-border-subtle p-0\">\n {combined.map((row) =>\n row.kind === 'asset' ? (\n <AssetRow key={`a-${row.asset.id}`} asset={row.asset} />\n ) : (\n <InvoiceRow key={`i-${row.invoice.id}`} invoice={row.invoice} />\n )\n )}\n </GlassCard>\n );\n })()}\n </Section>\n\n {r.notes && (\n <GlassCard treatment=\"plain\" className=\"p-4\">\n <p className=\"text-xs font-medium text-text-secondary\">\n {tr('relationships.detail.sections.notes', 'Notes')}\n </p>\n <p className=\"mt-1 whitespace-pre-wrap text-sm text-text-primary\">{r.notes}</p>\n </GlassCard>\n )}\n </div>\n\n {/* Right rail: health gauge + renewal timeline */}\n <div className=\"space-y-4\">\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <Activity className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.healthScore', 'Health score')}\n </div>\n {r.healthScore != null ? (\n <div className=\"mt-4 flex flex-col items-center\">\n <Gauge\n value={r.healthScore}\n max={100}\n size={160}\n label={tr('relationships.detail.outOf100', 'of 100')}\n />\n <div className=\"mt-2 w-full\">\n <MiniProgress\n label={tr('common.healthScore', 'Health score')}\n value={r.healthScore}\n max={100}\n tone={healthTone(r.healthScore)}\n />\n </div>\n <p\n className=\"mt-3 text-center text-xs text-text-secondary\"\n data-testid=\"health-score-basis\"\n >\n {tr(\n 'relationships.detail.healthScoreBasis',\n 'Computed from usage, payment history, price stability and overlap with your other subscriptions.'\n )}\n </p>\n </div>\n ) : (\n <p className=\"mt-4 text-sm text-text-secondary\">\n {tr(\n 'relationships.detail.empty.noHealthScore',\n 'Not scored yet. A health score appears once Subscriber Bot has enough signal.'\n )}\n </p>\n )}\n </GlassCard>\n\n <GlassCard treatment=\"metric\" className=\"p-5\">\n <div className=\"flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <CalendarClock className=\"h-4 w-4 text-text-secondary\" />{' '}\n {tr('relationships.detail.sections.renewalTimeline', 'Renewal timeline')}\n </div>\n <p className=\"mt-0.5 text-xs text-text-secondary\">\n {tr(\n 'relationships.detail.sections.renewalTimelineDescription',\n 'Detected renewals and price changes'\n )}\n </p>\n {renewalTimeline.length === 0 ? (\n <div className=\"mt-4\">\n <EmptyState\n illustration=\"empty-data\"\n title={tr('relationships.detail.empty.noRenewalEventsTitle', 'No renewal events')}\n description={tr(\n 'relationships.detail.empty.noRenewalEventsDescription',\n \"Renewals and price changes will appear here as they're detected.\"\n )}\n />\n </div>\n ) : (\n <Timeline items={renewalTimeline} className=\"mt-4\" />\n )}\n </GlassCard>\n </div>\n </div>\n\n {showEdit && <RelationshipEditModal relationship={r} onClose={() => setShowEdit(false)} />}\n {showAddEntitlement && (\n <AddEntitlementModal relationshipId={r.id} onClose={() => setShowAddEntitlement(false)} />\n )}\n {showAttachAsset && (\n <AttachAssetModal relationshipId={r.id} onClose={() => setShowAttachAsset(false)} />\n )}\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwEA,IAAM,IACJ,wMACI,IAAW,sDAEX,IAAkC;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,IAA0C;CAC9C;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,IAA8B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,KAAgD;CACpD,cAAc;CACd,YAAY;CACZ,SAAS;CACT,UAAU;CACV,YAAY;CACZ,mBAAmB;CACnB,YAAY;CACZ,OAAO;AACT,GAGM,KAKD;CACH;EACE,QAAQ;EACR,UAAU;EACV,cAAc;EACd,MAAM;CACR;CACA;EACE,QAAQ;EACR,UAAU;EACV,cAAc;EACd,M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;IAAI,eAAe,EAAmB,EAAK;GAAI,CAAA;EAE3E;;AAEhB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SubBillingInterval } from './index';
|
|
2
2
|
|
|
3
|
-
export type SubBankAggregator = 'PLAID' | 'STATEMENT_IMPORT';
|
|
3
|
+
export type SubBankAggregator = 'PLAID' | 'TRUELAYER' | 'ACCOUNT_AGGREGATOR' | 'STATEMENT_IMPORT';
|
|
4
|
+
/** How the browser runs an aggregator's flow (BOFF-10811). */
|
|
5
|
+
export type SubBankLinkMode = 'PLAID_LINK' | 'REDIRECT';
|
|
4
6
|
export type SubBankConnectionStatus = 'ACTIVE' | 'NEEDS_REAUTH' | 'ERROR' | 'DISCONNECTED' | 'REVOKED';
|
|
5
7
|
export type SubRecurringChargeStatus = 'DETECTED' | 'TRACKED' | 'DISMISSED';
|
|
6
8
|
export type SubStatementAmountConvention = 'OUTFLOW_NEGATIVE' | 'OUTFLOW_POSITIVE';
|
|
@@ -12,6 +14,9 @@ export interface SubBankAggregatorInfo {
|
|
|
12
14
|
environment: string | null;
|
|
13
15
|
countries: string[];
|
|
14
16
|
requiresLink: boolean;
|
|
17
|
+
linkMode: SubBankLinkMode | null;
|
|
18
|
+
/** The Account Aggregator needs the customer's mobile number / VUA up front. */
|
|
19
|
+
requiresCustomerIdentifier: boolean;
|
|
15
20
|
}
|
|
16
21
|
export interface SubBankAccount {
|
|
17
22
|
id: string;
|
|
@@ -31,6 +36,8 @@ export interface SubBankConnection {
|
|
|
31
36
|
lastSyncedAt: string | null;
|
|
32
37
|
lastSyncError: string | null;
|
|
33
38
|
transactionCount: number;
|
|
39
|
+
/** When the consent has to be reconfirmed (PSD2 90 days, AA consent expiry). */
|
|
40
|
+
consentExpiresAt: string | null;
|
|
34
41
|
createdAt: string;
|
|
35
42
|
updatedAt: string;
|
|
36
43
|
accounts: SubBankAccount[];
|
|
@@ -65,6 +72,8 @@ export interface SubBankSyncResult {
|
|
|
65
72
|
export interface SubBankLinkSession {
|
|
66
73
|
aggregator: SubBankAggregator;
|
|
67
74
|
linkToken: string;
|
|
75
|
+
/** REDIRECT aggregators: where the browser goes to authorise. */
|
|
76
|
+
linkUrl: string | null;
|
|
68
77
|
expiresAt: string | null;
|
|
69
78
|
}
|
|
70
79
|
export interface SubImportBankStatementInput {
|
|
@@ -80,6 +89,8 @@ export interface SubImportBankStatementInput {
|
|
|
80
89
|
export interface SubCompleteBankLinkInput {
|
|
81
90
|
aggregator: SubBankAggregator;
|
|
82
91
|
publicToken: string;
|
|
92
|
+
/** REDIRECT aggregators: the session's linkToken. */
|
|
93
|
+
state?: string | null;
|
|
83
94
|
institutionId?: string | null;
|
|
84
95
|
institutionName?: string | null;
|
|
85
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"banking.d.ts","sourceRoot":"","sources":["../../../src/subscriberbot/types/banking.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"banking.d.ts","sourceRoot":"","sources":["../../../src/subscriberbot/types/banking.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,WAAW,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;AAClG,8DAA8D;AAC9D,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,UAAU,CAAC;AACxD,MAAM,MAAM,uBAAuB,GACjC,QAAQ,GAAG,cAAc,GAAG,OAAO,GAAG,cAAc,GAAG,SAAS,CAAC;AACnE,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAC;AAC5E,MAAM,MAAM,4BAA4B,GAAG,kBAAkB,GAAG,kBAAkB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AG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,gBAAgB,CAAC,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACvD,UAAU,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,iBAAiB,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SubBankAggregator } from '../types/banking';
|
|
2
|
+
|
|
3
|
+
export interface PendingBankLink {
|
|
4
|
+
aggregator: SubBankAggregator;
|
|
5
|
+
linkToken: string;
|
|
6
|
+
connectionId: string | null;
|
|
7
|
+
startedAt: number;
|
|
8
|
+
}
|
|
9
|
+
export type BankRedirectResult = {
|
|
10
|
+
kind: 'complete';
|
|
11
|
+
aggregator: SubBankAggregator;
|
|
12
|
+
publicToken: string;
|
|
13
|
+
state: string;
|
|
14
|
+
connectionId: string | null;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'declined';
|
|
17
|
+
aggregator: SubBankAggregator;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'expired';
|
|
20
|
+
};
|
|
21
|
+
export declare function savePendingBankLink(pending: Omit<PendingBankLink, 'startedAt'>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Read (and remove from the address bar) the result of a redirect flow, if
|
|
24
|
+
* the page was opened by one. Returns null when the URL carries no result.
|
|
25
|
+
*/
|
|
26
|
+
export declare function consumeBankRedirect(): BankRedirectResult | null;
|
|
27
|
+
//# sourceMappingURL=bankRedirectLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bankRedirectLink.d.ts","sourceRoot":"","sources":["../../../src/subscriberbot/utils/bankRedirectLink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,kBAAkB,GAC1B;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,GACD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,iBAAiB,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAUxB,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,IAAI,CAErF;AA8BD;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,kBAAkB,GAAG,IAAI,CAyC/D"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/subscriberbot/utils/bankRedirectLink.ts
|
|
2
|
+
var e = "subscriberbot.bankLink.pending", t = 1800 * 1e3;
|
|
3
|
+
function n() {
|
|
4
|
+
try {
|
|
5
|
+
return typeof window > "u" ? null : window.sessionStorage;
|
|
6
|
+
} catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function r(t) {
|
|
11
|
+
n()?.setItem(e, JSON.stringify({
|
|
12
|
+
...t,
|
|
13
|
+
startedAt: Date.now()
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
function i() {
|
|
17
|
+
let r = n(), i = r?.getItem(e);
|
|
18
|
+
if (r?.removeItem(e), !i) return null;
|
|
19
|
+
try {
|
|
20
|
+
let e = JSON.parse(i);
|
|
21
|
+
if ((e.aggregator === "TRUELAYER" || e.aggregator === "ACCOUNT_AGGREGATOR") && typeof e.linkToken == "string" && typeof e.startedAt == "number" && Date.now() - e.startedAt < t) return {
|
|
22
|
+
aggregator: e.aggregator,
|
|
23
|
+
linkToken: e.linkToken,
|
|
24
|
+
connectionId: typeof e.connectionId == "string" ? e.connectionId : null,
|
|
25
|
+
startedAt: e.startedAt
|
|
26
|
+
};
|
|
27
|
+
} catch {}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
var a = [
|
|
31
|
+
"code",
|
|
32
|
+
"state",
|
|
33
|
+
"error",
|
|
34
|
+
"error_description",
|
|
35
|
+
"id",
|
|
36
|
+
"success",
|
|
37
|
+
"errorcode"
|
|
38
|
+
];
|
|
39
|
+
function o() {
|
|
40
|
+
if (typeof window > "u") return null;
|
|
41
|
+
let e = new URL(window.location.href), t = e.searchParams, n = t.get("code"), r = t.get("state"), o = t.get("error"), s = t.get("id"), c = t.get("success"), l = n !== null || o !== null, u = s !== null && c !== null;
|
|
42
|
+
if (!l && !u) return null;
|
|
43
|
+
let d = i();
|
|
44
|
+
for (let e of a) t.delete(e);
|
|
45
|
+
return window.history.replaceState(window.history.state, "", `${e.pathname}${e.search}${e.hash}`), d ? l && d.aggregator === "TRUELAYER" ? n ? {
|
|
46
|
+
kind: "complete",
|
|
47
|
+
aggregator: "TRUELAYER",
|
|
48
|
+
publicToken: n,
|
|
49
|
+
state: r || d.linkToken,
|
|
50
|
+
connectionId: d.connectionId
|
|
51
|
+
} : {
|
|
52
|
+
kind: "declined",
|
|
53
|
+
aggregator: "TRUELAYER"
|
|
54
|
+
} : u && d.aggregator === "ACCOUNT_AGGREGATOR" ? c !== "true" || !s ? {
|
|
55
|
+
kind: "declined",
|
|
56
|
+
aggregator: "ACCOUNT_AGGREGATOR"
|
|
57
|
+
} : {
|
|
58
|
+
kind: "complete",
|
|
59
|
+
aggregator: "ACCOUNT_AGGREGATOR",
|
|
60
|
+
publicToken: s,
|
|
61
|
+
state: d.linkToken,
|
|
62
|
+
connectionId: d.connectionId
|
|
63
|
+
} : { kind: "expired" } : { kind: "expired" };
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { o as consumeBankRedirect, r as savePendingBankLink };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=bankRedirectLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bankRedirectLink.js","names":[],"sources":["../../../src/subscriberbot/utils/bankRedirectLink.ts"],"sourcesContent":["/**\n * Redirect-based bank linking (BOFF-10811)\n * @module subscriberbot/utils\n *\n * TrueLayer (UK / EU open banking) and an RBI Account Aggregator (India) do\n * not use a drop-in widget: the browser leaves for the bank or Account\n * Aggregator and comes back to Bank connections with a one-time result.\n *\n * TrueLayer ?code=...&state=... (or ?error=access_denied)\n * Account Aggregator ?id=<consentId>&success=true|false\n *\n * Before leaving, the page keeps the session's signed link token in\n * sessionStorage (per tab, gone when the tab closes). On return it is sent\n * with the result to subCompleteBankLink, which only accepts a token minted\n * for this signed-in user, aggregator and consent.\n */\n\nimport type { SubBankAggregator } from '../types/banking';\n\nconst STORAGE_KEY = 'subscriberbot.bankLink.pending';\n/** Matches the service's link-state lifetime. */\nconst PENDING_TTL_MS = 30 * 60 * 1000;\n\nexport interface PendingBankLink {\n aggregator: SubBankAggregator;\n linkToken: string;\n connectionId: string | null;\n startedAt: number;\n}\n\nexport type BankRedirectResult =\n | {\n kind: 'complete';\n aggregator: SubBankAggregator;\n publicToken: string;\n state: string;\n connectionId: string | null;\n }\n | { kind: 'declined'; aggregator: SubBankAggregator }\n | { kind: 'expired' };\n\nfunction storage(): Storage | null {\n try {\n return typeof window === 'undefined' ? null : window.sessionStorage;\n } catch {\n return null;\n }\n}\n\nexport function savePendingBankLink(pending: Omit<PendingBankLink, 'startedAt'>): void {\n storage()?.setItem(STORAGE_KEY, JSON.stringify({ ...pending, startedAt: Date.now() }));\n}\n\nfunction takePendingBankLink(): PendingBankLink | null {\n const store = storage();\n const raw = store?.getItem(STORAGE_KEY);\n store?.removeItem(STORAGE_KEY);\n if (!raw) return null;\n try {\n const value = JSON.parse(raw) as Partial<PendingBankLink>;\n if (\n (value.aggregator === 'TRUELAYER' || value.aggregator === 'ACCOUNT_AGGREGATOR') &&\n typeof value.linkToken === 'string' &&\n typeof value.startedAt === 'number' &&\n Date.now() - value.startedAt < PENDING_TTL_MS\n ) {\n return {\n aggregator: value.aggregator,\n linkToken: value.linkToken,\n connectionId: typeof value.connectionId === 'string' ? value.connectionId : null,\n startedAt: value.startedAt,\n };\n }\n } catch {\n // An unreadable entry is treated like no pending link.\n }\n return null;\n}\n\nconst RESULT_PARAMS = ['code', 'state', 'error', 'error_description', 'id', 'success', 'errorcode'];\n\n/**\n * Read (and remove from the address bar) the result of a redirect flow, if\n * the page was opened by one. Returns null when the URL carries no result.\n */\nexport function consumeBankRedirect(): BankRedirectResult | null {\n if (typeof window === 'undefined') return null;\n const url = new URL(window.location.href);\n const params = url.searchParams;\n const code = params.get('code');\n const state = params.get('state');\n const trueLayerError = params.get('error');\n const consentId = params.get('id');\n const success = params.get('success');\n const isTrueLayer = code !== null || trueLayerError !== null;\n const isAa = consentId !== null && success !== null;\n if (!isTrueLayer && !isAa) return null;\n\n const pending = takePendingBankLink();\n for (const name of RESULT_PARAMS) params.delete(name);\n window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);\n\n if (!pending) return { kind: 'expired' };\n if (isTrueLayer && pending.aggregator === 'TRUELAYER') {\n if (!code) return { kind: 'declined', aggregator: 'TRUELAYER' };\n return {\n kind: 'complete',\n aggregator: 'TRUELAYER',\n publicToken: code,\n // TrueLayer hands the state back; the stored token is the same value.\n state: state || pending.linkToken,\n connectionId: pending.connectionId,\n };\n }\n if (isAa && pending.aggregator === 'ACCOUNT_AGGREGATOR') {\n if (success !== 'true' || !consentId)\n return { kind: 'declined', aggregator: 'ACCOUNT_AGGREGATOR' };\n return {\n kind: 'complete',\n aggregator: 'ACCOUNT_AGGREGATOR',\n publicToken: consentId,\n state: pending.linkToken,\n connectionId: pending.connectionId,\n };\n }\n return { kind: 'expired' };\n}\n"],"mappings":";AAmBA,IAAM,IAAc,kCAEd,IAAiB,OAAU;AAoBjC,SAAS,IAA0B;CACjC,IAAI;EACF,OAAO,OAAO,SAAW,MAAc,OAAO,OAAO;CACvD,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,EAAoB,GAAmD;CACrF,EAAQ,GAAG,QAAQ,GAAa,KAAK,UAAU;EAAE,GAAG;EAAS,WAAW,KAAK,IAAI;CAAE,CAAC,CAAC;AACvF;AAEA,SAAS,IAA8C;CACrD,IAAM,IAAQ,EAAQ,GAChB,IAAM,GAAO,QAAQ,CAAW;CAEtC,IADA,GAAO,WAAW,CAAW,GACzB,CAAC,GAAK,OAAO;CACjB,IAAI;EACF,IAAM,IAAQ,KAAK,MAAM,CAAG;EAC5B,KACG,EAAM,eAAe,eAAe,EAAM,eAAe,yBAC1D,OAAO,EAAM,aAAc,YAC3B,OAAO,EAAM,aAAc,YAC3B,KAAK,IAAI,IAAI,EAAM,YAAY,GAE/B,OAAO;GACL,YAAY,EAAM;GAClB,WAAW,EAAM;GACjB,cAAc,OAAO,EAAM,gBAAiB,WAAW,EAAM,eAAe;GAC5E,WAAW,EAAM;EACnB;CAEJ,QAAQ,CAER;CACA,OAAO;AACT;AAEA,IAAM,IAAgB;CAAC;CAAQ;CAAS;CAAS;CAAqB;CAAM;CAAW;AAAW;AAMlG,SAAgB,IAAiD;CAC/D,IAAI,OAAO,SAAW,KAAa,OAAO;CAC1C,IAAM,IAAM,IAAI,IAAI,OAAO,SAAS,IAAI,GAClC,IAAS,EAAI,cACb,IAAO,EAAO,IAAI,MAAM,GACxB,IAAQ,EAAO,IAAI,OAAO,GAC1B,IAAiB,EAAO,IA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