(
group: G,
options: CreatePluginAtomClientOptions = {},
)
| 420 | * React tree without colliding. |
| 421 | */ |
| 422 | export const createPluginAtomClient = < |
| 423 | G extends HttpApiGroup.HttpApiGroup<string, HttpApiEndpoint.Any, boolean>, |
| 424 | >( |
| 425 | group: G, |
| 426 | options: CreatePluginAtomClientOptions = {}, |
| 427 | ) => { |
| 428 | const { baseUrl = "/api", authorizationHeader, headers } = options; |
| 429 | const pluginId = group.identifier; |
| 430 | const bundle = HttpApi.make(`plugin-${pluginId}`).add(group); |
| 431 | const getBaseUrl = typeof baseUrl === "function" ? baseUrl : null; |
| 432 | const staticBaseUrl = typeof baseUrl === "function" ? undefined : baseUrl; |
| 433 | const getAuthorizationHeader = |
| 434 | typeof authorizationHeader === "function" ? authorizationHeader : null; |
| 435 | const hasAuthorization = authorizationHeader !== undefined && authorizationHeader !== null; |
| 436 | const hasHeaders = headers !== undefined; |
| 437 | const transformClient = |
| 438 | getBaseUrl || hasAuthorization || hasHeaders |
| 439 | ? HttpClient.mapRequest((request) => |
| 440 | applyPluginAtomClientRequestTransform(request, { |
| 441 | ...(getBaseUrl ? { baseUrl: getBaseUrl } : {}), |
| 442 | ...(getAuthorizationHeader |
| 443 | ? { authorizationHeader: getAuthorizationHeader } |
| 444 | : authorizationHeader !== undefined |
| 445 | ? { authorizationHeader } |
| 446 | : {}), |
| 447 | ...(headers !== undefined ? { headers } : {}), |
| 448 | }), |
| 449 | ) |
| 450 | : undefined; |
| 451 | |
| 452 | return AtomHttpApi.Service<`Plugin_${G["identifier"]}Client`>()(`Plugin_${pluginId}Client`, { |
| 453 | api: bundle, |
| 454 | httpClient: FetchHttpClient.layer, |
| 455 | ...(staticBaseUrl !== undefined ? { baseUrl: staticBaseUrl } : {}), |
| 456 | ...(transformClient ? { transformClient } : {}), |
| 457 | }); |
| 458 | }; |
| 459 | |
| 460 | // --------------------------------------------------------------------------- |
| 461 | // ExecutorPluginsProvider + hooks — host-level distribution of the loaded |
no test coverage detected