From fe6537f66cf709b1df76470c8bd8f14b585a08a9 Mon Sep 17 00:00:00 2001 From: Zoltan Hricz Date: Fri, 27 Feb 2026 21:01:28 +0100 Subject: [PATCH 1/3] fix: correct type export and register custom element in the DOM --- demo/demo.ts | 11 +++++------ package.json | 2 +- src/types/api.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/demo/demo.ts b/demo/demo.ts index a306b8a..b72ec12 100644 --- a/demo/demo.ts +++ b/demo/demo.ts @@ -1,22 +1,21 @@ import type { AuthCredentials, ConfigureAppPayload, - CortiEmbeddedAPI, Fact, InteractionDetails, CreateInteractionPayload, SessionConfig, GetStatusResponse, -} from '../src/types'; +} from '../dist'; interface CortiEmbeddedEventDetail { name: string; payload: unknown; } -// Get the component with proper typing -const component = document.getElementById('corti-component') as HTMLElement & - CortiEmbeddedAPI; +// Get the component with proper typing — querySelector('corti-embedded') is +// automatically typed as CortiEmbeddedElement via HTMLElementTagNameMap +const component = document.querySelector('corti-embedded') // Define log entry types type LogType = 'info' | 'success' | 'error' | 'warning'; @@ -508,7 +507,7 @@ customElements.whenDefined('corti-embedded').then(() => { updateStatus(); addLogEntry('Corti component loaded and ready', 'success'); - component.addEventListener('embedded-event', (event: Event) => { + component?.addEventListener('embedded-event', (event: Event) => { const { detail } = event as CustomEvent; addLogEntry( `[EMBEDDED-EVENT] - ${detail.name}: ${JSON.stringify(detail.payload)}`, diff --git a/package.json b/package.json index 332e68a..d21a273 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "module": "dist/web-bundle.js", "exports": { ".": { - "types": "./dist/web-bundle.d.ts", + "types": "./dist/web-index.d.ts", "import": "./dist/web-bundle.js", "browser": "./dist/web-bundle.js", "default": "./dist/web-bundle.js" diff --git a/src/types/api.ts b/src/types/api.ts index 4b9eedf..3d8d2f5 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -100,11 +100,20 @@ export interface CortiEmbeddedWindowAPI { v1: CortiEmbeddedV1API; } +/** + * Type representing the corti-embedded custom element in the DOM. + * Automatically available via querySelector/getElementById when this package is installed. + */ +export type CortiEmbeddedElement = HTMLElement & CortiEmbeddedAPI; + // Extend Window interface declare global { interface Window { CortiEmbedded?: CortiEmbeddedWindowAPI; } + interface HTMLElementTagNameMap { + 'corti-embedded': CortiEmbeddedElement; + } } /** From f2a4b8ce660be152c838c039d44135ce00580b02 Mon Sep 17 00:00:00 2001 From: Zoltan Hricz Date: Mon, 2 Mar 2026 12:22:24 +0100 Subject: [PATCH 2/3] Update src/types/api.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/types/api.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/types/api.ts b/src/types/api.ts index 3d8d2f5..5d34841 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -102,7 +102,10 @@ export interface CortiEmbeddedWindowAPI { /** * Type representing the corti-embedded custom element in the DOM. - * Automatically available via querySelector/getElementById when this package is installed. + * When this package is installed, tag-name based APIs like + * document.querySelector('corti-embedded') and document.createElement('corti-embedded') + * are automatically typed via HTMLElementTagNameMap. Other lookups such as getElementById + * still return HTMLElement | null and require a cast or narrowing to CortiEmbeddedElement. */ export type CortiEmbeddedElement = HTMLElement & CortiEmbeddedAPI; From f9ef8dc7d7a0824f13ec35a8dc633f6e398bccc6 Mon Sep 17 00:00:00 2001 From: Zoltan Hricz Date: Tue, 10 Mar 2026 12:57:34 +0100 Subject: [PATCH 3/3] refactor: eslint warning correction --- src/types/api.ts | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/types/api.ts b/src/types/api.ts index 3997e5b..51b6c8a 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -94,25 +94,6 @@ export interface CortiEmbeddedWindowAPI { v1: CortiEmbeddedV1API; } -/** - * Type representing the corti-embedded custom element in the DOM. - * When this package is installed, tag-name based APIs like - * document.querySelector('corti-embedded') and document.createElement('corti-embedded') - * are automatically typed via HTMLElementTagNameMap. Other lookups such as getElementById - * still return HTMLElement | null and require a cast or narrowing to CortiEmbeddedElement. - */ -export type CortiEmbeddedElement = HTMLElement & CortiEmbeddedAPI; - -// Extend Window interface -declare global { - interface Window { - CortiEmbedded?: CortiEmbeddedWindowAPI; - } - interface HTMLElementTagNameMap { - 'corti-embedded': CortiEmbeddedElement; - } -} - /** * Event listener function type */ @@ -207,3 +188,22 @@ export interface CortiEmbeddedAPI { */ hide(): void; } + +/** + * Type representing the corti-embedded custom element in the DOM. + * When this package is installed, tag-name based APIs like + * document.querySelector('corti-embedded') and document.createElement('corti-embedded') + * are automatically typed via HTMLElementTagNameMap. Other lookups such as getElementById + * still return HTMLElement | null and require a cast or narrowing to CortiEmbeddedElement. + */ +export type CortiEmbeddedElement = HTMLElement & CortiEmbeddedAPI; + +// Extend Window interface +declare global { + interface Window { + CortiEmbedded?: CortiEmbeddedWindowAPI; + } + interface HTMLElementTagNameMap { + 'corti-embedded': CortiEmbeddedElement; + } +}