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

Function createPluginAtomClient

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

Source from the content-addressed store, hash-verified

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