Stone.js API
    Preparing search index...

    Browser Adapter for Stone.js.

    The BrowserAdapter provides seamless integration between Stone.js applications and the Browser environment. It processes incoming events from Browser, transforms them into IncomingBrowserEvent instances, and returns a BrowserResponse.

    This adapter ensures compatibility with Browser's execution model and abstracts the event handling process for Stone.js developers.

    The type of the raw event received from Browser.

    The type of the response to send back to Browser.

    The Browser execution context type.

    The type of the processed incoming event.

    Options used to create an incoming event.

    The type of the outgoing response after processing.

    Context type specific to the adapter.

    import { BrowserAdapter } from '@stone-js/browser-adapter';

    const adapter = BrowserAdapter.create({...});

    await adapter.run();

    Hierarchy

    Index
    • Create an Adapter.

      Parameters

      • blueprint: IBlueprint

        The blueprint to create the adapter.

      Returns BrowserAdapter

    blueprint: IBlueprint
    hooks: AdapterHookType<BrowserAdapterContext, unknown>
    middleware: AdapterMixedPipeType<BrowserAdapterContext, unknown>[]
    resolvedErrorHandlers: Record<
        string,
        IAdapterErrorHandler<RawEventType, RawResponseType, ExecutionContextType>,
    >
    • Build the raw response.

      Parameters

      • context: BrowserAdapterContext

        The event context.

      • OptionaleventHandler: AdapterEventHandlerType<IncomingBrowserEvent, OutgoingBrowserResponse>

        The event handler to be run.

      Returns Promise<unknown>

      The raw response wrapper.

    • Processes an incoming Browser event.

      This method transforms the raw Browser event into a Stone.js IncomingBrowserEvent, processes it through the pipeline, and generates a RawResponse to send back.

      Parameters

      • eventHandler: AdapterEventHandlerType<IncomingBrowserEvent, OutgoingBrowserResponse>
      • rawEvent: BrowserEvent

        The raw Browser event to be processed.

      • executionContext: Window & typeof globalThis

        The Browser execution context for the event.

      Returns Promise<unknown>

      A promise resolving to the processed RawResponse.

    • Execute the event handler lifecycle hooks.

      Parameters

      • hook: KernelHookName

        The hook to execute.

      • eventHandler: AdapterEventHandlerType<IncomingBrowserEvent, OutgoingBrowserResponse>

        The event handler to be run.

      Returns Promise<void>

    • Execute adapter lifecycle hooks.

      Parameters

      • name: AdapterHookName

        The hook's name.

      • Optionalcontext: BrowserAdapterContext

        The event context.

      • Optionalerror: any

        The error to handle.

      Returns Promise<void>

    • Handle error.

      Parameters

      Returns Promise<AdapterEventBuilderType<unknown>>

      The raw response.

    • Handle the event.

      Parameters

      • context: BrowserAdapterContext

        The event context.

      • eventHandler: AdapterEventHandlerType<IncomingBrowserEvent, OutgoingBrowserResponse>

        The event handler to be run.

      Returns Promise<IAdapterEventBuilder<RawResponseOptions, IRawResponseWrapper<unknown>>>

      The raw response wrapper.

    • Create pipeline options for the Adapter.

      Returns PipelineOptions<BrowserAdapterContext, AdapterEventBuilderType<unknown>>

      The pipeline options for transforming the event.

    • Initializes the adapter and validates its execution context.

      Ensures the adapter is running in a Browser environment. If not, it throws an error to prevent misuse.

      Returns Promise<void>

      If executed outside a Browser context (e.g., node).

    • Get the error handler for the given error.

      Parameters

      • error: Error

        The error to get the handler for.

      Returns IAdapterErrorHandler<BrowserEvent, unknown, Window & typeof globalThis>

      The error handler.

      IntegrationError

    • Get the event handler for the adapter.

      Returns AdapterEventHandlerType<IncomingBrowserEvent, OutgoingBrowserResponse>

      The event handler for the adapter.

      If the event handler is missing.

    • Executes the adapter and provides an Browser-compatible handler function.

      The run method initializes the adapter and listens for incoming Browser events. It processes these events, generates a response, and sends it back to the Browser.

      Idempotent: calling run() again tears down the previous listeners first, so HMR reloads and tests never accumulate duplicate handlers.

      Type Parameters

      • ExecutionResultType = undefined

      Returns Promise<ExecutionResultType>

      If used outside the Browser environment.

    • Send the raw event through the destination.

      Parameters

      • context: BrowserAdapterContext

        The event context.

      • eventHandler: AdapterEventHandlerType<IncomingBrowserEvent, OutgoingBrowserResponse>

        The event handler to be run.

      Returns Promise<unknown>

      Platform-specific response.

      IntegrationError

    • Tear down the adapter: remove all registered window listeners and run onStop hooks.

      Safe to call multiple times and when the adapter was never started.

      Returns Promise<void>

    • Validate the context and event handler.

      Parameters

      • context: BrowserAdapterContext

        The context to validate.

      • eventHandler: AdapterEventHandlerType<IncomingBrowserEvent, OutgoingBrowserResponse>

        The event handler to validate.

      Returns void

      IntegrationError