MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / createPluginAtomClient

Function createPluginAtomClient

packages/core/sdk/src/client.ts:347–383  ·  view source on GitHub ↗
(
  group: G,
  options: CreatePluginAtomClientOptions = {},
)

Source from the content-addressed store, hash-verified

345 * React tree without colliding.
346 */
347export const createPluginAtomClient = <
348 G extends HttpApiGroup.HttpApiGroup<string, HttpApiEndpoint.Any, boolean>,
349>(
350 group: G,
351 options: CreatePluginAtomClientOptions = {},
352) => {
353 const { baseUrl = "/api", authorizationHeader, headers } = options;
354 const pluginId = group.identifier;
355 const bundle = HttpApi.make(`plugin-${pluginId}`).add(group);
356 const getBaseUrl = typeof baseUrl === "function" ? baseUrl : null;
357 const staticBaseUrl = typeof baseUrl === "function" ? undefined : baseUrl;
358 const getAuthorizationHeader =
359 typeof authorizationHeader === "function" ? authorizationHeader : null;
360 const hasAuthorization = authorizationHeader !== undefined && authorizationHeader !== null;
361 const hasHeaders = headers !== undefined;
362 const transformClient =
363 getBaseUrl || hasAuthorization || hasHeaders
364 ? HttpClient.mapRequest((request) =>
365 applyPluginAtomClientRequestTransform(request, {
366 ...(getBaseUrl ? { baseUrl: getBaseUrl } : {}),
367 ...(getAuthorizationHeader
368 ? { authorizationHeader: getAuthorizationHeader }
369 : authorizationHeader !== undefined
370 ? { authorizationHeader }
371 : {}),
372 ...(headers !== undefined ? { headers } : {}),
373 }),
374 )
375 : undefined;
376
377 return AtomHttpApi.Service<`Plugin_${G["identifier"]}Client`>()(`Plugin_${pluginId}Client`, {
378 api: bundle,
379 httpClient: FetchHttpClient.layer,
380 ...(staticBaseUrl !== undefined ? { baseUrl: staticBaseUrl } : {}),
381 ...(transformClient ? { transformClient } : {}),
382 });
383};
384
385// ---------------------------------------------------------------------------
386// ExecutorPluginsProvider + hooks — host-level distribution of the loaded

Callers 7

client.test.tsFile · 0.90
client.tsxFile · 0.90
page.tsxFile · 0.90
client.tsFile · 0.90
client.tsFile · 0.90
client.tsFile · 0.90
client.tsFile · 0.90

Tested by

no test coverage detected