/** * Default success HTML template for OAuth authorization */ export const SUCCESS_TEMPLATE = ` Authorization Successful

Authorization Successful!

You have successfully authorized the application. You can close this window and return to the application.

`; /** * Default error HTML template for OAuth authorization * Supports placeholder replacement: {{error}}, {{error_description}}, {{error_uri}} */ export const ERROR_TEMPLATE = ` Authorization Error

Authorization Failed

{{error}}

The authorization request could not be completed.

{{#if error_description}}
Error Details: {{error_description}}
{{/if}} {{#if error_uri}}

More information about this error

{{/if}} Try Again
`; /** * Render HTML template with parameter substitution */ export function renderTemplate( template: string, params: Record ): string { let rendered = template; // Simple placeholder replacement for (const [key, value] of Object.entries(params)) { const placeholder = `{{${key}}}`; rendered = rendered.replace( new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), value || '' ); } // Handle conditional blocks rendered = rendered.replace( /{{#if (\w+)}}(.*?){{\/if}}/gs, (match, condition, content) => { return params[condition] ? content : ''; } ); return rendered; } /** * Generate success page HTML */ export function renderSuccessPage(customTemplate?: string): string { return customTemplate || SUCCESS_TEMPLATE; } /** * Generate error page HTML with error details */ export function renderErrorPage( error?: string, errorDescription?: string, errorUri?: string, customTemplate?: string ): string { const template = customTemplate || ERROR_TEMPLATE; return renderTemplate(template, { error: error || 'unknown_error', error_description: errorDescription, error_uri: errorUri, }); }