diff --git a/index.d.ts b/index.d.ts index b91da40..cc82789 100644 --- a/index.d.ts +++ b/index.d.ts @@ -15,7 +15,7 @@ type WidgetCallback = () => Promise interface MCEvent { readonly name?: string - readonly payload: unknown + readonly payload: Record client: Client readonly type: string } @@ -54,15 +54,15 @@ interface Manager { type: ClientEventType, callback: MCEventListener ): boolean | undefined - get(key: string): Promise - set(key: string, value: any): Promise + get(key: string): Promise + set(key: string, value: string): Promise route( path: string, callback: (request: Request | any) => Promise | Response ): string | undefined proxy(path: string, target: string): string | undefined serve(path: string, target: string): string | undefined - useCache(key: string, callback: Function, expiry?: number): Promise + useCache(key: string, callback: Function, expiry?: number): Promise invalidateCache(key: string): Promise registerEmbed(name: string, callback: EmbedCallback): boolean | undefined registerWidget(callback: WidgetCallback): boolean | undefined diff --git a/tests/demoComponent.ts b/tests/demoComponent.ts index 5be8206..6043a7f 100644 --- a/tests/demoComponent.ts +++ b/tests/demoComponent.ts @@ -33,6 +33,9 @@ export default async function (manager: Manager, settings: ComponentSettings) { // Save mouse coordinates as a cookie const { client, payload } = event console.info('🐁 ⬇️ Mousedown payload:', payload) + if (!Array.isArray(payload.mousedown)) { + throw new Error('expected mousedown to be an array') + } const [firstClick] = payload.mousedown client.set('lastClickX', firstClick.clientX) client.set('lastClickY', firstClick.clientY) @@ -85,7 +88,9 @@ export default async function (manager: Manager, settings: ComponentSettings) { payload.user_id = client.get('user_id') if (Object.keys(payload || {}).length) { - const params = new URLSearchParams(payload).toString() + const params = new URLSearchParams( + payload as Record + ).toString() fetch(`http://www.example.com/?${params}`) } }) @@ -129,6 +134,9 @@ export default async function (manager: Manager, settings: ComponentSettings) { console.error('error fetching weather for embed:', error) } }) + if (typeof embed !== 'string') { + throw new Error('Unexpected embed return type: ' + typeof embed) + } return embed } )