Client
Use @bnomei/emdash-mika/client only when browser code or a framework island needs public plugin JSON reads.
The package export ./client is built from src/api/client.ts. It is
browser-safe because it only calls public plugin routes.
Important exports include:
createMikaClient();MikaClient;MikaClientOptions;MikaClientRouteName;MikaClientRouteOptions;CatalogSellablesOptions.
The client exposes:
client.catalog.sellables(collection, id, { locale });client.stock.availability(sellableId);client.routes(routeName, options).
It intentionally does not expose cart, checkout, account, subscription, webhook, admin, or agent-tool mutation namespaces. Use Astro Actions or host-owned protected endpoints for those flows.
Options
Section titled “Options”createMikaClient() accepts:
| Option | Role |
|---|---|
apiBase |
Overrides the EmDash plugin API base. Default is /_emdash/api/plugins. |
pluginId |
Overrides the plugin id. Default is mika. |
baseUrl |
Makes route URLs absolute against an origin. |
fetch |
Injects a fetch implementation for tests or custom runtimes. |
request |
Lets server-side callers derive origin and same-origin cookies from an incoming request. |
headers |
Adds default request headers. |
The browser client uses accept: application/json and returns normalized
MikaApiResult envelopes. Failed network requests return status: 0 with
PROVIDER_FAILED. Malformed JSON envelopes become typed failure results rather
than throwing.
Route Builder
Section titled “Route Builder”client.routes(routeName, options) resolves named public route keys to EmDash
plugin API URLs. Browser code can only pass the public route names:
| Name | Path |
|---|---|
catalogSellables |
/_emdash/api/plugins/mika/catalog/sellables |
sellableAvailability |
/_emdash/api/plugins/mika/sellables/availability |
Search parameters are added by the client:
catalog.sellables()sendscollection,id, and optionallocale;stock.availability()sendssellableId.
Cookie Forwarding
Section titled “Cookie Forwarding”The low-level request helper can forward cookies from options.request when the
target URL is same-origin. The public browser client does not need cookies for
catalog and stock reads. The server client adds the trusted option for
cross-origin cookie forwarding; use that only in backend code.
Source Anchors
Section titled “Source Anchors”- ⓟ
../emdash-mika/package.json - ⓟ
../emdash-mika/src/api/client.ts - ⓟ
../emdash-mika/src/api/request.ts - ⓟ
../emdash-mika/src/api/routes.ts - ⓟ
../emdash-mika/src/api/server-client.ts