diff --git a/src/index.ts b/src/index.ts index cd8b23b..df5f10b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import type { } from '@remote-ui/rpc' import type { ContextAccessor } from '~types/context/schema' -import type { ExtensionApi } from '~types/endpoint' +import type { WidgetHooks } from '~types/endpoint' import { SchemaMap } from '~types/context' @@ -22,7 +22,7 @@ export { } from './context/store' export const createWidgetEndpoint = >( - api: ExtensionApi, + hooks: WidgetHooks, messenger: MessageEndpoint ): Endpoint> => { const endpoint = createEndpoint>(messenger) @@ -39,16 +39,16 @@ export const createWidgetEndpoint = >( release(methods) } - await api.run(channel, target, methods) + await hooks.run(channel, target, methods) }, release () { - api.release() + hooks.release() onRelease() onRelease = () => {} }, - } as ExtensionApi as unknown as Record) + } as WidgetHooks as unknown as Record) return endpoint } diff --git a/tests/order/card.test.ts b/tests/order/card.test.ts index 9c84f7a..6ce0c37 100644 --- a/tests/order/card.test.ts +++ b/tests/order/card.test.ts @@ -1,7 +1,3 @@ -import type { Channel } from '@omnicajs/vue-remote/host' -import type { ExtensionApi } from '~types/endpoint' -import type { None } from '~types/scaffolding' - import type { ContextAccessor, TypeOf } from '~types/context/schema' import type { Schema } from '~types/context/order/card' @@ -28,7 +24,6 @@ import { } from 'vue' import { createPinia } from 'pinia' -import { createWidgetEndpoint } from '@/index' import { createEndpoint, fromMessagePort, @@ -95,7 +90,7 @@ const createHostContext = () => { } }, - on (context: string, event: string, handler: (payload: unknown) => void) { + on (context, event: string, handler: (payload: unknown) => void) { if (context !== 'order/card') { throw new Error(`[crm:embed:host] Context ${context} is not supported`) } @@ -133,23 +128,25 @@ describe('order/card', () => { const { order, accessor } = createHostContext() - const host = createEndpoint>(fromMessagePort(port1)) + const host = createEndpoint<{ run (): void }>(fromMessagePort(port1)) host.expose(accessor) const pinia = createPinia() - pinia.use(injectAccessor(createWidgetEndpoint({ - async run () { + const remote = createEndpoint>(fromMessagePort(port2)) + + remote.expose({ + run () { const app = createApp({ template: '
' }) app.use(pinia) }, + }) - release () {}, - }, fromMessagePort(port2)))) + pinia.use(injectAccessor(remote)) - await host.call.run(null as unknown as Channel, 'order/card:customer', {}) + await host.call.run() const wrapper = mount({ setup () { diff --git a/types/endpoint.d.ts b/types/endpoint.d.ts index 514a4cc..f0ea884 100644 --- a/types/endpoint.d.ts +++ b/types/endpoint.d.ts @@ -10,7 +10,7 @@ export type Target = | 'order/card:customer.phone' | 'order/card:delivery.address' -export interface ExtensionApi> { +export interface WidgetHooks> { run ( channel: Channel, target: Target,