@syndew/oluso-workspace-ui 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syndew-oluso-workspace-ui-hosted-document-page.component-BmifVN4H.mjs","sources":["../../../../libs/workspace-ui/src/lib/pages/hosted-document/hosted-document-page.component.ts"],"sourcesContent":["import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, computed, inject, signal } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { HttpBackend, HttpClient } from '@angular/common/http';\nimport { LocaleDatePipe } from '@syndew/oluso-ui-core';\nimport { apiUrl } from '../../auth/oidc.config';\n\n/**\n * Anonymous hosted view of a customer-facing document (an invoice today,\n * quotes next). The magic-link token comes from the URL fragment\n * (#tk=…&dl=1) so it never reaches server logs. The page previews the token\n * through the public links API, renders the document it carries, offers the\n * PDF through the file endpoint, and shows any actions the handler exposes.\n */\ninterface DocumentParty {\n name: string;\n contactName?: string;\n addressLines: string[];\n email?: string;\n phone?: string;\n taxId?: string;\n}\n\ninterface DocumentLine {\n lineNumber: number;\n description: string;\n productCode?: string;\n quantity: number;\n unitPrice: number;\n discount: number;\n taxRate?: number;\n tax: number;\n amount: number;\n}\n\ninterface HostedDocument {\n kind: string;\n number: string;\n status: string;\n statusLabel?: string;\n payable?: boolean;\n acceptedByName?: string;\n purchaseOrderNumber?: string;\n currencyCode: string;\n issueDate: string;\n dueDate?: string;\n dueLabel: string;\n company: DocumentParty;\n customer: DocumentParty;\n lines: DocumentLine[];\n surcharges: DocumentLine[];\n subtotal: number;\n discount: number;\n tax: number;\n fees: number;\n total: number;\n amountPaid: number;\n balanceDue: number;\n notes?: string;\n terms?: string;\n paymentInstructions?: string;\n footer?: string;\n branding?: { accentColor?: string; logoUrl?: string };\n}\n\ninterface DocumentField {\n key: string;\n label: string;\n required?: boolean;\n placeholder?: string;\n maxLength?: number;\n}\n\ninterface DocumentOption {\n key: string;\n label: string;\n variant: string;\n requiresComments?: boolean;\n commentsRequired?: boolean;\n fields?: DocumentField[];\n}\n\ninterface DocumentPreview {\n title: string;\n summary?: string;\n description?: string;\n options: DocumentOption[];\n alreadyActioned: boolean;\n alreadyActionedReason?: string;\n locked?: boolean;\n lockMode?: 'email' | 'code';\n data?: { document?: HostedDocument; branding?: { accentColor?: string; logoUrl?: string } };\n}\n\n/** The unlock proof is kept per link in this browser so reopening does not ask again. */\nfunction unlockStorageKey(token: string): string {\n return `oluso.link-unlock.${token.slice(0, 16)}`;\n}\n\nfunction readUnlock(token: string): string | null {\n try {\n return localStorage.getItem(unlockStorageKey(token));\n } catch {\n return null;\n }\n}\n\nfunction storeUnlock(token: string, proof: string): void {\n try {\n localStorage.setItem(unlockStorageKey(token), proof);\n } catch {\n // Private windows can refuse storage; the visitor unlocks again next time.\n }\n}\n\ninterface UnlockResponse {\n unlock?: string;\n codeSent?: boolean;\n message?: string;\n}\n\ninterface ExecuteResult {\n message: string;\n}\n\n@Component({\n selector: 'workspace-hosted-document-page',\n standalone: true,\n imports: [CommonModule, LocaleDatePipe],\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n <div class=\"min-h-screen bg-gray-100 py-8 px-4\" [style]=\"brandStyle()\">\n <div class=\"mx-auto max-w-3xl\">\n @if (loading()) {\n <div class=\"bg-white rounded-lg shadow p-8 text-center\">\n <div class=\"inline-block h-8 w-8 rounded-full border-2 border-primary-600 border-t-transparent animate-spin\"></div>\n <p class=\"mt-3 text-sm text-gray-500\">Loading…</p>\n </div>\n } @else if (loadError()) {\n <div class=\"bg-white rounded-lg shadow p-8 text-center\">\n <h1 class=\"text-lg font-semibold text-gray-900 mb-2\">Link unavailable</h1>\n <p class=\"text-sm text-gray-600\">{{ loadError() }}</p>\n </div>\n } @else if (preview()?.locked) {\n @if (branding()?.logoUrl && !logoFailed()) {\n <div class=\"mb-4\">\n <img [src]=\"branding()!.logoUrl\" alt=\"\" (error)=\"logoFailed.set(true)\" class=\"max-h-12 max-w-[12rem] object-contain\" />\n </div>\n }\n <div class=\"bg-white rounded-lg shadow p-6 sm:p-8 max-w-md\">\n <h1 class=\"text-lg font-semibold text-gray-900\">{{ preview()?.title }}</h1>\n <p class=\"mt-1 text-sm text-gray-600\">\n @if (codeSent()) {\n Enter the 6-digit code we emailed to {{ unlockEmail }}.\n } @else {\n To keep it private, confirm the email address this was sent to.\n }\n </p>\n <form class=\"mt-5 space-y-3\" (submit)=\"submitUnlock($event)\">\n @if (!codeSent()) {\n <div>\n <label for=\"unlock-email\" class=\"block text-sm font-medium text-gray-700 mb-1\">Email address</label>\n <input id=\"unlock-email\" type=\"email\" autocomplete=\"email\" [value]=\"unlockEmail\" (input)=\"unlockEmail = inputValue($event)\"\n class=\"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-primary-500 focus:ring-primary-500\" />\n </div>\n } @else {\n <div>\n <label for=\"unlock-code\" class=\"block text-sm font-medium text-gray-700 mb-1\">Code</label>\n <input id=\"unlock-code\" inputmode=\"numeric\" autocomplete=\"one-time-code\" maxlength=\"6\" [value]=\"unlockCode\" (input)=\"unlockCode = inputValue($event)\"\n class=\"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm tracking-widest focus:border-primary-500 focus:ring-primary-500\" />\n </div>\n }\n @if (unlockMessage()) {\n <p class=\"text-sm\" [class]=\"unlockFailed() ? 'text-red-700' : 'text-gray-600'\">{{ unlockMessage() }}</p>\n }\n <div class=\"flex items-center gap-3\">\n <button type=\"submit\" [disabled]=\"unlocking() || (codeSent() ? unlockCode.trim().length !== 6 : !unlockEmail.trim())\"\n class=\"px-3 py-2 rounded-md text-sm font-medium text-white bg-primary-600 hover:bg-primary-700 disabled:opacity-50\">\n {{ unlocking() ? 'Checking…' : codeSent() ? 'Open' : preview()?.lockMode === 'code' ? 'Send code' : 'Open' }}\n </button>\n @if (codeSent()) {\n <button type=\"button\" (click)=\"resendCode()\" [disabled]=\"unlocking()\" class=\"text-sm text-gray-600 hover:underline\">Send a new code</button>\n <button type=\"button\" (click)=\"changeEmail()\" [disabled]=\"unlocking()\" class=\"text-sm text-gray-600 hover:underline\">Use a different email</button>\n }\n </div>\n </form>\n </div>\n } @else if (document(); as doc) {\n @if (doc.branding?.logoUrl && !logoFailed()) {\n <div class=\"mb-4\">\n <img [src]=\"doc.branding!.logoUrl\" [alt]=\"doc.company.name\" (error)=\"logoFailed.set(true)\" class=\"max-h-12 max-w-[12rem] object-contain\" />\n </div>\n }\n <!-- Phones: title, then the response buttons side by side, then the download full width. -->\n <div class=\"flex flex-col gap-3 mb-4 sm:flex-row sm:items-center sm:justify-between\">\n <div class=\"min-w-0\">\n <h1 class=\"text-xl font-semibold text-gray-900 break-words\">{{ doc.kind }} {{ doc.number }}</h1>\n @if (preview()?.summary) {\n <p class=\"text-sm text-gray-600\">{{ preview()?.summary }}</p>\n }\n </div>\n <div class=\"grid grid-cols-2 gap-2 sm:flex sm:items-center sm:shrink-0\">\n <button\n type=\"button\"\n (click)=\"downloadPdf()\"\n [disabled]=\"downloading()\"\n class=\"col-span-2 order-last sm:order-none px-3 py-2.5 sm:py-2 rounded-md text-sm font-medium border border-primary-600 text-primary-700 bg-white hover:bg-primary-50 disabled:opacity-50 whitespace-nowrap\"\n >\n {{ downloading() ? 'Preparing…' : 'Download PDF' }}\n </button>\n @for (opt of preview()?.options ?? []; track opt.key) {\n <button\n type=\"button\"\n (click)=\"act(opt)\"\n [disabled]=\"submitting()\"\n class=\"px-3 py-2.5 sm:py-2 rounded-md text-sm font-medium text-white disabled:opacity-50 whitespace-nowrap\"\n [class.col-span-2]=\"(preview()?.options?.length ?? 0) === 1\"\n [class]=\"variantClass(opt.variant)\"\n >\n {{ opt.label }}\n </button>\n }\n </div>\n </div>\n\n @if (pendingOption(); as pending) {\n <div class=\"bg-gray-50 border border-gray-200 rounded-md p-4 mb-4 space-y-3\">\n @for (field of pending.fields ?? []; track field.key) {\n <div>\n <label [for]=\"'field-' + field.key\" class=\"block text-sm font-medium text-gray-700 mb-1\">{{ field.label }}</label>\n <input\n [id]=\"'field-' + field.key\"\n type=\"text\"\n [value]=\"fieldValues[field.key] ?? ''\"\n (input)=\"onFieldInput(field.key, $event)\"\n [attr.maxlength]=\"field.maxLength ?? 200\"\n [placeholder]=\"field.placeholder ?? ''\"\n class=\"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-primary-500 focus:ring-primary-500\"\n />\n </div>\n }\n @if (pending.requiresComments) {\n <div>\n <label for=\"option-comments\" class=\"block text-sm font-medium text-gray-700 mb-1\">\n {{ pending.label }} — add a note{{ pending.commentsRequired ? '' : ' (optional)' }}\n </label>\n <textarea\n id=\"option-comments\"\n rows=\"3\"\n [value]=\"comments\"\n (input)=\"onCommentsInput($event)\"\n class=\"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-primary-500 focus:ring-primary-500\"\n placeholder=\"Let them know why\"\n ></textarea>\n </div>\n }\n <div class=\"flex items-center gap-2\">\n <button\n type=\"button\"\n (click)=\"submit(pending)\"\n [disabled]=\"submitting() || !canSubmit(pending)\"\n class=\"px-3 py-2 rounded-md text-sm font-medium text-white disabled:opacity-50\"\n [class]=\"variantClass(pending.variant)\"\n >\n {{ submitting() ? 'Sending…' : 'Confirm ' + pending.label.toLowerCase() }}\n </button>\n <button\n type=\"button\"\n (click)=\"cancelPending()\"\n [disabled]=\"submitting()\"\n class=\"px-3 py-2 rounded-md text-sm font-medium border border-gray-300 text-gray-700 bg-white hover:bg-gray-50 disabled:opacity-50\"\n >\n Cancel\n </button>\n </div>\n </div>\n }\n @if (actionResult(); as r) {\n <div class=\"bg-emerald-50 border border-emerald-200 rounded-md p-4 mb-4 text-sm text-emerald-800\">{{ r.message }}</div>\n }\n @if (actionError(); as err) {\n <div class=\"bg-red-50 border border-red-200 rounded-md p-4 mb-4 text-sm text-red-700\">{{ err }}</div>\n }\n @if (preview()?.alreadyActioned) {\n <div class=\"bg-gray-50 border border-gray-200 rounded-md p-4 mb-4 text-sm text-gray-600\">\n {{ preview()?.alreadyActionedReason || 'This document has already been actioned.' }}\n </div>\n }\n\n <div class=\"bg-white rounded-lg shadow p-4 sm:p-8\">\n <div class=\"flex flex-col gap-4 mb-6 sm:flex-row sm:justify-between sm:gap-8 sm:mb-8\">\n <div class=\"text-sm\">\n <div class=\"text-base font-semibold text-gray-900\">{{ doc.company.name }}</div>\n @for (line of doc.company.addressLines; track $index) {\n <div class=\"text-gray-600\">{{ line }}</div>\n }\n @if (doc.company.taxId) {\n <div class=\"text-gray-600\">Tax ID: {{ doc.company.taxId }}</div>\n }\n </div>\n <div class=\"text-sm sm:text-right\">\n <div class=\"text-2xl font-bold text-primary-700 uppercase\">{{ doc.kind }}</div>\n <div class=\"font-semibold text-gray-900\">{{ doc.number }}</div>\n <div class=\"text-gray-600 mt-1\">Date: {{ doc.issueDate | localeDate: 'mediumDate' }}</div>\n @if (doc.dueDate) {\n <div class=\"text-gray-600\">{{ doc.dueLabel }}: {{ doc.dueDate | localeDate: 'mediumDate' }}</div>\n }\n <div class=\"text-gray-500\">Status: {{ doc.statusLabel || doc.status }}</div>\n @if (doc.purchaseOrderNumber) {\n <div class=\"text-gray-500\">PO: {{ doc.purchaseOrderNumber }}</div>\n }\n </div>\n </div>\n\n <div class=\"text-sm mb-6\">\n <div class=\"text-xs font-medium uppercase tracking-wide text-gray-500 mb-1\">Bill to</div>\n <div class=\"font-semibold text-gray-900\">{{ doc.customer.name }}</div>\n @if (doc.customer.contactName) {\n <div class=\"text-gray-700\">{{ doc.customer.contactName }}</div>\n }\n @for (line of doc.customer.addressLines; track $index) {\n <div class=\"text-gray-600\">{{ line }}</div>\n }\n @if (doc.customer.email) {\n <div class=\"text-gray-600\">{{ doc.customer.email }}</div>\n }\n </div>\n\n <!-- Phones keep two columns: quantity, price and tax move under the description. -->\n <table class=\"w-full text-sm\">\n <thead>\n <tr class=\"border-b border-gray-300 text-left text-gray-600\">\n <th class=\"hidden sm:table-cell py-2 pr-2 w-8\">#</th>\n <th class=\"py-2 pr-2\">Description</th>\n <th class=\"hidden sm:table-cell py-2 pr-2 text-right\">Qty</th>\n <th class=\"hidden sm:table-cell py-2 pr-2 text-right\">Unit price</th>\n <th class=\"hidden sm:table-cell py-2 pr-2 text-right\">Tax</th>\n <th class=\"py-2 text-right\">Amount</th>\n </tr>\n </thead>\n <tbody>\n @for (line of doc.lines; track line.lineNumber) {\n <tr class=\"border-b border-gray-100\">\n <td class=\"hidden sm:table-cell py-2 pr-2 text-gray-500\">{{ line.lineNumber }}</td>\n <td class=\"py-2 pr-2\">\n <div class=\"text-gray-900\">{{ line.description }}</div>\n @if (line.productCode) {\n <div class=\"text-xs text-gray-500\">{{ line.productCode }}</div>\n }\n @if (line.discount > 0) {\n <div class=\"text-xs text-gray-500\">Discount {{ money(line.discount, doc.currencyCode) }}</div>\n }\n <div class=\"sm:hidden text-xs text-gray-500\">\n {{ line.quantity }} × {{ money(line.unitPrice, doc.currencyCode) }} · Tax {{ money(line.tax, doc.currencyCode) }}{{ line.taxRate ? ' (' + line.taxRate + '%)' : '' }}\n </div>\n </td>\n <td class=\"hidden sm:table-cell py-2 pr-2 text-right\">{{ line.quantity }}</td>\n <td class=\"hidden sm:table-cell py-2 pr-2 text-right\">{{ money(line.unitPrice, doc.currencyCode) }}</td>\n <td class=\"hidden sm:table-cell py-2 pr-2 text-right\">\n {{ money(line.tax, doc.currencyCode) }}\n @if (line.taxRate) {\n <div class=\"text-xs text-gray-500\">{{ line.taxRate }}%</div>\n }\n </td>\n <td class=\"py-2 text-right whitespace-nowrap align-top\">{{ money(line.amount, doc.currencyCode) }}</td>\n </tr>\n }\n @for (s of doc.surcharges; track $index) {\n <tr class=\"border-b border-gray-100\">\n <td class=\"hidden sm:table-cell py-2 pr-2\"></td>\n <td class=\"py-2 pr-2 text-gray-900\">\n {{ s.description }}\n <div class=\"sm:hidden text-xs text-gray-500\">Tax {{ money(s.tax, doc.currencyCode) }}</div>\n </td>\n <td class=\"hidden sm:table-cell py-2 pr-2 text-right\">1</td>\n <td class=\"hidden sm:table-cell py-2 pr-2 text-right\">{{ money(s.unitPrice, doc.currencyCode) }}</td>\n <td class=\"hidden sm:table-cell py-2 pr-2 text-right\">{{ money(s.tax, doc.currencyCode) }}</td>\n <td class=\"py-2 text-right whitespace-nowrap align-top\">{{ money(s.amount, doc.currencyCode) }}</td>\n </tr>\n }\n </tbody>\n </table>\n\n <div class=\"flex justify-end mt-6\">\n <div class=\"w-full sm:w-72 text-sm\">\n <div class=\"flex justify-between py-1 border-b border-gray-100\"><span>Subtotal</span><span>{{ money(doc.subtotal, doc.currencyCode) }}</span></div>\n @if (doc.discount > 0) {\n <div class=\"flex justify-between py-1 border-b border-gray-100\"><span>Discount</span><span>-{{ money(doc.discount, doc.currencyCode) }}</span></div>\n }\n @if (doc.fees > 0) {\n <div class=\"flex justify-between py-1 border-b border-gray-100\"><span>Fees</span><span>{{ money(doc.fees, doc.currencyCode) }}</span></div>\n }\n <div class=\"flex justify-between py-1 border-b border-gray-100\"><span>Tax</span><span>{{ money(doc.tax, doc.currencyCode) }}</span></div>\n <div class=\"flex justify-between py-1 border-b border-gray-100 font-semibold\"><span>Total</span><span>{{ money(doc.total, doc.currencyCode) }}</span></div>\n @if (doc.amountPaid > 0) {\n <div class=\"flex justify-between py-1 border-b border-gray-100\"><span>Paid</span><span>-{{ money(doc.amountPaid, doc.currencyCode) }}</span></div>\n }\n @if (doc.kind === 'Invoice') {\n <div class=\"flex justify-between py-1 font-semibold text-primary-700\"><span>Balance due</span><span>{{ money(doc.balanceDue, doc.currencyCode) }}</span></div>\n }\n </div>\n </div>\n\n @if (doc.paymentInstructions && doc.payable !== false) {\n <div class=\"mt-8 text-sm\">\n <div class=\"text-xs font-medium uppercase tracking-wide text-gray-500 mb-1\">How to pay</div>\n <div class=\"text-gray-800 whitespace-pre-line\">{{ doc.paymentInstructions }}</div>\n </div>\n }\n @if (doc.notes) {\n <div class=\"mt-6 text-sm\">\n <div class=\"text-xs font-medium uppercase tracking-wide text-gray-500 mb-1\">Notes</div>\n <div class=\"text-gray-800 whitespace-pre-line\">{{ doc.notes }}</div>\n </div>\n }\n @if (doc.terms) {\n <div class=\"mt-6 text-sm\">\n <div class=\"text-xs font-medium uppercase tracking-wide text-gray-500 mb-1\">Terms</div>\n <div class=\"text-gray-800 whitespace-pre-line\">{{ doc.terms }}</div>\n </div>\n }\n @if (doc.footer) {\n <div class=\"mt-8 pt-4 border-t border-gray-200 text-center text-xs text-gray-500\">{{ doc.footer }}</div>\n }\n </div>\n }\n </div>\n </div>\n `,\n})\nexport class HostedDocumentPageComponent implements OnInit {\n /** Bypasses the app's interceptors: the token is the only credential, so no session token or tenant header rides along. */\n private readonly http = new HttpClient(inject(HttpBackend));\n private readonly cdr = inject(ChangeDetectorRef);\n\n readonly loading = signal(true);\n readonly loadError = signal<string | null>(null);\n readonly preview = signal<DocumentPreview | null>(null);\n readonly document = signal<HostedDocument | null>(null);\n readonly downloading = signal(false);\n readonly submitting = signal(false);\n readonly pendingOption = signal<DocumentOption | null>(null);\n comments = '';\n fieldValues: Record<string, string> = {};\n readonly logoFailed = signal(false);\n readonly branding = computed(() => this.document()?.branding ?? this.preview()?.data?.branding ?? null);\n\n unlockEmail = '';\n unlockCode = '';\n private unlockProof: string | null = null;\n readonly unlocking = signal(false);\n readonly codeSent = signal(false);\n readonly unlockMessage = signal<string | null>(null);\n readonly unlockFailed = signal(false);\n\n /**\n * The tenant's colour in place of the host app's theme on this page: the\n * primary palette is derived from the one accent colour the tenant set.\n */\n readonly brandStyle = computed(() => {\n const accent = this.branding()?.accentColor;\n if (!accent || !/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(accent)) return '';\n return [\n `--color-primary-50: color-mix(in srgb, ${accent} 8%, white)`,\n `--color-primary-100: color-mix(in srgb, ${accent} 16%, white)`,\n `--color-primary-500: color-mix(in srgb, ${accent} 85%, white)`,\n `--color-primary-600: ${accent}`,\n `--color-primary-700: color-mix(in srgb, ${accent} 82%, black)`,\n ].join('; ');\n });\n readonly actionResult = signal<ExecuteResult | null>(null);\n readonly actionError = signal<string | null>(null);\n\n private token = '';\n private autoDownload = false;\n\n ngOnInit(): void {\n const fragment = readFragment();\n this.token = fragment.get('tk') ?? '';\n this.autoDownload = fragment.get('dl') === '1';\n\n if (!this.token) {\n this.loading.set(false);\n this.loadError.set('This link is missing or malformed.');\n return;\n }\n\n this.unlockProof = readUnlock(this.token);\n this.loadPreview();\n }\n\n private loadPreview(): void {\n this.http.post<DocumentPreview>(`${apiUrl}/api/public/links/preview`, { token: this.token, unlock: this.unlockProof }).subscribe({\n next: (dto) => {\n this.preview.set(dto);\n this.document.set(dto.data?.document ?? null);\n if (!dto.locked && !dto.data?.document) {\n this.loadError.set(dto.alreadyActionedReason || 'This link does not carry a document.');\n }\n this.loading.set(false);\n this.cdr.markForCheck();\n if (this.autoDownload && dto.data?.document) {\n this.downloadPdf();\n }\n },\n error: (err) => {\n this.loadError.set(err?.error?.message || 'This link is invalid, expired, or has already been used.');\n this.loading.set(false);\n this.cdr.markForCheck();\n },\n });\n }\n\n inputValue(event: Event): string {\n return (event.target as HTMLInputElement).value;\n }\n\n submitUnlock(event: Event): void {\n event.preventDefault();\n this.unlock(this.codeSent() ? this.unlockCode.trim() : null);\n }\n\n resendCode(): void {\n this.unlockCode = '';\n this.unlock(null);\n }\n\n changeEmail(): void {\n this.codeSent.set(false);\n this.unlockCode = '';\n this.unlockMessage.set(null);\n this.unlockFailed.set(false);\n }\n\n private unlock(code: string | null): void {\n if (this.unlocking()) return;\n this.unlocking.set(true);\n this.unlockMessage.set(null);\n this.unlockFailed.set(false);\n this.http\n .post<UnlockResponse>(`${apiUrl}/api/public/links/unlock`, { token: this.token, email: this.unlockEmail.trim(), code })\n .subscribe({\n next: (res) => {\n this.unlocking.set(false);\n if (res.unlock) {\n this.unlockProof = res.unlock;\n storeUnlock(this.token, res.unlock);\n this.loading.set(true);\n this.loadPreview();\n } else if (res.codeSent) {\n this.codeSent.set(true);\n this.unlockMessage.set(res.message ?? null);\n } else {\n this.loadPreview();\n }\n this.cdr.markForCheck();\n },\n error: (err) => {\n this.unlocking.set(false);\n this.unlockFailed.set(true);\n this.unlockMessage.set(err?.error?.message || err?.error?.Message || 'That did not work. Try again.');\n this.cdr.markForCheck();\n },\n });\n }\n\n downloadPdf(): void {\n if (this.downloading()) return;\n this.downloading.set(true);\n this.http\n .post(`${apiUrl}/api/public/links/file`, { token: this.token, unlock: this.unlockProof }, { responseType: 'blob', observe: 'response' })\n .subscribe({\n next: (res) => {\n const doc = this.document();\n const name = fileNameFrom(res.headers.get('content-disposition')) ?? `${doc?.kind ?? 'document'}-${doc?.number ?? ''}.pdf`;\n const url = URL.createObjectURL(res.body as Blob);\n const a = window.document.createElement('a');\n a.href = url;\n a.download = name;\n a.click();\n URL.revokeObjectURL(url);\n this.downloading.set(false);\n this.cdr.markForCheck();\n },\n error: () => {\n this.actionError.set('The PDF could not be downloaded.');\n this.downloading.set(false);\n this.cdr.markForCheck();\n },\n });\n }\n\n act(option: DocumentOption): void {\n if (this.submitting()) return;\n if (option.requiresComments || (option.fields?.length ?? 0) > 0) {\n this.comments = '';\n this.fieldValues = {};\n this.pendingOption.set(option);\n return;\n }\n this.submit(option);\n }\n\n cancelPending(): void {\n this.pendingOption.set(null);\n this.comments = '';\n this.fieldValues = {};\n }\n\n onFieldInput(key: string, event: Event): void {\n this.fieldValues = { ...this.fieldValues, [key]: (event.target as HTMLInputElement).value };\n }\n\n canSubmit(option: DocumentOption): boolean {\n if (option.commentsRequired && !this.comments.trim()) return false;\n return (option.fields ?? []).every((f) => !f.required || (this.fieldValues[f.key] ?? '').trim() !== '');\n }\n\n onCommentsInput(event: Event): void {\n this.comments = (event.target as HTMLTextAreaElement).value;\n }\n\n submit(option: DocumentOption): void {\n if (this.submitting()) return;\n if (!this.canSubmit(option)) return;\n this.submitting.set(true);\n this.actionError.set(null);\n const comments = this.comments.trim() || null;\n const fields: Record<string, string> = {};\n for (const field of option.fields ?? []) {\n const value = (this.fieldValues[field.key] ?? '').trim();\n if (value) fields[field.key] = value;\n }\n this.http\n .post<ExecuteResult>(`${apiUrl}/api/public/links/redeem`, { token: this.token, option: option.key, comments, fields, unlock: this.unlockProof })\n .subscribe({\n next: (res) => {\n this.pendingOption.set(null);\n this.comments = '';\n this.fieldValues = {};\n this.actionResult.set(res);\n this.preview.update((p) => (p ? { ...p, options: [], alreadyActioned: true, alreadyActionedReason: res.message } : p));\n this.submitting.set(false);\n this.cdr.markForCheck();\n },\n error: (err) => {\n this.actionError.set(err?.error?.message || err?.error?.error || 'The action could not be completed.');\n this.submitting.set(false);\n this.cdr.markForCheck();\n },\n });\n }\n\n /** Symbol formatting in the viewer's locale (\"£1,234.56\"); falls back to the code when the browser does not know it. */\n money(amount: number, currency: string): string {\n try {\n return new Intl.NumberFormat(undefined, { style: 'currency', currency, currencyDisplay: 'narrowSymbol' }).format(amount);\n } catch {\n return `${amount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${currency}`;\n }\n }\n\n variantClass(variant: string): string {\n switch (variant) {\n case 'danger':\n return 'bg-red-600 hover:bg-red-700';\n case 'secondary':\n return 'bg-gray-600 hover:bg-gray-700';\n default:\n return 'bg-primary-600 hover:bg-primary-700';\n }\n }\n}\n\nfunction readFragment(): URLSearchParams {\n if (typeof window === 'undefined') return new URLSearchParams();\n return new URLSearchParams(window.location.hash.replace(/^#/, ''));\n}\n\nfunction fileNameFrom(contentDisposition: string | null): string | null {\n if (!contentDisposition) return null;\n const utf8 = /filename\\*=UTF-8''([^;]+)/i.exec(contentDisposition);\n if (utf8) return decodeURIComponent(utf8[1]);\n const plain = /filename=\"?([^\";]+)\"?/i.exec(contentDisposition);\n return plain ? plain[1] : null;\n}\n"],"names":[],"mappings":";;;;;;;AA6FA;AACA,SAAS,gBAAgB,CAAC,KAAa,EAAA;IACrC,OAAO,CAAA,kBAAA,EAAqB,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0ST,EAAA,CAAA;AACF,iBAAA;;AAqPD,SAAS,YAAY,GAAA;IACnB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,eAAe,EAAE;AAC/D,IAAA,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACpE;AAEA,SAAS,YAAY,CAAC,kBAAiC,EAAA;AACrD,IAAA,IAAI,CAAC,kBAAkB;AAAE,QAAA,OAAO,IAAI;IACpC,MAAM,IAAI,GAAG,4BAA4B,CAAC,IAAI,CAAC,kBAAkB,CAAC;AAClE,IAAA,IAAI,IAAI;AAAE,QAAA,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,kBAAkB,CAAC;AAC/D,IAAA,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI;AAChC;;;;"}
@@ -0,0 +1,331 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, ChangeDetectorRef, signal, ChangeDetectionStrategy, Component } from '@angular/core';
3
+ import { CommonModule } from '@angular/common';
4
+ import * as i1 from '@angular/forms';
5
+ import { FormsModule } from '@angular/forms';
6
+ import { HttpClient, HttpBackend } from '@angular/common/http';
7
+ import { apiUrl } from './syndew-oluso-workspace-ui.mjs';
8
+
9
+ class MagicLinkPageComponent {
10
+ /** Bypasses the app's interceptors: the token is the only credential, so no session token or tenant header rides along. */
11
+ http = new HttpClient(inject(HttpBackend));
12
+ cdr = inject(ChangeDetectorRef);
13
+ loading = signal(true, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
14
+ loadError = signal(null, ...(ngDevMode ? [{ debugName: "loadError" }] : /* istanbul ignore next */ []));
15
+ preview = signal(null, ...(ngDevMode ? [{ debugName: "preview" }] : /* istanbul ignore next */ []));
16
+ submitting = signal(false, ...(ngDevMode ? [{ debugName: "submitting" }] : /* istanbul ignore next */ []));
17
+ submitError = signal(null, ...(ngDevMode ? [{ debugName: "submitError" }] : /* istanbul ignore next */ []));
18
+ result = signal(null, ...(ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []));
19
+ selectedOption = signal(null, ...(ngDevMode ? [{ debugName: "selectedOption" }] : /* istanbul ignore next */ []));
20
+ comments = '';
21
+ // Token is read from the URL fragment so it never appears in server
22
+ // logs, browser history auto-complete, or Referer headers.
23
+ token = '';
24
+ ngOnInit() {
25
+ this.token = extractFragmentToken();
26
+ if (!this.token) {
27
+ this.loading.set(false);
28
+ this.loadError.set('This link is missing or malformed.');
29
+ return;
30
+ }
31
+ this.http.post(`${apiUrl}/api/public/links/preview`, { token: this.token })
32
+ .subscribe({
33
+ next: (dto) => {
34
+ this.preview.set(dto);
35
+ this.loading.set(false);
36
+ this.cdr.markForCheck();
37
+ },
38
+ error: (err) => {
39
+ this.loadError.set(err?.error?.message || 'This link is invalid, expired, or has already been used.');
40
+ this.loading.set(false);
41
+ this.cdr.markForCheck();
42
+ },
43
+ });
44
+ }
45
+ pickOption(option) {
46
+ this.submitError.set(null);
47
+ this.comments = '';
48
+ this.selectedOption.set(option);
49
+ // Auto-submit for options that don't need a comment.
50
+ if (!option.requiresComments) {
51
+ this.confirmOption(option);
52
+ }
53
+ }
54
+ cancelOption() {
55
+ if (this.submitting())
56
+ return;
57
+ this.selectedOption.set(null);
58
+ this.comments = '';
59
+ this.submitError.set(null);
60
+ }
61
+ confirmOption(option) {
62
+ if (this.submitting())
63
+ return;
64
+ if (option.commentsRequired && !this.comments.trim()) {
65
+ this.submitError.set('A comment is required.');
66
+ return;
67
+ }
68
+ this.submitting.set(true);
69
+ this.submitError.set(null);
70
+ this.http
71
+ .post(`${apiUrl}/api/public/links/redeem`, {
72
+ token: this.token,
73
+ option: option.key,
74
+ comments: this.comments.trim() || undefined,
75
+ })
76
+ .subscribe({
77
+ next: (res) => {
78
+ this.result.set(res);
79
+ this.submitting.set(false);
80
+ this.cdr.markForCheck();
81
+ // Drop the fragment from the URL so a refresh doesn't try to
82
+ // re-redeem an already-consumed token.
83
+ if (typeof window !== 'undefined' && window.history?.replaceState) {
84
+ const cleanUrl = window.location.pathname + window.location.search;
85
+ window.history.replaceState(null, '', cleanUrl);
86
+ }
87
+ },
88
+ error: (err) => {
89
+ this.submitting.set(false);
90
+ this.submitError.set(err?.error?.message || 'Could not submit. The link may have just been used.');
91
+ this.cdr.markForCheck();
92
+ },
93
+ });
94
+ }
95
+ variantClass(variant) {
96
+ switch (variant) {
97
+ case 'danger':
98
+ return 'bg-red-600 hover:bg-red-700';
99
+ case 'warning':
100
+ return 'bg-amber-600 hover:bg-amber-700';
101
+ case 'neutral':
102
+ return 'bg-gray-600 hover:bg-gray-700';
103
+ default:
104
+ return 'bg-primary-600 hover:bg-primary-700';
105
+ }
106
+ }
107
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: MagicLinkPageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
108
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.25", type: MagicLinkPageComponent, isStandalone: true, selector: "app-magic-link-page", ngImport: i0, template: `
109
+ <div class="min-h-screen flex items-center justify-center bg-gray-50 px-4 py-10">
110
+ <div class="max-w-lg w-full bg-white border border-gray-200 rounded-lg shadow-sm p-8 space-y-5">
111
+ @if (loading()) {
112
+ <div class="text-center py-6">
113
+ <div class="inline-block h-8 w-8 rounded-full border-2 border-primary-600 border-t-transparent animate-spin"></div>
114
+ <p class="mt-3 text-sm text-gray-500">Loading…</p>
115
+ </div>
116
+ } @else if (loadError()) {
117
+ <div class="text-center">
118
+ <div class="mx-auto h-12 w-12 rounded-full bg-amber-100 flex items-center justify-center mb-3">
119
+ <svg class="h-6 w-6 text-amber-600" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
120
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" />
121
+ </svg>
122
+ </div>
123
+ <h1 class="text-lg font-semibold text-gray-900 mb-2">Link unavailable</h1>
124
+ <p class="text-sm text-gray-600">{{ loadError() }}</p>
125
+ </div>
126
+ } @else if (result(); as r) {
127
+ <div class="text-center">
128
+ <div class="mx-auto h-12 w-12 rounded-full bg-emerald-100 flex items-center justify-center mb-3">
129
+ <svg class="h-6 w-6 text-emerald-600" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
130
+ <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
131
+ </svg>
132
+ </div>
133
+ <h1 class="text-lg font-semibold text-gray-900 mb-1">{{ r.message }}</h1>
134
+ <p class="text-sm text-gray-500">You can close this page.</p>
135
+ </div>
136
+ } @else if (preview(); as p) {
137
+ <div>
138
+ <h1 class="text-lg font-semibold text-gray-900">{{ p.title }}</h1>
139
+ @if (p.summary) {
140
+ <p class="mt-1 text-sm text-gray-700">{{ p.summary }}</p>
141
+ }
142
+ @if (p.description) {
143
+ <p class="mt-2 text-xs text-gray-500">{{ p.description }}</p>
144
+ }
145
+ </div>
146
+
147
+ @if (p.alreadyActioned) {
148
+ <div class="bg-gray-50 border border-gray-200 rounded-md p-4 text-sm text-gray-600">
149
+ {{ p.alreadyActionedReason || 'This link has already been actioned.' }}
150
+ </div>
151
+ } @else {
152
+ @if (selectedOption(); as opt) {
153
+ @if (opt.requiresComments) {
154
+ <div>
155
+ <label class="block text-xs font-medium text-gray-700 mb-1">
156
+ {{ opt.commentsRequired ? 'Comment (required)' : 'Comment (optional)' }}
157
+ </label>
158
+ <textarea
159
+ [(ngModel)]="comments"
160
+ [disabled]="submitting()"
161
+ rows="3"
162
+ class="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500 disabled:opacity-50"
163
+ [placeholder]="opt.label + '…'"
164
+ ></textarea>
165
+ </div>
166
+ }
167
+ @if (submitError(); as err) {
168
+ <p class="text-sm text-red-600">{{ err }}</p>
169
+ }
170
+ <div class="flex items-center justify-end gap-2">
171
+ <button
172
+ type="button"
173
+ (click)="cancelOption()"
174
+ [disabled]="submitting()"
175
+ class="px-3 py-1.5 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-100 disabled:opacity-50"
176
+ >
177
+ Back
178
+ </button>
179
+ <button
180
+ type="button"
181
+ (click)="confirmOption(opt)"
182
+ [disabled]="submitting() || (opt.commentsRequired && !comments.trim())"
183
+ class="px-3 py-1.5 rounded-md text-sm font-medium text-white disabled:opacity-50"
184
+ [class]="variantClass(opt.variant)"
185
+ >
186
+ {{ submitting() ? 'Submitting…' : opt.label }}
187
+ </button>
188
+ </div>
189
+ } @else {
190
+ <div class="flex flex-wrap items-center gap-2">
191
+ @for (opt of p.options; track opt.key) {
192
+ <button
193
+ type="button"
194
+ (click)="pickOption(opt)"
195
+ class="px-3 py-1.5 rounded-md text-sm font-medium text-white"
196
+ [class]="variantClass(opt.variant)"
197
+ >
198
+ {{ opt.label }}
199
+ </button>
200
+ }
201
+ </div>
202
+ }
203
+ }
204
+ }
205
+ </div>
206
+ </div>
207
+ `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
208
+ }
209
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: MagicLinkPageComponent, decorators: [{
210
+ type: Component,
211
+ args: [{
212
+ selector: 'app-magic-link-page',
213
+ standalone: true,
214
+ imports: [CommonModule, FormsModule],
215
+ changeDetection: ChangeDetectionStrategy.OnPush,
216
+ template: `
217
+ <div class="min-h-screen flex items-center justify-center bg-gray-50 px-4 py-10">
218
+ <div class="max-w-lg w-full bg-white border border-gray-200 rounded-lg shadow-sm p-8 space-y-5">
219
+ @if (loading()) {
220
+ <div class="text-center py-6">
221
+ <div class="inline-block h-8 w-8 rounded-full border-2 border-primary-600 border-t-transparent animate-spin"></div>
222
+ <p class="mt-3 text-sm text-gray-500">Loading…</p>
223
+ </div>
224
+ } @else if (loadError()) {
225
+ <div class="text-center">
226
+ <div class="mx-auto h-12 w-12 rounded-full bg-amber-100 flex items-center justify-center mb-3">
227
+ <svg class="h-6 w-6 text-amber-600" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
228
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" />
229
+ </svg>
230
+ </div>
231
+ <h1 class="text-lg font-semibold text-gray-900 mb-2">Link unavailable</h1>
232
+ <p class="text-sm text-gray-600">{{ loadError() }}</p>
233
+ </div>
234
+ } @else if (result(); as r) {
235
+ <div class="text-center">
236
+ <div class="mx-auto h-12 w-12 rounded-full bg-emerald-100 flex items-center justify-center mb-3">
237
+ <svg class="h-6 w-6 text-emerald-600" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
238
+ <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
239
+ </svg>
240
+ </div>
241
+ <h1 class="text-lg font-semibold text-gray-900 mb-1">{{ r.message }}</h1>
242
+ <p class="text-sm text-gray-500">You can close this page.</p>
243
+ </div>
244
+ } @else if (preview(); as p) {
245
+ <div>
246
+ <h1 class="text-lg font-semibold text-gray-900">{{ p.title }}</h1>
247
+ @if (p.summary) {
248
+ <p class="mt-1 text-sm text-gray-700">{{ p.summary }}</p>
249
+ }
250
+ @if (p.description) {
251
+ <p class="mt-2 text-xs text-gray-500">{{ p.description }}</p>
252
+ }
253
+ </div>
254
+
255
+ @if (p.alreadyActioned) {
256
+ <div class="bg-gray-50 border border-gray-200 rounded-md p-4 text-sm text-gray-600">
257
+ {{ p.alreadyActionedReason || 'This link has already been actioned.' }}
258
+ </div>
259
+ } @else {
260
+ @if (selectedOption(); as opt) {
261
+ @if (opt.requiresComments) {
262
+ <div>
263
+ <label class="block text-xs font-medium text-gray-700 mb-1">
264
+ {{ opt.commentsRequired ? 'Comment (required)' : 'Comment (optional)' }}
265
+ </label>
266
+ <textarea
267
+ [(ngModel)]="comments"
268
+ [disabled]="submitting()"
269
+ rows="3"
270
+ class="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500 disabled:opacity-50"
271
+ [placeholder]="opt.label + '…'"
272
+ ></textarea>
273
+ </div>
274
+ }
275
+ @if (submitError(); as err) {
276
+ <p class="text-sm text-red-600">{{ err }}</p>
277
+ }
278
+ <div class="flex items-center justify-end gap-2">
279
+ <button
280
+ type="button"
281
+ (click)="cancelOption()"
282
+ [disabled]="submitting()"
283
+ class="px-3 py-1.5 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-100 disabled:opacity-50"
284
+ >
285
+ Back
286
+ </button>
287
+ <button
288
+ type="button"
289
+ (click)="confirmOption(opt)"
290
+ [disabled]="submitting() || (opt.commentsRequired && !comments.trim())"
291
+ class="px-3 py-1.5 rounded-md text-sm font-medium text-white disabled:opacity-50"
292
+ [class]="variantClass(opt.variant)"
293
+ >
294
+ {{ submitting() ? 'Submitting…' : opt.label }}
295
+ </button>
296
+ </div>
297
+ } @else {
298
+ <div class="flex flex-wrap items-center gap-2">
299
+ @for (opt of p.options; track opt.key) {
300
+ <button
301
+ type="button"
302
+ (click)="pickOption(opt)"
303
+ class="px-3 py-1.5 rounded-md text-sm font-medium text-white"
304
+ [class]="variantClass(opt.variant)"
305
+ >
306
+ {{ opt.label }}
307
+ </button>
308
+ }
309
+ </div>
310
+ }
311
+ }
312
+ }
313
+ </div>
314
+ </div>
315
+ `,
316
+ }]
317
+ }] });
318
+ function extractFragmentToken() {
319
+ if (typeof window === 'undefined')
320
+ return '';
321
+ // Fragment looks like "#tk=…" — parse robustly so future params
322
+ // (signature, version, etc.) can be added without breaking older links.
323
+ const hash = window.location.hash.replace(/^#/, '');
324
+ if (!hash)
325
+ return '';
326
+ const params = new URLSearchParams(hash);
327
+ return params.get('tk') ?? '';
328
+ }
329
+
330
+ export { MagicLinkPageComponent };
331
+ //# sourceMappingURL=syndew-oluso-workspace-ui-magic-link-page.component-CBohrM7h.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syndew-oluso-workspace-ui-magic-link-page.component-CBohrM7h.mjs","sources":["../../../../libs/workspace-ui/src/lib/pages/magic-link/magic-link-page.component.ts"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n ChangeDetectorRef,\n Component,\n OnInit,\n inject,\n signal,\n} from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { FormsModule } from '@angular/forms';\nimport { HttpBackend, HttpClient } from '@angular/common/http';\nimport { apiUrl } from '../../auth/oidc.config';\n\n/**\n * Generic anonymous landing page for action-token magic links. The email\n * the user clicked contains `/m#tk=<token>` — the token lives in the URL\n * fragment, which the browser never sends to the server, so it never\n * appears in access logs or Referer headers.\n *\n * On load this reads `window.location.hash`, POSTs the token to\n * `/api/public/links/preview` to fetch the action-specific view-model\n * (title / summary / options), and renders one button per option. Picking\n * an option POSTs to `/api/public/links/redeem` which atomically consumes\n * the token and dispatches to whichever `IActionTokenHandler` is\n * registered server-side.\n *\n * Adding a new magic-link flow (vendor invoice confirm, candidate offer\n * accept, etc.) requires zero frontend changes — only a new handler.\n */\ninterface ActionTokenOption {\n key: string;\n label: string;\n variant: string;\n requiresComments?: boolean;\n commentsRequired?: boolean;\n}\n\ninterface ActionTokenPreview {\n title: string;\n summary?: string;\n description?: string;\n options: ActionTokenOption[];\n alreadyActioned: boolean;\n alreadyActionedReason?: string;\n}\n\ninterface ActionTokenExecuteResult {\n message: string;\n redirectUrl?: string;\n}\n\n@Component({\n selector: 'app-magic-link-page',\n standalone: true,\n imports: [CommonModule, FormsModule],\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n <div class=\"min-h-screen flex items-center justify-center bg-gray-50 px-4 py-10\">\n <div class=\"max-w-lg w-full bg-white border border-gray-200 rounded-lg shadow-sm p-8 space-y-5\">\n @if (loading()) {\n <div class=\"text-center py-6\">\n <div class=\"inline-block h-8 w-8 rounded-full border-2 border-primary-600 border-t-transparent animate-spin\"></div>\n <p class=\"mt-3 text-sm text-gray-500\">Loading…</p>\n </div>\n } @else if (loadError()) {\n <div class=\"text-center\">\n <div class=\"mx-auto h-12 w-12 rounded-full bg-amber-100 flex items-center justify-center mb-3\">\n <svg class=\"h-6 w-6 text-amber-600\" fill=\"none\" viewBox=\"0 0 24 24\" stroke-width=\"1.5\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z\" />\n </svg>\n </div>\n <h1 class=\"text-lg font-semibold text-gray-900 mb-2\">Link unavailable</h1>\n <p class=\"text-sm text-gray-600\">{{ loadError() }}</p>\n </div>\n } @else if (result(); as r) {\n <div class=\"text-center\">\n <div class=\"mx-auto h-12 w-12 rounded-full bg-emerald-100 flex items-center justify-center mb-3\">\n <svg class=\"h-6 w-6 text-emerald-600\" fill=\"none\" viewBox=\"0 0 24 24\" stroke-width=\"1.5\" stroke=\"currentColor\">\n <path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"m4.5 12.75 6 6 9-13.5\" />\n </svg>\n </div>\n <h1 class=\"text-lg font-semibold text-gray-900 mb-1\">{{ r.message }}</h1>\n <p class=\"text-sm text-gray-500\">You can close this page.</p>\n </div>\n } @else if (preview(); as p) {\n <div>\n <h1 class=\"text-lg font-semibold text-gray-900\">{{ p.title }}</h1>\n @if (p.summary) {\n <p class=\"mt-1 text-sm text-gray-700\">{{ p.summary }}</p>\n }\n @if (p.description) {\n <p class=\"mt-2 text-xs text-gray-500\">{{ p.description }}</p>\n }\n </div>\n\n @if (p.alreadyActioned) {\n <div class=\"bg-gray-50 border border-gray-200 rounded-md p-4 text-sm text-gray-600\">\n {{ p.alreadyActionedReason || 'This link has already been actioned.' }}\n </div>\n } @else {\n @if (selectedOption(); as opt) {\n @if (opt.requiresComments) {\n <div>\n <label class=\"block text-xs font-medium text-gray-700 mb-1\">\n {{ opt.commentsRequired ? 'Comment (required)' : 'Comment (optional)' }}\n </label>\n <textarea\n [(ngModel)]=\"comments\"\n [disabled]=\"submitting()\"\n rows=\"3\"\n class=\"w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500 disabled:opacity-50\"\n [placeholder]=\"opt.label + '…'\"\n ></textarea>\n </div>\n }\n @if (submitError(); as err) {\n <p class=\"text-sm text-red-600\">{{ err }}</p>\n }\n <div class=\"flex items-center justify-end gap-2\">\n <button\n type=\"button\"\n (click)=\"cancelOption()\"\n [disabled]=\"submitting()\"\n class=\"px-3 py-1.5 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-100 disabled:opacity-50\"\n >\n Back\n </button>\n <button\n type=\"button\"\n (click)=\"confirmOption(opt)\"\n [disabled]=\"submitting() || (opt.commentsRequired && !comments.trim())\"\n class=\"px-3 py-1.5 rounded-md text-sm font-medium text-white disabled:opacity-50\"\n [class]=\"variantClass(opt.variant)\"\n >\n {{ submitting() ? 'Submitting…' : opt.label }}\n </button>\n </div>\n } @else {\n <div class=\"flex flex-wrap items-center gap-2\">\n @for (opt of p.options; track opt.key) {\n <button\n type=\"button\"\n (click)=\"pickOption(opt)\"\n class=\"px-3 py-1.5 rounded-md text-sm font-medium text-white\"\n [class]=\"variantClass(opt.variant)\"\n >\n {{ opt.label }}\n </button>\n }\n </div>\n }\n }\n }\n </div>\n </div>\n `,\n})\nexport class MagicLinkPageComponent implements OnInit {\n /** Bypasses the app's interceptors: the token is the only credential, so no session token or tenant header rides along. */\n private readonly http = new HttpClient(inject(HttpBackend));\n private readonly cdr = inject(ChangeDetectorRef);\n\n readonly loading = signal(true);\n readonly loadError = signal<string | null>(null);\n readonly preview = signal<ActionTokenPreview | null>(null);\n readonly submitting = signal(false);\n readonly submitError = signal<string | null>(null);\n readonly result = signal<ActionTokenExecuteResult | null>(null);\n readonly selectedOption = signal<ActionTokenOption | null>(null);\n comments = '';\n\n // Token is read from the URL fragment so it never appears in server\n // logs, browser history auto-complete, or Referer headers.\n private token = '';\n\n ngOnInit(): void {\n this.token = extractFragmentToken();\n if (!this.token) {\n this.loading.set(false);\n this.loadError.set('This link is missing or malformed.');\n return;\n }\n\n this.http.post<ActionTokenPreview>(`${apiUrl}/api/public/links/preview`, { token: this.token })\n .subscribe({\n next: (dto) => {\n this.preview.set(dto);\n this.loading.set(false);\n this.cdr.markForCheck();\n },\n error: (err) => {\n this.loadError.set(err?.error?.message || 'This link is invalid, expired, or has already been used.');\n this.loading.set(false);\n this.cdr.markForCheck();\n },\n });\n }\n\n pickOption(option: ActionTokenOption): void {\n this.submitError.set(null);\n this.comments = '';\n this.selectedOption.set(option);\n // Auto-submit for options that don't need a comment.\n if (!option.requiresComments) {\n this.confirmOption(option);\n }\n }\n\n cancelOption(): void {\n if (this.submitting()) return;\n this.selectedOption.set(null);\n this.comments = '';\n this.submitError.set(null);\n }\n\n confirmOption(option: ActionTokenOption): void {\n if (this.submitting()) return;\n if (option.commentsRequired && !this.comments.trim()) {\n this.submitError.set('A comment is required.');\n return;\n }\n this.submitting.set(true);\n this.submitError.set(null);\n this.http\n .post<ActionTokenExecuteResult>(`${apiUrl}/api/public/links/redeem`, {\n token: this.token,\n option: option.key,\n comments: this.comments.trim() || undefined,\n })\n .subscribe({\n next: (res) => {\n this.result.set(res);\n this.submitting.set(false);\n this.cdr.markForCheck();\n // Drop the fragment from the URL so a refresh doesn't try to\n // re-redeem an already-consumed token.\n if (typeof window !== 'undefined' && window.history?.replaceState) {\n const cleanUrl = window.location.pathname + window.location.search;\n window.history.replaceState(null, '', cleanUrl);\n }\n },\n error: (err) => {\n this.submitting.set(false);\n this.submitError.set(err?.error?.message || 'Could not submit. The link may have just been used.');\n this.cdr.markForCheck();\n },\n });\n }\n\n variantClass(variant: string): string {\n switch (variant) {\n case 'danger':\n return 'bg-red-600 hover:bg-red-700';\n case 'warning':\n return 'bg-amber-600 hover:bg-amber-700';\n case 'neutral':\n return 'bg-gray-600 hover:bg-gray-700';\n default:\n return 'bg-primary-600 hover:bg-primary-700';\n }\n }\n}\n\nfunction extractFragmentToken(): string {\n if (typeof window === 'undefined') return '';\n // Fragment looks like \"#tk=…\" — parse robustly so future params\n // (signature, version, etc.) can be added without breaking older links.\n const hash = window.location.hash.replace(/^#/, '');\n if (!hash) return '';\n const params = new URLSearchParams(hash);\n return params.get('tk') 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