@appland/scanner 1.71.3 → 1.71.5

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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [@appland/scanner-v1.71.5](https://github.com/getappmap/appmap-js/compare/@appland/scanner-v1.71.4...@appland/scanner-v1.71.5) (2022-10-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Fix unresolved type in Rule.Options ([f4ed63c](https://github.com/getappmap/appmap-js/commit/f4ed63ca27e7c79b8e9bdb9faf63c9b3cd10145f))
7
+
8
+ # [@appland/scanner-v1.71.4](https://github.com/getappmap/appmap-js/compare/@appland/scanner-v1.71.3...@appland/scanner-v1.71.4) (2022-10-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Export and package types for @appland/scanner ([f0b1583](https://github.com/getappmap/appmap-js/commit/f0b15838d463806322836259ed6866353e9454d8))
14
+
1
15
  # [@appland/scanner-v1.71.3](https://github.com/getappmap/appmap-js/compare/@appland/scanner-v1.71.2...@appland/scanner-v1.71.3) (2022-10-11)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@appland/scanner",
3
- "version": "1.71.3",
3
+ "version": "1.71.5",
4
4
  "description": "",
5
5
  "bin": "built/cli.js",
6
6
  "files": [
7
7
  "built",
8
- "doc"
8
+ "doc",
9
+ "src/types.d.ts"
9
10
  ],
11
+ "types": "src/types.d.ts",
10
12
  "scripts": {
11
13
  "build": "mkdir -p built && cp -r src/sampleConfig built && tsc -p tsconfig.build.json && yarn schema && yarn doc",
12
14
  "build-native": "yarn build && ./bin/build-native",
package/src/types.d.ts ADDED
@@ -0,0 +1,154 @@
1
+ import { AppMap, Event } from '@appland/models';
2
+ import { SqliteParser } from '@appland/models/types/sqlite-parser';
3
+ import { URL } from 'url';
4
+
5
+ /**
6
+ * Each Rule in the scanner library wants to consider some set of events as it decides whether the code should be flagged or not.
7
+ * A Scope is a way of declaring how these "sets" are defined. A common scope is `http_server_request`. The rule will look at each HTTP
8
+ * server request separately; what happens in one request is irrelevant to the next. For example, when looking for authz_before_authn, each HTTP
9
+ * server request is considered separately.
10
+ *
11
+ * `http_server_request` is one example of a "command". Other types of commands are: CLI commands and background jobs. Each of these has a
12
+ * defined beginning and end, and is logically completely separate from any other command.
13
+ *
14
+ * Some rules are relevant only to HTTP server requests - such as `http500`. Others are applicable to any kind of command - such as `nPlusOneQuery`.
15
+ *
16
+ * Finally, other rules simply want to look for a certain condition regardless of where it occurs. For example, Too many SQL joins will flag any
17
+ * query anywhere in the AppMap, even if it's not part of a command. This rule uses the root scope, which yields a new scope for every root-level Event
18
+ * (root-level = "has no parent").
19
+ *
20
+ * Ideally, AppMaps would not contain any events that are not part of a command - because without knowing the command, we don't really have any context
21
+ * of what the code is trying to do. But, anticipating that this may sometimes happen, "root" scope is a good choice for a rule that may flag code
22
+ * anywhere in the AppMap.
23
+ */
24
+ export type ScopeName =
25
+ | 'root'
26
+ | 'command'
27
+ | 'http_client_request'
28
+ | 'http_server_request'
29
+ | 'transaction';
30
+
31
+ /**
32
+ * Indicates the aspect of software quality that is most relevant to a rule.
33
+ */
34
+ export type ImpactDomain = 'Security' | 'Performance' | 'Maintainability' | 'Stability';
35
+
36
+ /**
37
+ * Scope provides an Event at the root of the scope, and a Generator to iterate over its descendants.
38
+ */
39
+ interface Scope {
40
+ scope: Event;
41
+ events: () => Generator<Event>;
42
+ }
43
+
44
+ /**
45
+ * Level indicates the priority of a finding.
46
+ */
47
+ export type Level = 'warning' | 'error';
48
+
49
+ type StringFilter = (value: string) => boolean;
50
+
51
+ /**
52
+ * EventFilter is used by Rule to select Events that will be analyzed for findings.
53
+ * The event filter is always applied to the Scope.scope event. If enumerateScope is true,
54
+ * the filter is applied to all Scope.events as well.
55
+ */
56
+ type EventFilter = (e: Event, appMapIndex: AppMapIndex) => boolean;
57
+
58
+ /**
59
+ * MatchResult is created by a rule when it matches an Event.
60
+ */
61
+ export interface MatchResult {
62
+ level?: Level;
63
+ event: Event;
64
+ message: string;
65
+ participatingEvents?: Record<string, Event>;
66
+ groupMessage?: string;
67
+ occurranceCount?: number;
68
+ relatedEvents?: Event[];
69
+ }
70
+
71
+ type MatcherResult =
72
+ | Promise<boolean | string | MatchResult[]>
73
+ | boolean
74
+ | string
75
+ | MatchResult[]
76
+ | undefined;
77
+
78
+ type EventType = 'http_server_request' | 'http_client_request' | 'sql_query' | 'function';
79
+
80
+ export type QueryAST = SqliteParser.ListStatement | null;
81
+
82
+ interface AppMapIndex {
83
+ appMap: AppMap;
84
+
85
+ sqlAST(event: Event): QueryAST | undefined;
86
+
87
+ sqlNormalized(event: Event): string;
88
+ }
89
+
90
+ /**
91
+ * Matcher function is part of a rule. It's applied to an Event to determine whether there is a finding
92
+ * on this event. If the Matcher returns true, a string, or a MatchResult[], then finding(s) are created.
93
+ */
94
+ type Matcher = (e: Event, appMapIndex: AppMapIndex, eventFilter: EventFilter) => MatcherResult;
95
+
96
+ /**
97
+ * Finding is the full data structure that is created when a Rule matches an Event.
98
+ *
99
+ * The Rule only needs to return a boolean, string, or MatchResult. The scanner framework
100
+ * adds the rest of the information to build the complete finding.
101
+ */
102
+ interface Finding {
103
+ appMapFile: string;
104
+ checkId: string;
105
+ ruleId: string;
106
+ ruleTitle: string;
107
+ event: Event;
108
+ hash: string; // Deprecated for local use. Still used to integrate local results with the server.
109
+ hash_v2: string;
110
+ scope: Event;
111
+ message: string;
112
+ stack: string[];
113
+ groupMessage?: string;
114
+ occurranceCount?: number;
115
+ relatedEvents?: Event[];
116
+ impactDomain?: ImpactDomain;
117
+ // Map of events by functional role name; for example, logEvent, secret, scope, etc.
118
+ participatingEvents?: Record<string, Event>;
119
+ }
120
+
121
+ interface RuleLogic {
122
+ // Tests an event in the scope see if it matches the rule conditions.
123
+ matcher: Matcher;
124
+ // When specified by the rule, only events which pass the where filter
125
+ // will be passed to the matcher.
126
+ where?: EventFilter;
127
+ // When specified by the rule, provides a detailed message for a finding on a specific event.
128
+ message?: (scope: Event, event: Event) => string;
129
+ }
130
+
131
+ interface Rule {
132
+ // Unique id of the rule.
133
+ id: string;
134
+ // Simple text description of the rule.
135
+ title: string;
136
+ // Longer text description of the rule.
137
+ description: string;
138
+ // URL to the documentation.
139
+ url?: string;
140
+ // labels which the rule depends on.
141
+ labels?: string[];
142
+ // Specifies which sub-tree events will be identified as "root events of concern".
143
+ // Events which are outside of any scope will not be processed by the rule.
144
+ scope?: ScopeName;
145
+ // Whether to pass all the events in the scope to the matcher. If false, only the scope event
146
+ // is passed to the matcher, and the rule should traverse the scope as needed.
147
+ enumerateScope: boolean;
148
+ impactDomain?: ImpactDomain;
149
+ references?: Record<string, URL>;
150
+ // User-defined options for the rule.
151
+ Options?: any; // FIXME
152
+ // Function to instantiate the rule logic from configured options.
153
+ build: (options: this['Options']) => RuleLogic;
154
+ }