@odigos/ui-kit 0.0.249 → 0.0.251
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/docs/api-context.md +687 -0
- package/lib/chunks/connections-scope-CneIqjeg.js +1 -0
- package/lib/chunks/flow-CQi_KYfs.js +49 -0
- package/lib/chunks/helpers-K1tnyqhm.js +19 -0
- package/lib/chunks/{index-CRKgHzab.js → index-Dv0RvKAp.js} +8 -8
- package/lib/chunks/source-instrument-form-context-C79I_5cH.js +1 -0
- package/lib/chunks/{ui-components-DODwSdKu.js → ui-components-BKrLf2tx.js} +214 -214
- package/lib/chunks/use-odigos-api-CDHW7ekQ.js +5 -0
- package/lib/chunks/vendor-BFqT13Me.js +1 -0
- package/lib/components/_v2/segment/index.d.ts +4 -2
- package/lib/components/v2.js +1 -1
- package/lib/components.js +1 -1
- package/lib/constants/strings/index.d.ts +7 -0
- package/lib/constants.js +1 -1
- package/lib/containers/_v2/_drawers/add-action-drawer/index.d.ts +0 -2
- package/lib/containers/_v2/_drawers/add-destination-drawer/form-column/index.d.ts +1 -5
- package/lib/containers/_v2/_drawers/add-destination-drawer/index.d.ts +0 -6
- package/lib/containers/_v2/_drawers/add-destination-drawer/lists-filters/index.d.ts +2 -1
- package/lib/containers/_v2/_drawers/add-rule-drawer/index.d.ts +0 -2
- package/lib/containers/_v2/_drawers/add-source-drawer/index.d.ts +1 -4
- package/lib/containers/_v2/_drawers/edit-action-drawer/index.d.ts +0 -3
- package/lib/containers/_v2/_drawers/edit-config-drawer/index.d.ts +1 -3
- package/lib/containers/_v2/_drawers/edit-destination-drawer/index.d.ts +0 -5
- package/lib/containers/_v2/_drawers/edit-rule-drawer/index.d.ts +0 -3
- package/lib/containers/_v2/_drawers/edit-source-drawer/debug/index.d.ts +1 -2
- package/lib/containers/_v2/_drawers/edit-source-drawer/index.d.ts +3 -14
- package/lib/containers/_v2/_drawers/edit-source-drawer/overview/containers-card/index.d.ts +1 -2
- package/lib/containers/_v2/_drawers/edit-source-drawer/overview/index.d.ts +0 -2
- package/lib/containers/_v2/_drawers/edit-source-drawer/peers/index.d.ts +1 -6
- package/lib/containers/_v2/_drawers/edit-source-drawer/profiling/index.d.ts +1 -15
- package/lib/containers/_v2/_drawers/edit-source-drawer/sampling/index.d.ts +8 -0
- package/lib/containers/_v2/_drawers/edit-source-drawer/sampling/rule-row.d.ts +8 -0
- package/lib/containers/_v2/_drawers/edit-source-drawer/tabs.d.ts +1 -0
- package/lib/containers/_v2/_drawers/system-drawer/describe/index.d.ts +1 -8
- package/lib/containers/_v2/_drawers/system-drawer/diagnose/index.d.ts +1 -4
- package/lib/containers/_v2/_drawers/system-drawer/index.d.ts +1 -4
- package/lib/containers/_v2/_drawers/system-drawer/tokens/index.d.ts +1 -2
- package/lib/containers/_v2/_forms/add-destination-form/index.d.ts +1 -2
- package/lib/containers/_v2/_modals/add-data-stream-modal/index.d.ts +0 -3
- package/lib/containers/_v2/_modals/edit-data-stream-modal/index.d.ts +0 -2
- package/lib/containers/_v2/_modals/sampling-onboarding-modal/types.d.ts +1 -4
- package/lib/containers/_v2/central-connections/index.d.ts +1 -12
- package/lib/containers/_v2/onboarding/index.d.ts +0 -8
- package/lib/containers/_v2/overview/columns/column/head.d.ts +1 -1
- package/lib/containers/_v2/overview/columns/column/index.d.ts +2 -1
- package/lib/containers/_v2/overview/columns/index.d.ts +1 -8
- package/lib/containers/_v2/overview/data-stream-select/index.d.ts +1 -10
- package/lib/containers/_v2/overview/drawers/index.d.ts +2 -29
- package/lib/containers/_v2/overview/index.d.ts +2 -8
- package/lib/containers/_v2/overview/multi-source-control/index.d.ts +1 -5
- package/lib/containers/_v2/pipeline-collectors/index.d.ts +0 -7
- package/lib/containers/_v2/pipeline-collectors/pods-info/index.d.ts +1 -2
- package/lib/containers/_v2/pipeline-collectors/pods-info/pod-drawer/index.d.ts +1 -2
- package/lib/containers/_v2/sampling-rules/helpers.d.ts +2 -0
- package/lib/containers/_v2/sampling-rules/types.d.ts +2 -16
- package/lib/containers/_v2/settings/index.d.ts +0 -9
- package/lib/containers/service-map/index.d.ts +4 -2
- package/lib/containers/v2.js +197 -166
- package/lib/containers.js +7 -7
- package/lib/contexts/index.d.ts +1 -0
- package/lib/contexts/odigos-api/capabilities.d.ts +38 -0
- package/lib/contexts/odigos-api/client.d.ts +22 -0
- package/lib/contexts/odigos-api/connections-scope.d.ts +18 -0
- package/lib/contexts/odigos-api/hooks/use-actions-api.d.ts +26 -0
- package/lib/contexts/odigos-api/hooks/use-collectors-api.d.ts +25 -0
- package/lib/contexts/odigos-api/hooks/use-config-api.d.ts +24 -0
- package/lib/contexts/odigos-api/hooks/use-data-streams-api.d.ts +26 -0
- package/lib/contexts/odigos-api/hooks/use-describe-api.d.ts +33 -0
- package/lib/contexts/odigos-api/hooks/use-destinations-api.d.ts +50 -0
- package/lib/contexts/odigos-api/hooks/use-instrumentation-rules-api.d.ts +35 -0
- package/lib/contexts/odigos-api/hooks/use-k8s-manifest-api.d.ts +14 -0
- package/lib/contexts/odigos-api/hooks/use-metrics-api.d.ts +13 -0
- package/lib/contexts/odigos-api/hooks/use-namespace-api.d.ts +30 -0
- package/lib/contexts/odigos-api/hooks/use-profiling-api.d.ts +17 -0
- package/lib/contexts/odigos-api/hooks/use-sampling-api.d.ts +39 -0
- package/lib/contexts/odigos-api/hooks/use-service-map-api.d.ts +13 -0
- package/lib/contexts/odigos-api/hooks/use-snapshots-api.d.ts +13 -0
- package/lib/contexts/odigos-api/hooks/use-sources-api.d.ts +75 -0
- package/lib/contexts/odigos-api/hooks/use-tokens-api.d.ts +12 -0
- package/lib/contexts/odigos-api/index.d.ts +37 -0
- package/lib/contexts/odigos-api/internal/notify.d.ts +49 -0
- package/lib/contexts/odigos-api/internal/source-payloads.d.ts +53 -0
- package/lib/contexts/odigos-api/platform-helpers.d.ts +98 -0
- package/lib/contexts/odigos-api/provider.d.ts +28 -0
- package/lib/contexts/odigos-api/runner.d.ts +32 -0
- package/lib/contexts/odigos-api/types.d.ts +831 -0
- package/lib/contexts/odigos-api/use-api-for-connections.d.ts +43 -0
- package/lib/contexts/odigos-api/use-api-query.d.ts +130 -0
- package/lib/contexts/odigos-api/use-odigos-api.d.ts +103 -0
- package/lib/contexts/odigos-api.js +1 -0
- package/lib/contexts/odigos-context.d.ts +2 -2
- package/lib/contexts/storybook-context.d.ts +2 -2
- package/lib/contexts.js +1 -1
- package/lib/functions.js +1 -1
- package/lib/hooks.js +1 -1
- package/lib/icons/destinations/open-telemetry-logo/index.d.ts +2 -1
- package/lib/snippets/_v2/sampling-rule-form-sections/preset-with-custom-input.d.ts +1 -1
- package/lib/snippets/v2.js +1 -1
- package/lib/snippets.js +1 -49
- package/lib/store/index.d.ts +0 -1
- package/lib/store/useDrawerStore.d.ts +6 -1
- package/lib/store.js +1 -1
- package/lib/theme.js +1 -1
- package/lib/types/actions/index.d.ts +0 -5
- package/lib/types/common/index.d.ts +29 -4
- package/lib/types/destinations/index.d.ts +0 -10
- package/lib/types/index.d.ts +0 -1
- package/lib/types/instrumentation-rules/index.d.ts +0 -5
- package/lib/types/namespaces/index.d.ts +0 -5
- package/lib/types/pipeline-collectors/index.d.ts +0 -5
- package/lib/types/snapshot/index.d.ts +0 -2
- package/lib/types/sources/index.d.ts +0 -30
- package/lib/types/tokens/index.d.ts +0 -6
- package/lib/types/workload/index.d.ts +46 -22
- package/lib/types.js +1 -1
- package/lib/visuals.js +1 -1
- package/package.json +31 -22
- package/lib/chunks/helpers-IEFhGXc7.js +0 -19
- package/lib/chunks/source-instrument-form-context-DjIHPYQJ.js +0 -1
- package/lib/chunks/vendor-Be0cOokr.js +0 -1
- package/lib/mock-data/actions/index.d.ts +0 -2
- package/lib/mock-data/config/index.d.ts +0 -3
- package/lib/mock-data/connections/index.d.ts +0 -2
- package/lib/mock-data/describe/index.d.ts +0 -3
- package/lib/mock-data/destinations/index.d.ts +0 -4
- package/lib/mock-data/index.d.ts +0 -15
- package/lib/mock-data/instrumentation-instances/index.d.ts +0 -2
- package/lib/mock-data/instrumentation-rules/index.d.ts +0 -2
- package/lib/mock-data/namespaces/index.d.ts +0 -2
- package/lib/mock-data/pipeline-collectors/index.d.ts +0 -6
- package/lib/mock-data/profiling/index.d.ts +0 -8
- package/lib/mock-data/service-map/index.d.ts +0 -4
- package/lib/mock-data/snapshot/index.d.ts +0 -5
- package/lib/mock-data/sources/index.d.ts +0 -4
- package/lib/mock-data/sources/yamls.d.ts +0 -22
- package/lib/mock-data/tokens/index.d.ts +0 -2
- package/lib/mock-data/traces/index.d.ts +0 -2
- package/lib/store/useEntityStore.d.ts +0 -24
- package/lib/types/k8s-manifest/index.d.ts +0 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type TokenPayload } from '@/types';
|
|
2
|
+
import type { OperationContext, OdigosApiOperations } from '../types';
|
|
3
|
+
export interface TokensApi {
|
|
4
|
+
fetchTokens?: () => Promise<{
|
|
5
|
+
data?: TokenPayload[];
|
|
6
|
+
error?: string;
|
|
7
|
+
}>;
|
|
8
|
+
updateToken?: (token: string) => Promise<{
|
|
9
|
+
error?: string;
|
|
10
|
+
} | undefined>;
|
|
11
|
+
}
|
|
12
|
+
export declare const useTokensApi: (operations: OdigosApiOperations, ctx: OperationContext) => TokensApi;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point for the OdigosApiContext.
|
|
3
|
+
*
|
|
4
|
+
* This module is exported as `@odigos/ui-kit/contexts/odigos-api` (see the
|
|
5
|
+
* kit's `package.json` exports). Host adapters import the provider, types,
|
|
6
|
+
* and per-domain return types from here. Container code imports
|
|
7
|
+
* `useOdigosApi`.
|
|
8
|
+
*
|
|
9
|
+
* The mock provider (used by storybook only) lives under
|
|
10
|
+
* `.storybook/odigos-api-mock-provider.tsx` so it never compiles into the
|
|
11
|
+
* production bundle.
|
|
12
|
+
*/
|
|
13
|
+
export { OdigosApiProvider } from './provider';
|
|
14
|
+
export { OdigosApiConnectionsScope } from './connections-scope';
|
|
15
|
+
export { useApiForConnections, type ApiForConnections } from './use-api-for-connections';
|
|
16
|
+
export { useOdigosApi, type SubscribableDomain, type UseOdigosApiReturn } from './use-odigos-api';
|
|
17
|
+
export { useApiQuery, useApiLazyQuery, useApiMutation, type UseApiQueryOptions, type UseApiQueryResult, type UseApiLazyQueryResult, type UseApiMutationOptions, type UseApiMutationResult, type UseApiMutationTuple, } from './use-api-query';
|
|
18
|
+
export { pickByPlatform, versionedDocument, vmDialectMap, type VersionedDocumentMap } from './platform-helpers';
|
|
19
|
+
export type { ApolloConfig, CreateActionResult, CreateActionVars, CreateCostReductionRuleResult, CreateDataStreamResult, CreateDataStreamVars, CreateDestinationResult, CreateDestinationVars, CreateHighlyRelevantOperationRuleResult, CreateInstrumentationRuleResult, CreateInstrumentationRuleVars, CreateNoisyOperationRuleResult, DeleteActionResult, DeleteActionVars, DeleteCostReductionRuleResult, DeleteDataStreamResult, DeleteDataStreamVars, DeleteDestinationResult, DeleteDestinationVars, DeleteHighlyRelevantOperationRuleResult, DeleteInstrumentationRuleResult, DeleteInstrumentationRuleVars, DeleteNoisyOperationRuleResult, DescribeOdigosData, DescribeSourceData, DestinationWireInput, DiagnoseResult, DiagnoseVars, GetActionsData, GetAllClusterSnapshotsData, GetClusterSnapshotData, GetClusterSnapshotVars, GetCollectorPodInfoData, GetCollectorPodInfoVars, GetConfigYamlsData, GetDataStreamsData, GetDestinationsData, GetEffectiveConfigVars, GetGatewayInfoData, GetGatewayPodsData, GetInstrumentationRulesData, GetK8sManifestData, GetK8sManifestVars, GetMetricsData, GetNamespaceVars, GetNamespacesWithWorkloadsData, GetNodeCollectorInfoData, GetNodeCollectorPodsData, GetPeerSourcesVars, GetProfilingSlotsData, GetSamplingRulesData, GetServiceMapData, GetSourceConditionsData, GetSourceLibrariesData, GetSourceLibrariesVars, GetSourceProfilingData, GetTokensData, GetWorkloadsByIdsData, GetWorkloadsByIdsVars, GetWorkloadsData, GetWorkloadsVars, MultiFetchGroup, MultiFetchResponse, MultiFetchResult, OdigosApiOperations, OdigosApiProviderProps, Operation, OperationContext, PersistNamespacesResult, PersistNamespacesVars, PersistSourcesResult, PersistSourcesVars, RecoverFromRollbackVars, ResetLocalUiConfigResult, RestartPodVars, RestartWorkloadsVars, SamplingK8sHealthConfigInput, SamplingK8sHealthConfigVars, SamplingRuleCreateVars, SamplingRuleDeleteVars, SamplingRuleUpdateVars, SourceConditionEntry, TestDestinationConnectionVars, UpdateActionResult, UpdateActionVars, UpdateCostReductionRuleResult, UpdateDataStreamResult, UpdateDataStreamVars, UpdateDestinationData, UpdateDestinationVars, UpdateHighlyRelevantOperationRuleResult, UpdateInstrumentationRuleResult, UpdateInstrumentationRuleVars, UpdateLocalUiConfigResult, UpdateLocalUiConfigVars, UpdateLocalUiSamplingConfigResult, UpdateLocalUiSamplingConfigVars, UpdateNoisyOperationRuleResult, UpdateRemoteConfigResult, UpdateRemoteConfigVars, UpdateSourceVars, UpdateTokenResult, UpdateTokenVars, } from './types';
|
|
20
|
+
export type { Capabilities } from './capabilities';
|
|
21
|
+
export type { ConfigApi } from './hooks/use-config-api';
|
|
22
|
+
export type { TokensApi } from './hooks/use-tokens-api';
|
|
23
|
+
export type { ActionsApi } from './hooks/use-actions-api';
|
|
24
|
+
export type { MetricsApi } from './hooks/use-metrics-api';
|
|
25
|
+
export type { DescribeApi } from './hooks/use-describe-api';
|
|
26
|
+
export type { SamplingApi } from './hooks/use-sampling-api';
|
|
27
|
+
export type { NamespaceApi } from './hooks/use-namespace-api';
|
|
28
|
+
export type { ProfilingApi } from './hooks/use-profiling-api';
|
|
29
|
+
export type { SnapshotsApi } from './hooks/use-snapshots-api';
|
|
30
|
+
export type { CollectorsApi } from './hooks/use-collectors-api';
|
|
31
|
+
export type { ServiceMapApi } from './hooks/use-service-map-api';
|
|
32
|
+
export type { DataStreamsApi } from './hooks/use-data-streams-api';
|
|
33
|
+
export type { K8sManifestApi } from './hooks/use-k8s-manifest-api';
|
|
34
|
+
export type { DestinationsApi } from './hooks/use-destinations-api';
|
|
35
|
+
export type { SourcesApi, PersistSourceInput } from './hooks/use-sources-api';
|
|
36
|
+
export type { InstrumentationRulesApi } from './hooks/use-instrumentation-rules-api';
|
|
37
|
+
export { prepareSourcePayloads, prepareNamespacePayloads, type SourceInstrumentInput, type NamespaceInstrumentInput, type SourceInstrumentInputItem, type NamespaceInstrumentInputItem, } from './internal/source-payloads';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared notification helpers used by every domain hook.
|
|
3
|
+
*
|
|
4
|
+
* Each per-domain hook calls `useNotify(entityType)` once at the top to
|
|
5
|
+
* get the same `notifyError` / `notifySuccess` / `notifyPending` /
|
|
6
|
+
* `notifyReadonly` shape, with the SSE-target conversion + crdType
|
|
7
|
+
* pre-wired. This replaces the `notifyError = (title, message, target?) => …`
|
|
8
|
+
* boilerplate that every hook used to repeat.
|
|
9
|
+
*/
|
|
10
|
+
import type { NotifyPayload } from '@/store';
|
|
11
|
+
import { StatusType, type EntityTypes, type WorkloadId } from '@/types';
|
|
12
|
+
type AddNotification = (notif: NotifyPayload) => void;
|
|
13
|
+
export interface DomainNotifier {
|
|
14
|
+
/** Generic dispatcher — used for non-success/error/pending paths. */
|
|
15
|
+
notify: (type: StatusType, title: string, message: string, target?: string | WorkloadId, hideFromHistory?: boolean) => void;
|
|
16
|
+
/** Toast a CRUD error with the entity-typed crdType + optional target. */
|
|
17
|
+
notifyError: (title: string, message: string, target?: string | WorkloadId) => void;
|
|
18
|
+
/** Toast a CRUD success with the entity-typed crdType + optional target. */
|
|
19
|
+
notifySuccess: (title: string, message: string, target?: string | WorkloadId) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Toast a "pending"/in-flight notification (default status, history-hidden).
|
|
22
|
+
* Use sparingly — these are transient and should be cleared by the
|
|
23
|
+
* follow-up success/error toast or by SSE.
|
|
24
|
+
*/
|
|
25
|
+
notifyPending: (message: string, target?: string | WorkloadId) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Dispatch the standardized "operation blocked because the user is
|
|
28
|
+
* read-only" warning. Returns `undefined` so callers can
|
|
29
|
+
* `return notifyReadonly()` inside Promise-returning functions without
|
|
30
|
+
* TypeScript complaining about `void` not matching the declared shape.
|
|
31
|
+
*/
|
|
32
|
+
notifyReadonly: () => undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns a domain-bound notifier. Pass the `EntityTypes` for the domain
|
|
36
|
+
* (e.g. `EntityTypes.Source`) and every dispatched toast is tagged with
|
|
37
|
+
* the correct `crdType` and SSE-target translation.
|
|
38
|
+
*/
|
|
39
|
+
export declare const useNotify: (entityType: EntityTypes) => DomainNotifier;
|
|
40
|
+
/**
|
|
41
|
+
* Standalone form of the readonly notification, used by the small number
|
|
42
|
+
* of hooks that don't need the full `useNotify` surface (e.g. data-streams,
|
|
43
|
+
* which doesn't have a CRD entity type and just dispatches a generic
|
|
44
|
+
* untyped warning).
|
|
45
|
+
*
|
|
46
|
+
* @deprecated New code should prefer `useNotify(...).notifyReadonly()`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const notifyReadonly: (addNotification: AddNotification) => undefined;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source/namespace payload preparation, relocated from the host apps.
|
|
3
|
+
*
|
|
4
|
+
* Originally lived as `prepareSourcePayloads` / `prepareNamespacePayloads`
|
|
5
|
+
* in `odigos/frontend/webapp/utils/functions/sources.ts` and the equivalent
|
|
6
|
+
* file in central-ui. Now centralized in the kit so `useSourcesApi`
|
|
7
|
+
* doesn't depend on host code.
|
|
8
|
+
*
|
|
9
|
+
* The previous version of this helper accepted Zustand-store
|
|
10
|
+
* mutators (`addEntities` / `removeEntities`) so it could optimistically
|
|
11
|
+
* patch the in-memory entity store before the server's mutation
|
|
12
|
+
* resolved. After the kit moved to Apollo's normalized cache as the
|
|
13
|
+
* single source of truth, those optimistic patches are gone — every
|
|
14
|
+
* mutation `await`s `fetchAll()` immediately after, so all
|
|
15
|
+
* `useApiQuery('GET_WORKLOADS')` subscribers see the canonical
|
|
16
|
+
* post-mutation state with sub-second latency. The helper is now a
|
|
17
|
+
* pure (payload, count) builder.
|
|
18
|
+
*/
|
|
19
|
+
import type { NamespaceSelectionFormData, SourceSelectionFormData } from '@/store';
|
|
20
|
+
import type { K8sResourceKind } from '@/types';
|
|
21
|
+
export interface SourceInstrumentInputItem {
|
|
22
|
+
namespace: string;
|
|
23
|
+
name: string;
|
|
24
|
+
kind: K8sResourceKind | '';
|
|
25
|
+
selected: boolean;
|
|
26
|
+
currentStreamName: string;
|
|
27
|
+
}
|
|
28
|
+
export interface NamespaceInstrumentInputItem {
|
|
29
|
+
namespace: string;
|
|
30
|
+
selected: boolean;
|
|
31
|
+
currentStreamName: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SourceInstrumentInput {
|
|
34
|
+
sources: SourceInstrumentInputItem[];
|
|
35
|
+
}
|
|
36
|
+
export interface NamespaceInstrumentInput {
|
|
37
|
+
namespaces: NamespaceInstrumentInputItem[];
|
|
38
|
+
}
|
|
39
|
+
export declare const prepareSourcePayloads: (selectAppsList: SourceSelectionFormData, existingSources: Array<{
|
|
40
|
+
id: {
|
|
41
|
+
namespace: string;
|
|
42
|
+
name: string;
|
|
43
|
+
kind: string;
|
|
44
|
+
};
|
|
45
|
+
dataStreamNames?: string[] | null;
|
|
46
|
+
}>, selectedStreamName: string, handleInstrumentationCount: (toAddCount: number, toDeleteCount: number) => void) => {
|
|
47
|
+
payload: SourceInstrumentInput;
|
|
48
|
+
isEmpty: boolean;
|
|
49
|
+
};
|
|
50
|
+
export declare const prepareNamespacePayloads: (futureSelectAppsList: NamespaceSelectionFormData, selectedStreamName: string) => {
|
|
51
|
+
payload: NamespaceInstrumentInput;
|
|
52
|
+
isEmpty: boolean;
|
|
53
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-routing helpers used by host adapters to express
|
|
3
|
+
* "this operation has a different document/payload per platform".
|
|
4
|
+
*
|
|
5
|
+
* The kit exposes these so adapters can avoid repeating the same
|
|
6
|
+
* platform-switch / version-floor logic at every operation. They live
|
|
7
|
+
* separately from `runner.ts` because they don't touch Apollo — they're
|
|
8
|
+
* pure ergonomic helpers over `OperationContext`.
|
|
9
|
+
*/
|
|
10
|
+
import type { DocumentNode } from 'graphql';
|
|
11
|
+
import { PlatformType } from '@/types';
|
|
12
|
+
import type { OperationContext } from './types';
|
|
13
|
+
/**
|
|
14
|
+
* Pick a value based on the active platform.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const doc = pickByPlatform(ctx, {
|
|
19
|
+
* K8s: K8S_GET_WORKLOADS,
|
|
20
|
+
* Vm: VM_GET_SOURCES,
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Returns `undefined` if the active platform doesn't have a branch — the
|
|
25
|
+
* runner will then short-circuit with "Operation not supported in this
|
|
26
|
+
* context", which is the correct UX (capabilities flags hide the calling
|
|
27
|
+
* affordance, but a defensive short-circuit prevents stale UI from
|
|
28
|
+
* sending an op that doesn't exist on the current platform).
|
|
29
|
+
*/
|
|
30
|
+
export declare const pickByPlatform: <T>(ctx: OperationContext, branches: {
|
|
31
|
+
K8s?: T;
|
|
32
|
+
Vm?: T;
|
|
33
|
+
}) => T | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Per-platform, per-version map of `DocumentNode`s. Top-level keys are
|
|
36
|
+
* `PlatformType` values; second-level keys are version strings (as
|
|
37
|
+
* declared by the host's release schedule — e.g. `'v1.20'`,
|
|
38
|
+
* `'v0.6.0'`). Values are pre-built `DocumentNode`s.
|
|
39
|
+
*
|
|
40
|
+
* Designed to be assignable from the agents-api `dialects` registry's
|
|
41
|
+
* `print(dialect.docName)` outputs once the host wraps them with `gql`,
|
|
42
|
+
* and from hand-authored `gql` consts on the K8s side.
|
|
43
|
+
*/
|
|
44
|
+
export type VersionedDocumentMap = {
|
|
45
|
+
readonly [P in PlatformType]?: Readonly<Record<string, DocumentNode>>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Build a `(ctx) => DocumentNode | undefined` resolver for
|
|
49
|
+
* `Operation.document` from a `VersionedDocumentMap`.
|
|
50
|
+
*
|
|
51
|
+
* Resolution algorithm — same as central-ui's `getVersionedQuery`:
|
|
52
|
+
* 1. Pick the platform branch matching `ctx.platformType`.
|
|
53
|
+
* 2. Sort that branch's versions descending (numeric-aware via
|
|
54
|
+
* `trimVersion`).
|
|
55
|
+
* 3. Return the highest version that's `<= ctx.version`. This "floor
|
|
56
|
+
* to the matching bucket" rule keeps older proxies/agents from
|
|
57
|
+
* receiving documents whose schemas they don't understand yet.
|
|
58
|
+
* 4. If no bucket fits (or the platform is missing), return undefined
|
|
59
|
+
* → the runner short-circuits with "Operation not supported in
|
|
60
|
+
* this context".
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const operations: OdigosApiOperations = {
|
|
65
|
+
* GET_WORKLOADS: {
|
|
66
|
+
* document: versionedDocument({
|
|
67
|
+
* [PlatformType.K8s]: { 'v1.16': K8S_GET_WORKLOADS_V1_16 },
|
|
68
|
+
* [PlatformType.Vm]: vmDialectMap((d) => d.getSourcesV2),
|
|
69
|
+
* }),
|
|
70
|
+
* transformResult: (raw, ctx) => …,
|
|
71
|
+
* },
|
|
72
|
+
* …
|
|
73
|
+
* };
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare const versionedDocument: (map: VersionedDocumentMap) => (ctx: OperationContext) => DocumentNode | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Convenience builder for the VM half of a `VersionedDocumentMap` from a
|
|
79
|
+
* dialect-style registry (e.g. `@odigos/vmagent-api-apollo-client/registry`'s
|
|
80
|
+
* `dialects` export).
|
|
81
|
+
*
|
|
82
|
+
* Hosts pass:
|
|
83
|
+
* - `dialects` — the registry value (`Record<DialectVersion, Dialect>`).
|
|
84
|
+
* - `select` — pick a specific `DocumentNode` out of each dialect.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { dialects } from '@odigos/vmagent-api-apollo-client/registry';
|
|
89
|
+
*
|
|
90
|
+
* const VM_GET_SOURCES = vmDialectMap(dialects, (d) => d.getSourcesV2);
|
|
91
|
+
* // => Record<'v0.6.0' | 'v0.8.0' | …, DocumentNode>
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* Generic `<TRegistry, TDialect>` is permissive on purpose — the kit
|
|
95
|
+
* never imports the `vmagent-api-apollo-client` package itself; this
|
|
96
|
+
* helper just maps over whatever the host hands in.
|
|
97
|
+
*/
|
|
98
|
+
export declare const vmDialectMap: <TRegistry extends Record<string, TDialect>, TDialect>(dialects: TRegistry, select: (dialect: TDialect) => DocumentNode) => Record<keyof TRegistry & string, DocumentNode>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<OdigosApiProvider>` — the public entry point for the kit's API context.
|
|
3
|
+
*
|
|
4
|
+
* Hosts mount this once at the layout level. It:
|
|
5
|
+
* 1. Constructs the ApolloClient from `apolloConfig` (memoized on the
|
|
6
|
+
* `httpUrl` so the client is recreated only when the endpoint changes).
|
|
7
|
+
* 2. Mounts Apollo's `<ApolloProvider>`.
|
|
8
|
+
* 3. Exposes `operations` + `context` to per-domain hooks via an internal
|
|
9
|
+
* React context.
|
|
10
|
+
* 4. Reads via `useOdigosApi()` (see `use-odigos-api.ts`) which composes
|
|
11
|
+
* every per-domain hook into a single namespaced object.
|
|
12
|
+
*
|
|
13
|
+
* Hosts that need Next.js SSR support wrap this with their own
|
|
14
|
+
* `<ApolloNextAppProvider>` externally — see [odigos-api-adapter.tsx]
|
|
15
|
+
* in odigos webapp for the canonical pattern.
|
|
16
|
+
*/
|
|
17
|
+
import React, { type FC } from 'react';
|
|
18
|
+
import type { OdigosApiInternalValue, OdigosApiProviderProps } from './types';
|
|
19
|
+
/** @internal — used by per-domain hooks via the `hooks/` folder. */
|
|
20
|
+
export declare const useOdigosApiInternal: () => OdigosApiInternalValue;
|
|
21
|
+
export declare const OdigosApiProvider: FC<OdigosApiProviderProps>;
|
|
22
|
+
/**
|
|
23
|
+
* Internal context used by the mock provider so storybook stories can
|
|
24
|
+
* supply a partial API surface without constructing Apollo at all.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare const __OdigosApiInternalContext: React.Context<OdigosApiInternalValue | null>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes Operations against the host's ApolloClient.
|
|
3
|
+
*
|
|
4
|
+
* Each domain hook ultimately calls one of `runQuery`, `runMutation`, or
|
|
5
|
+
* `runMulti`. The runner resolves the document (which may be a function of
|
|
6
|
+
* `OperationContext` for versioned-query maps), applies optional variable +
|
|
7
|
+
* result transformations, and surfaces a uniform `{ data, error }` shape.
|
|
8
|
+
*/
|
|
9
|
+
import type { ApolloClient, FetchPolicy } from '@apollo/client';
|
|
10
|
+
import type { MultiFetchResponse, Operation, OperationContext } from './types';
|
|
11
|
+
export interface RunResult<T> {
|
|
12
|
+
data?: T;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Execute a single query. Tolerates `op === undefined` (returned as a
|
|
17
|
+
* graceful "not configured" error) so domain hooks calling `runQuery(client,
|
|
18
|
+
* operations.X, …)` against a host adapter that omits slot `X` — including
|
|
19
|
+
* the Storybook mock provider's empty operations map — don't crash with
|
|
20
|
+
* `Cannot read properties of undefined`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const runQuery: <T, V>(defaultClient: ApolloClient<unknown>, op: Operation<T, V> | undefined, vars: V | undefined, ctx: OperationContext, fetchPolicy?: FetchPolicy) => Promise<RunResult<T>>;
|
|
23
|
+
/** Execute a single mutation. Same `op === undefined` tolerance as `runQuery`. */
|
|
24
|
+
export declare const runMutation: <T, V>(defaultClient: ApolloClient<unknown>, op: Operation<T, V> | undefined, vars: V | undefined, ctx: OperationContext) => Promise<RunResult<T>>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute a multi-cluster fan-out. When `op.documentMulti` /
|
|
27
|
+
* `transformVariablesMulti` are set (central-ui), groups proxies by
|
|
28
|
+
* resolved version and emits one Apollo call per group, then merges
|
|
29
|
+
* results. When they're absent (odigos webapp), falls back to N parallel
|
|
30
|
+
* single calls.
|
|
31
|
+
*/
|
|
32
|
+
export declare const runMulti: <T, V>(defaultClient: ApolloClient<unknown>, op: Operation<T, V> | undefined, proxyIDs: string[], vars: V | undefined, ctx: OperationContext) => Promise<MultiFetchResponse<T>>;
|