@infrascan/shared-types 0.3.0 → 0.4.0
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 +6 -0
- package/package.json +1 -1
- package/src/api.ts +3 -14
- package/src/graph.ts +8 -57
- package/src/index.ts +1 -0
- package/src/plugins.ts +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @infrascan/shared-types
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#77](https://github.com/infrascan/infrascan/pull/77) [`21d4ecf`](https://github.com/infrascan/infrascan/commit/21d4ecf4b7fec31f4ac7b2cc5857aa5d2b725075) Thanks [@lfarrel6](https://github.com/lfarrel6)! - Add in-memory graph model to decouple the infrascan packages from a single graphing library, and to make graph manipulation easier
|
|
8
|
+
|
|
3
9
|
## 0.3.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AwsCredentialIdentityProvider, RetryStrategy, RetryStrategyV2 } from "@aws-sdk/types";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { SelectedEdge, SelectedNode } from "./graph";
|
|
4
4
|
import type { BaseEdgeResolver } from "./config";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -85,9 +85,9 @@ type GetterFn<T, P extends Provider> = (
|
|
|
85
85
|
type GetNodeFn<T extends Provider> = (
|
|
86
86
|
stateConnector: Connector,
|
|
87
87
|
context: ProviderContextMap[T],
|
|
88
|
-
) => Promise<
|
|
88
|
+
) => Promise<SelectedNode[]>;
|
|
89
89
|
|
|
90
|
-
type GetEdgeFn = (stateConnector: Connector) => Promise<
|
|
90
|
+
type GetEdgeFn = (stateConnector: Connector) => Promise<SelectedEdge[]>;
|
|
91
91
|
|
|
92
92
|
export type Provider = "aws";
|
|
93
93
|
|
|
@@ -106,15 +106,6 @@ export type ProviderContext<T extends Provider> = {
|
|
|
106
106
|
context: ProviderContextMap[T];
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
type FormatNodeFn<P extends Provider> = (
|
|
110
|
-
node: GraphNode,
|
|
111
|
-
context: ProviderContextMap[P],
|
|
112
|
-
) => GraphNode;
|
|
113
|
-
type FormatEdgeFn<P extends Provider> = (
|
|
114
|
-
node: GraphEdge,
|
|
115
|
-
context: ProviderContextMap[P],
|
|
116
|
-
) => GraphEdge;
|
|
117
|
-
|
|
118
109
|
export type EntityRoleData = {
|
|
119
110
|
roleArn: string;
|
|
120
111
|
executor: string;
|
|
@@ -131,9 +122,7 @@ export interface ServiceModule<T, P extends Provider> {
|
|
|
131
122
|
getters: GetterFn<T, P>[];
|
|
132
123
|
nodes?: string[];
|
|
133
124
|
getNodes?: GetNodeFn<P>;
|
|
134
|
-
formatNode?: FormatNodeFn<P>;
|
|
135
125
|
edges?: BaseEdgeResolver[];
|
|
136
126
|
getEdges?: GetEdgeFn;
|
|
137
|
-
formatEdge?: FormatEdgeFn<P>;
|
|
138
127
|
getIamRoles?: GetIamRoleFn;
|
|
139
128
|
}
|
package/src/graph.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A node returned from a state selector before its been formatted for a graphing library
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export interface SelectedNode {
|
|
5
5
|
id: string;
|
|
6
6
|
name?: string;
|
|
7
7
|
parent?: string;
|
|
@@ -9,64 +9,15 @@ export type SelectedNode = {
|
|
|
9
9
|
rawState?: any;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
group: "nodes";
|
|
17
|
-
id: string;
|
|
18
|
-
data: {
|
|
19
|
-
id: string;
|
|
20
|
-
type: string;
|
|
21
|
-
/**
|
|
22
|
-
* Parent node (account, region etc)
|
|
23
|
-
*/
|
|
24
|
-
parent?: string;
|
|
25
|
-
name?: string;
|
|
26
|
-
service?: string;
|
|
27
|
-
};
|
|
28
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
29
|
-
metadata?: any;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* An edge connecting two nodes within a graph
|
|
34
|
-
*/
|
|
35
|
-
export type GraphEdge = {
|
|
36
|
-
group: "edges";
|
|
37
|
-
/**
|
|
38
|
-
* Unique ID for the edge
|
|
39
|
-
*/
|
|
40
|
-
id?: string;
|
|
41
|
-
data: {
|
|
42
|
-
id: string;
|
|
43
|
-
name: string;
|
|
44
|
-
/**
|
|
45
|
-
* Source Node
|
|
46
|
-
*/
|
|
47
|
-
source: string;
|
|
48
|
-
/**
|
|
49
|
-
* Target Node
|
|
50
|
-
*/
|
|
51
|
-
target: string;
|
|
52
|
-
type: string;
|
|
53
|
-
};
|
|
54
|
-
metadata?: {
|
|
55
|
-
label: string;
|
|
56
|
-
roleArn?: string;
|
|
57
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
58
|
-
statement?: any;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Generic type for elements in a graph
|
|
64
|
-
*/
|
|
65
|
-
export type GraphElement = GraphNode | GraphEdge;
|
|
12
|
+
export interface SelectedEdgeTarget {
|
|
13
|
+
name: string,
|
|
14
|
+
target: string
|
|
15
|
+
}
|
|
66
16
|
|
|
67
|
-
export
|
|
68
|
-
|
|
17
|
+
export interface SelectedEdge {
|
|
18
|
+
source: string;
|
|
69
19
|
target: string;
|
|
20
|
+
metadata?: Record<string, unknown>
|
|
70
21
|
};
|
|
71
22
|
|
|
72
23
|
export interface Node {
|
package/src/index.ts
CHANGED
package/src/plugins.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Graph } from "./graph";
|
|
2
|
+
import { AwsContext } from "./api";
|
|
3
|
+
|
|
4
|
+
// All supported events to trigger a plugin
|
|
5
|
+
export type GraphPluginEvents = "onServiceComplete" | "onRegionComplete" | "onAccountComplete" | "onGraphComplete";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A plugin which is called everytime a service's nodes have been added to the graph.
|
|
9
|
+
* Receives the current graph state, the service ID, and the current AWS Context.
|
|
10
|
+
*/
|
|
11
|
+
export type OnServiceCompletePlugin = (graph: Graph, service: string, context: AwsContext) => void | Promise<void>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A plugin which is called everytime a region's nodes have been added to the graph.
|
|
15
|
+
* Receives the current graph state, and the current AWS Context.
|
|
16
|
+
*/
|
|
17
|
+
export type OnRegionCompletePlugin = (graph: Graph, context: AwsContext) => void | Promise<void>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A plugin which is called everytime an account's nodes have been added to the graph.
|
|
21
|
+
* Receives the current graph state, and the current AWS Context.
|
|
22
|
+
*/
|
|
23
|
+
export type OnAccountCompletePlugin = (graph: Graph, context: AwsContext) => void | Promise<void>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A plugin which is called when the entire graph has been generated.
|
|
27
|
+
* Receives the entire graph state.
|
|
28
|
+
*/
|
|
29
|
+
export type OnGraphCompletePlugin = (graph: Graph) => void | Promise<void>;
|
|
30
|
+
|
|
31
|
+
export type PluginEventHandlerTypes = {
|
|
32
|
+
"onServiceComplete": OnServiceCompletePlugin,
|
|
33
|
+
"onRegionComplete": OnRegionCompletePlugin,
|
|
34
|
+
"onAccountComplete": OnAccountCompletePlugin,
|
|
35
|
+
"onGraphComplete": OnGraphCompletePlugin,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export interface GraphPlugin<E extends GraphPluginEvents> {
|
|
39
|
+
id: string,
|
|
40
|
+
event: E,
|
|
41
|
+
handler: PluginEventHandlerTypes[E]
|
|
42
|
+
}
|