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

Function createPluginAtomClient

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

Source from the content-addressed store, hash-verified

360 * React tree without colliding.
361 */
362export const createPluginAtomClient = <
363 G extends HttpApiGroup.HttpApiGroup<string, HttpApiEndpoint.Any, boolean>,
364>(
365 group: G,
366 options: CreatePluginAtomClientOptions = {},
367) => {
368 const { baseUrl = "/api", authorizationHeader, headers } = options;
369 const pluginId = group.identifier;
370 const bundle = HttpApi.make(`plugin-${pluginId}`).add(group);
371 const getBaseUrl = typeof baseUrl === "function" ? baseUrl : null;
372 const staticBaseUrl = typeof baseUrl === "function" ? undefined : baseUrl;
373 const getAuthorizationHeader =
374 typeof authorizationHeader === "function" ? authorizationHeader : null;
375 const hasAuthorization = authorizationHeader !== undefined && authorizationHeader !== null;
376 const hasHeaders = headers !== undefined;
377 const transformClient =
378 getBaseUrl || hasAuthorization || hasHeaders
379 ? HttpClient.mapRequest((request) =>
380 applyPluginAtomClientRequestTransform(request, {
381 ...(getBaseUrl ? { baseUrl: getBaseUrl } : {}),
382 ...(getAuthorizationHeader
383 ? { authorizationHeader: getAuthorizationHeader }
384 : authorizationHeader !== undefined
385 ? { authorizationHeader }
386 : {}),
387 ...(headers !== undefined ? { headers } : {}),
388 }),
389 )
390 : undefined;
391
392 return AtomHttpApi.Service<`Plugin_${G["identifier"]}Client`>()(`Plugin_${pluginId}Client`, {
393 api: bundle,
394 httpClient: FetchHttpClient.layer,
395 ...(staticBaseUrl !== undefined ? { baseUrl: staticBaseUrl } : {}),
396 ...(transformClient ? { transformClient } : {}),
397 });
398};
399
400// ---------------------------------------------------------------------------
401// 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