@vltpkg/query 0.0.0-4 → 0.0.0-6

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.
Files changed (112) hide show
  1. package/README.md +69 -1
  2. package/dist/esm/index.d.ts +12 -1
  3. package/dist/esm/index.d.ts.map +1 -1
  4. package/dist/esm/index.js +48 -1
  5. package/dist/esm/index.js.map +1 -1
  6. package/dist/esm/pseudo/abandoned.d.ts +5 -0
  7. package/dist/esm/pseudo/abandoned.d.ts.map +1 -0
  8. package/dist/esm/pseudo/abandoned.js +6 -0
  9. package/dist/esm/pseudo/abandoned.js.map +1 -0
  10. package/dist/esm/pseudo/confused.d.ts +5 -0
  11. package/dist/esm/pseudo/confused.d.ts.map +1 -0
  12. package/dist/esm/pseudo/confused.js +6 -0
  13. package/dist/esm/pseudo/confused.js.map +1 -0
  14. package/dist/esm/pseudo/debug.d.ts +5 -0
  15. package/dist/esm/pseudo/debug.d.ts.map +1 -0
  16. package/dist/esm/pseudo/debug.js +6 -0
  17. package/dist/esm/pseudo/debug.js.map +1 -0
  18. package/dist/esm/pseudo/deprecated.d.ts +5 -0
  19. package/dist/esm/pseudo/deprecated.d.ts.map +1 -0
  20. package/dist/esm/pseudo/deprecated.js +6 -0
  21. package/dist/esm/pseudo/deprecated.js.map +1 -0
  22. package/dist/esm/pseudo/dynamic.d.ts +5 -0
  23. package/dist/esm/pseudo/dynamic.d.ts.map +1 -0
  24. package/dist/esm/pseudo/dynamic.js +6 -0
  25. package/dist/esm/pseudo/dynamic.js.map +1 -0
  26. package/dist/esm/pseudo/entropic.d.ts +5 -0
  27. package/dist/esm/pseudo/entropic.d.ts.map +1 -0
  28. package/dist/esm/pseudo/entropic.js +6 -0
  29. package/dist/esm/pseudo/entropic.js.map +1 -0
  30. package/dist/esm/pseudo/env.d.ts +5 -0
  31. package/dist/esm/pseudo/env.d.ts.map +1 -0
  32. package/dist/esm/pseudo/env.js +6 -0
  33. package/dist/esm/pseudo/env.js.map +1 -0
  34. package/dist/esm/pseudo/eval.d.ts +5 -0
  35. package/dist/esm/pseudo/eval.d.ts.map +1 -0
  36. package/dist/esm/pseudo/eval.js +6 -0
  37. package/dist/esm/pseudo/eval.js.map +1 -0
  38. package/dist/esm/pseudo/fs.d.ts +5 -0
  39. package/dist/esm/pseudo/fs.d.ts.map +1 -0
  40. package/dist/esm/pseudo/fs.js +6 -0
  41. package/dist/esm/pseudo/fs.js.map +1 -0
  42. package/dist/esm/pseudo/helpers.d.ts +4 -0
  43. package/dist/esm/pseudo/helpers.d.ts.map +1 -1
  44. package/dist/esm/pseudo/helpers.js +19 -0
  45. package/dist/esm/pseudo/helpers.js.map +1 -1
  46. package/dist/esm/pseudo/minified.d.ts +5 -0
  47. package/dist/esm/pseudo/minified.d.ts.map +1 -0
  48. package/dist/esm/pseudo/minified.js +6 -0
  49. package/dist/esm/pseudo/minified.js.map +1 -0
  50. package/dist/esm/pseudo/native.d.ts +5 -0
  51. package/dist/esm/pseudo/native.d.ts.map +1 -0
  52. package/dist/esm/pseudo/native.js +6 -0
  53. package/dist/esm/pseudo/native.js.map +1 -0
  54. package/dist/esm/pseudo/network.d.ts +5 -0
  55. package/dist/esm/pseudo/network.d.ts.map +1 -0
  56. package/dist/esm/pseudo/network.js +6 -0
  57. package/dist/esm/pseudo/network.js.map +1 -0
  58. package/dist/esm/pseudo/obfuscated.d.ts +5 -0
  59. package/dist/esm/pseudo/obfuscated.d.ts.map +1 -0
  60. package/dist/esm/pseudo/obfuscated.js +6 -0
  61. package/dist/esm/pseudo/obfuscated.js.map +1 -0
  62. package/dist/esm/pseudo/scripts.d.ts +5 -0
  63. package/dist/esm/pseudo/scripts.d.ts.map +1 -0
  64. package/dist/esm/pseudo/scripts.js +6 -0
  65. package/dist/esm/pseudo/scripts.js.map +1 -0
  66. package/dist/esm/pseudo/shell.d.ts +5 -0
  67. package/dist/esm/pseudo/shell.d.ts.map +1 -0
  68. package/dist/esm/pseudo/shell.js +6 -0
  69. package/dist/esm/pseudo/shell.js.map +1 -0
  70. package/dist/esm/pseudo/shrinkwrap.d.ts +5 -0
  71. package/dist/esm/pseudo/shrinkwrap.d.ts.map +1 -0
  72. package/dist/esm/pseudo/shrinkwrap.js +6 -0
  73. package/dist/esm/pseudo/shrinkwrap.js.map +1 -0
  74. package/dist/esm/pseudo/suspicious.d.ts +5 -0
  75. package/dist/esm/pseudo/suspicious.d.ts.map +1 -0
  76. package/dist/esm/pseudo/suspicious.js +6 -0
  77. package/dist/esm/pseudo/suspicious.js.map +1 -0
  78. package/dist/esm/pseudo/tracker.d.ts +5 -0
  79. package/dist/esm/pseudo/tracker.d.ts.map +1 -0
  80. package/dist/esm/pseudo/tracker.js +6 -0
  81. package/dist/esm/pseudo/tracker.js.map +1 -0
  82. package/dist/esm/pseudo/trivial.d.ts +5 -0
  83. package/dist/esm/pseudo/trivial.d.ts.map +1 -0
  84. package/dist/esm/pseudo/trivial.js +6 -0
  85. package/dist/esm/pseudo/trivial.js.map +1 -0
  86. package/dist/esm/pseudo/undesirable.d.ts +5 -0
  87. package/dist/esm/pseudo/undesirable.d.ts.map +1 -0
  88. package/dist/esm/pseudo/undesirable.js +6 -0
  89. package/dist/esm/pseudo/undesirable.js.map +1 -0
  90. package/dist/esm/pseudo/unknown.d.ts +5 -0
  91. package/dist/esm/pseudo/unknown.d.ts.map +1 -0
  92. package/dist/esm/pseudo/unknown.js +6 -0
  93. package/dist/esm/pseudo/unknown.js.map +1 -0
  94. package/dist/esm/pseudo/unmaintained.d.ts +5 -0
  95. package/dist/esm/pseudo/unmaintained.d.ts.map +1 -0
  96. package/dist/esm/pseudo/unmaintained.js +6 -0
  97. package/dist/esm/pseudo/unmaintained.js.map +1 -0
  98. package/dist/esm/pseudo/unpopular.d.ts +5 -0
  99. package/dist/esm/pseudo/unpopular.d.ts.map +1 -0
  100. package/dist/esm/pseudo/unpopular.js +6 -0
  101. package/dist/esm/pseudo/unpopular.js.map +1 -0
  102. package/dist/esm/pseudo/unstable.d.ts +5 -0
  103. package/dist/esm/pseudo/unstable.d.ts.map +1 -0
  104. package/dist/esm/pseudo/unstable.js +6 -0
  105. package/dist/esm/pseudo/unstable.js.map +1 -0
  106. package/dist/esm/pseudo.d.ts.map +1 -1
  107. package/dist/esm/pseudo.js +56 -4
  108. package/dist/esm/pseudo.js.map +1 -1
  109. package/dist/esm/types.d.ts +2 -0
  110. package/dist/esm/types.d.ts.map +1 -1
  111. package/dist/esm/types.js.map +1 -1
  112. package/package.json +8 -7
package/README.md CHANGED
@@ -12,7 +12,7 @@ The **vlt** query syntax engine.
12
12
  ```js
13
13
  import { Query } from '@vltpkg/query'
14
14
 
15
- const query = new Query({ nodes })
15
+ const query = new Query({ nodes, specOptions, securityArchive })
16
16
  query.search(':root > *')
17
17
  ```
18
18
 
@@ -160,3 +160,71 @@ e.g: `#foo` is the same as `[name=foo]`
160
160
  - `:root` Returns the root node, that represents the package defined
161
161
  at the top-level `package.json` of your project folder.
162
162
  - `:scope` Returns the current scope of a given selector
163
+
164
+ ### Security Selectors
165
+
166
+ The following pseudo-selectors rely on security data provided by
167
+ [Socket](https://socket.dev/), the usage of any of these selectors is
168
+ going to require a network call to hydrate package report data. Keep
169
+ in mind that this is going to slow down end-user query usage since the
170
+ security data needs to be fetched prior to a `Query` instantiation.
171
+
172
+ - `:abandoned` Matches packages that were published by an npm account
173
+ that no longer exists.
174
+ - `:confused` Matches packages affected by manifest confusion. This
175
+ could be malicious or caused by an error when publishing the
176
+ package.
177
+ - `:debug` Matches packages that use debug, reflection and dynamic
178
+ code execution features.
179
+ - `:deprecated` Matches packages marked as deprecated. This could
180
+ indicate that a single version should not be used, or that the
181
+ package is no longer maintained and any new vulnerabilities will not
182
+ be fixed.
183
+ - `:dynamic` Matches packages that uses dynamic imports.
184
+ - `:entropic` Matches packages that contains high entropic strings.
185
+ This could be a sign of encrypted data, leaked secrets or obfuscated
186
+ code.
187
+ - `:env` Matches packages that accesses environment variables, which
188
+ may be a sign of credential stuffing or data theft.
189
+ - `:eval` Matches packages that use dynamic code execution (e.g.,
190
+ eval()), which is a dangerous practice. This can prevent the code
191
+ from running in certain environments and increases the risk that the
192
+ code may contain exploits or malicious behavior.
193
+ - `:fs` Matches packages that accesses the file system, and could
194
+ potentially read sensitive data.
195
+ - `:obfuscated` Matches packages that use obfuscated files,
196
+ intentionally packed to hide their behavior. This could be a sign of
197
+ malware.
198
+ - `:minified` Matches packages that contain minified code. This may be
199
+ harmless in some cases where minified code is included in packaged
200
+ libraries.
201
+ - `:native` Matches packages that contain native code (e.g., compiled
202
+ binaries or shared libraries). Including native code can obscure
203
+ malicious behavior.
204
+ - `:network` Matches packages that access the network.
205
+ - `:scripts` Matches packages that have scripts that are run when the
206
+ package is installed. The majority of malware in npm is hidden in
207
+ install scripts.
208
+ - `:shell` Matches packages that accesses the system shell. Accessing
209
+ the system shell increases the risk of executing arbitrary code.
210
+ - `:shrinkwrap` Matches packages that contains a shrinkwrap file. This
211
+ may allow the package to bypass normal install procedures.
212
+ - `:suspicious` Matches packages that may have its GitHub repository
213
+ artificially inflated with stars (from bots, crowdsourcing, etc.).
214
+ - `:tracker` Matches packages that contains telemetry which tracks how
215
+ it is used.
216
+ - `:trivial` Matches packages that have less than 10 lines of code.
217
+ These packages are easily copied into your own project and may not
218
+ warrant the additional supply chain risk of an external dependency.
219
+ - `:undesirable` Matches packages that are a joke, parody, or includes
220
+ undocumented or hidden behavior unrelated to its primary function.
221
+ - `:unknown` Matches packages that have a new npm collaborator
222
+ publishing a version of the package for the first time. New
223
+ collaborators are usually benign additions to a project, but do
224
+ indicate a change to the security surface area of a package.
225
+ - `:unmaintained` Matches packages that have not been updated in more
226
+ than 5 years and may be unmaintained.
227
+ - `:unpopular` Matches packages that are not very popular.
228
+ - `:unstable` Matches packages with unstable ownership. This indicates
229
+ a new collaborator has begun publishing package versions. Package
230
+ stability and security risk may be elevated.
@@ -1,15 +1,26 @@
1
1
  import type { GraphLike } from '@vltpkg/graph';
2
2
  import type { SpecOptions } from '@vltpkg/spec/browser';
3
+ import type { SecurityArchiveLike } from '@vltpkg/security-archive';
3
4
  import type { ParserState, QueryResponse } from './types.ts';
4
5
  export * from './types.ts';
5
6
  export declare const walk: (state: ParserState) => Promise<ParserState>;
6
7
  export type QueryOptions = {
7
8
  graph: GraphLike;
8
9
  specOptions: SpecOptions;
10
+ securityArchive: SecurityArchiveLike | undefined;
9
11
  };
10
12
  export declare class Query {
11
13
  #private;
12
- constructor({ graph, specOptions }: QueryOptions);
14
+ /**
15
+ * Helper method to determine if a given query string is using any of
16
+ * the known security selectors. This is useful so that operations can
17
+ * skip hydrating the security archive if it's not needed.
18
+ */
19
+ static hasSecuritySelectors(query: string): boolean;
20
+ constructor({ graph, specOptions, securityArchive }: QueryOptions);
21
+ /**
22
+ * Search the graph for nodes and edges that match the given query.
23
+ */
13
24
  search(query: string, signal?: AbortSignal): Promise<QueryResponse>;
14
25
  }
15
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,SAAS,EAAY,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAYvD,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EACd,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AAiC1B,eAAO,MAAM,IAAI,UACR,WAAW,KACjB,OAAO,CAAC,WAAW,CAmDrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,SAAS,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAED,qBAAa,KAAK;;gBAKJ,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,YAAY;IAM1C,MAAM,CACV,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC;CAkD1B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,SAAS,EAAY,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAYnE,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EACd,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AAiC1B,eAAO,MAAM,IAAI,UACR,WAAW,KACjB,OAAO,CAAC,WAAW,CAmDrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,SAAS,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;IACxB,eAAe,EAAE,mBAAmB,GAAG,SAAS,CAAA;CACjD,CAAA;AA+BD,qBAAa,KAAK;;IAMhB;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;gBASvC,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,YAAY;IAOjE;;OAEG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC;CAmD1B"}
package/dist/esm/index.js CHANGED
@@ -74,15 +74,61 @@ export const walk = async (state) => {
74
74
  }
75
75
  return state;
76
76
  };
77
+ // A list of known security selectors that rely on
78
+ // data from the security-archive in order to work
79
+ const securitySelectors = new Set([
80
+ ':abandoned',
81
+ ':confused',
82
+ ':debug',
83
+ ':deprecated',
84
+ ':dynamic',
85
+ ':entropic',
86
+ ':env',
87
+ ':eval',
88
+ ':fs',
89
+ ':obfuscated',
90
+ ':minified',
91
+ ':native',
92
+ ':network',
93
+ ':scripts',
94
+ ':shell',
95
+ ':shrinkwrap',
96
+ ':suspicious',
97
+ ':tracker',
98
+ ':trivial',
99
+ ':undesirable',
100
+ ':unknown',
101
+ ':unmaintained',
102
+ ':unpopular',
103
+ ':unstable',
104
+ ]);
77
105
  export class Query {
78
106
  #cache;
79
107
  #graph;
80
108
  #specOptions;
81
- constructor({ graph, specOptions }) {
109
+ #securityArchive;
110
+ /**
111
+ * Helper method to determine if a given query string is using any of
112
+ * the known security selectors. This is useful so that operations can
113
+ * skip hydrating the security archive if it's not needed.
114
+ */
115
+ static hasSecuritySelectors(query) {
116
+ for (const selector of securitySelectors) {
117
+ if (query.includes(selector)) {
118
+ return true;
119
+ }
120
+ }
121
+ return false;
122
+ }
123
+ constructor({ graph, specOptions, securityArchive }) {
82
124
  this.#cache = new Map();
83
125
  this.#graph = graph;
84
126
  this.#specOptions = specOptions;
127
+ this.#securityArchive = securityArchive;
85
128
  }
129
+ /**
130
+ * Search the graph for nodes and edges that match the given query.
131
+ */
86
132
  async search(query, signal) {
87
133
  if (typeof query !== 'string') {
88
134
  throw new TypeError('Query search argument needs to be a string');
@@ -115,6 +161,7 @@ export class Query {
115
161
  },
116
162
  partial: { nodes, edges },
117
163
  signal,
164
+ securityArchive: this.#securityArchive,
118
165
  specOptions: this.#specOptions,
119
166
  walk,
120
167
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,cAAc,GACf,MAAM,YAAY,CAAA;AAQnB,cAAc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,CAAA;QAE9D,0CAA0C;QAC1C,kCAAkC;QAClC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC;YAC7B,WAAW,EAAE,KAAK,IAAI,EAAE;gBACtB,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;oBAC1B,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;gBACxB,CAAC,CAAC,CAAA;gBACF,MAAM,EAAE,cAAc,EAAE,CAAA;YAC1B,CAAC;YACD,OAAO,EAAE,qBAAqB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;YAC/C,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC;gBACrB,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC;aACtB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,GAAG,EAAY;gBAC1B,KAAK,EAAE,IAAI,GAAG,EAAY;aAC3B;YACD,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;YACzB,MAAM;YACN,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,IAAI;SACL,CAAC,CAAA;QAEF,MAAM,GAAG,GAAkB;YACzB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAChC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SACjC,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC3B,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, GraphLike, NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport postcssSelectorParser from 'postcss-selector-parser'\nimport { attribute } from './attribute.ts'\nimport { classFn } from './class.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport {\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n} from './types.ts'\nimport type {\n PostcssNodeWithChildren,\n ParserState,\n ParserFn,\n QueryResponse,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n class: classFn,\n combinator,\n comment: noopFn,\n id,\n nesting: noopFn,\n pseudo,\n root: noopFn,\n selector: async (state: ParserState) => {\n state.partial.nodes = new Set(state.initial.nodes)\n state.partial.edges = new Set(state.initial.edges)\n return state\n },\n string: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n tag: async (state: ParserState) => {\n if (state.current.value !== '{' && state.current.value !== '}') {\n throw error('Unsupported selector', { found: state.current })\n }\n return state\n },\n universal: noopFn,\n}\nconst selectorsMap = new Map<string, ParserFn>(\n Object.entries(selectors),\n)\n\nexport const walk = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const parserFn = selectorsMap.get(state.current.type)\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Missing parser for query node: ${state.current.type}`,\n )\n }\n state = await parserFn(state)\n\n // pseudo selectors handle their own sub selectors\n if (\n isPostcssNodeWithChildren(state.current) &&\n state.current.type !== 'pseudo'\n ) {\n const node: PostcssNodeWithChildren = asPostcssNodeWithChildren(\n state.current,\n )\n\n if (node.nodes.length) {\n for (let i = 0; i < node.nodes.length; i++) {\n const current = node.nodes[i]\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!current) continue\n\n const childState: ParserState = {\n ...state,\n current,\n next: node.nodes[i + 1],\n prev: node.nodes[i - 1],\n }\n state = await walk(childState)\n }\n }\n\n if (isSelectorNode(node)) {\n for (const edge of state.partial.edges) {\n state.collect.edges.add(edge)\n }\n for (const node of state.partial.nodes) {\n state.collect.nodes.add(node)\n }\n }\n }\n return state\n}\n\nexport type QueryOptions = {\n graph: GraphLike\n specOptions: SpecOptions\n}\n\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #specOptions: SpecOptions\n\n constructor({ graph, specOptions }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#specOptions = specOptions\n }\n\n async search(\n query: string,\n signal?: AbortSignal,\n ): Promise<QueryResponse> {\n if (typeof query !== 'string') {\n throw new TypeError(\n 'Query search argument needs to be a string',\n )\n }\n\n if (!query) return { edges: [], nodes: [] }\n\n const cachedResult = this.#cache.get(query)\n if (cachedResult) {\n return cachedResult\n }\n\n const nodes = new Set<NodeLike>(\n Array.from(this.#graph.nodes.values()),\n )\n const edges = new Set<EdgeLike>(Array.from(this.#graph.edges))\n\n // builds initial state and walks over it,\n // retrieving the collected result\n const { collect } = await walk({\n cancellable: async () => {\n await new Promise(resolve => {\n setTimeout(resolve, 0)\n })\n signal?.throwIfAborted()\n },\n current: postcssSelectorParser().astSync(query),\n initial: {\n nodes: new Set(nodes),\n edges: new Set(edges),\n },\n collect: {\n nodes: new Set<NodeLike>(),\n edges: new Set<EdgeLike>(),\n },\n partial: { nodes, edges },\n signal,\n specOptions: this.#specOptions,\n walk,\n })\n\n const res: QueryResponse = {\n edges: Array.from(collect.edges),\n nodes: Array.from(collect.nodes),\n }\n this.#cache.set(query, res)\n return res\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAI3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EACL,yBAAyB,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K,CAAC;aACtB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,GAAG,EAAY;gBAC1B,KAAK,EAAE,IAAI,GAAG,EAAY;aAC3B;YACD,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;YACzB,MAAM;YACN,eAAe,EAAE,IAAI,CAAC,gBAAgB;YACtC,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,IAAI;SACL,CAAC,CAAA;QAEF,MAAM,GAAG,GAAkB;YACzB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAChC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SACjC,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC3B,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, GraphLike, NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport type { SecurityArchiveLike } from '@vltpkg/security-archive'\nimport postcssSelectorParser from 'postcss-selector-parser'\nimport { attribute } from './attribute.ts'\nimport { classFn } from './class.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport {\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n} from './types.ts'\nimport type {\n PostcssNodeWithChildren,\n ParserState,\n ParserFn,\n QueryResponse,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n class: classFn,\n combinator,\n comment: noopFn,\n id,\n nesting: noopFn,\n pseudo,\n root: noopFn,\n selector: async (state: ParserState) => {\n state.partial.nodes = new Set(state.initial.nodes)\n state.partial.edges = new Set(state.initial.edges)\n return state\n },\n string: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n tag: async (state: ParserState) => {\n if (state.current.value !== '{' && state.current.value !== '}') {\n throw error('Unsupported selector', { found: state.current })\n }\n return state\n },\n universal: noopFn,\n}\nconst selectorsMap = new Map<string, ParserFn>(\n Object.entries(selectors),\n)\n\nexport const walk = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const parserFn = selectorsMap.get(state.current.type)\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Missing parser for query node: ${state.current.type}`,\n )\n }\n state = await parserFn(state)\n\n // pseudo selectors handle their own sub selectors\n if (\n isPostcssNodeWithChildren(state.current) &&\n state.current.type !== 'pseudo'\n ) {\n const node: PostcssNodeWithChildren = asPostcssNodeWithChildren(\n state.current,\n )\n\n if (node.nodes.length) {\n for (let i = 0; i < node.nodes.length; i++) {\n const current = node.nodes[i]\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!current) continue\n\n const childState: ParserState = {\n ...state,\n current,\n next: node.nodes[i + 1],\n prev: node.nodes[i - 1],\n }\n state = await walk(childState)\n }\n }\n\n if (isSelectorNode(node)) {\n for (const edge of state.partial.edges) {\n state.collect.edges.add(edge)\n }\n for (const node of state.partial.nodes) {\n state.collect.nodes.add(node)\n }\n }\n }\n return state\n}\n\nexport type QueryOptions = {\n graph: GraphLike\n specOptions: SpecOptions\n securityArchive: SecurityArchiveLike | undefined\n}\n\n// A list of known security selectors that rely on\n// data from the security-archive in order to work\nconst securitySelectors = new Set([\n ':abandoned',\n ':confused',\n ':debug',\n ':deprecated',\n ':dynamic',\n ':entropic',\n ':env',\n ':eval',\n ':fs',\n ':obfuscated',\n ':minified',\n ':native',\n ':network',\n ':scripts',\n ':shell',\n ':shrinkwrap',\n ':suspicious',\n ':tracker',\n ':trivial',\n ':undesirable',\n ':unknown',\n ':unmaintained',\n ':unpopular',\n ':unstable',\n])\n\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #specOptions: SpecOptions\n #securityArchive: SecurityArchiveLike | undefined\n\n /**\n * Helper method to determine if a given query string is using any of\n * the known security selectors. This is useful so that operations can\n * skip hydrating the security archive if it's not needed.\n */\n static hasSecuritySelectors(query: string): boolean {\n for (const selector of securitySelectors) {\n if (query.includes(selector)) {\n return true\n }\n }\n return false\n }\n\n constructor({ graph, specOptions, securityArchive }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#specOptions = specOptions\n this.#securityArchive = securityArchive\n }\n\n /**\n * Search the graph for nodes and edges that match the given query.\n */\n async search(\n query: string,\n signal?: AbortSignal,\n ): Promise<QueryResponse> {\n if (typeof query !== 'string') {\n throw new TypeError(\n 'Query search argument needs to be a string',\n )\n }\n\n if (!query) return { edges: [], nodes: [] }\n\n const cachedResult = this.#cache.get(query)\n if (cachedResult) {\n return cachedResult\n }\n\n const nodes = new Set<NodeLike>(\n Array.from(this.#graph.nodes.values()),\n )\n const edges = new Set<EdgeLike>(Array.from(this.#graph.edges))\n\n // builds initial state and walks over it,\n // retrieving the collected result\n const { collect } = await walk({\n cancellable: async () => {\n await new Promise(resolve => {\n setTimeout(resolve, 0)\n })\n signal?.throwIfAborted()\n },\n current: postcssSelectorParser().astSync(query),\n initial: {\n nodes: new Set(nodes),\n edges: new Set(edges),\n },\n collect: {\n nodes: new Set<NodeLike>(),\n edges: new Set<EdgeLike>(),\n },\n partial: { nodes, edges },\n signal,\n securityArchive: this.#securityArchive,\n specOptions: this.#specOptions,\n walk,\n })\n\n const res: QueryResponse = {\n edges: Array.from(collect.edges),\n nodes: Array.from(collect.nodes),\n }\n this.#cache.set(query, res)\n return res\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **missingAuthor** report alert.
3
+ */
4
+ export declare const abandoned: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=abandoned.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abandoned.d.ts","sourceRoot":"","sources":["../../../src/pseudo/abandoned.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS,0FAGrB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **missingAuthor** report alert.
4
+ */
5
+ export const abandoned = createSecuritySelectorFilter('abandoned', 'missingAuthor');
6
+ //# sourceMappingURL=abandoned.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abandoned.js","sourceRoot":"","sources":["../../../src/pseudo/abandoned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,4BAA4B,CACnD,WAAW,EACX,eAAe,CAChB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **missingAuthor** report alert.\n */\nexport const abandoned = createSecuritySelectorFilter(\n 'abandoned',\n 'missingAuthor',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **manifestConfusion** report alert.
3
+ */
4
+ export declare const confused: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=confused.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confused.d.ts","sourceRoot":"","sources":["../../../src/pseudo/confused.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,QAAQ,0FAGpB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **manifestConfusion** report alert.
4
+ */
5
+ export const confused = createSecuritySelectorFilter('confused', 'manifestConfusion');
6
+ //# sourceMappingURL=confused.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confused.js","sourceRoot":"","sources":["../../../src/pseudo/confused.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,4BAA4B,CAClD,UAAU,EACV,mBAAmB,CACpB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **manifestConfusion** report alert.\n */\nexport const confused = createSecuritySelectorFilter(\n 'confused',\n 'manifestConfusion',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **debugAccess** report alert.
3
+ */
4
+ export declare const debug: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../src/pseudo/debug.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,KAAK,0FAGjB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **debugAccess** report alert.
4
+ */
5
+ export const debug = createSecuritySelectorFilter('debug', 'debugAccess');
6
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/pseudo/debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,4BAA4B,CAC/C,OAAO,EACP,aAAa,CACd,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **debugAccess** report alert.\n */\nexport const debug = createSecuritySelectorFilter(\n 'debug',\n 'debugAccess',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **deprecated** report alert.
3
+ */
4
+ export declare const deprecated: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=deprecated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecated.d.ts","sourceRoot":"","sources":["../../../src/pseudo/deprecated.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,UAAU,0FAGtB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **deprecated** report alert.
4
+ */
5
+ export const deprecated = createSecuritySelectorFilter('deprecated', 'deprecated');
6
+ //# sourceMappingURL=deprecated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecated.js","sourceRoot":"","sources":["../../../src/pseudo/deprecated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CACpD,YAAY,EACZ,YAAY,CACb,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **deprecated** report alert.\n */\nexport const deprecated = createSecuritySelectorFilter(\n 'deprecated',\n 'deprecated',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **dynamicRequire** report alert.
3
+ */
4
+ export declare const dynamic: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=dynamic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic.d.ts","sourceRoot":"","sources":["../../../src/pseudo/dynamic.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO,0FAGnB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **dynamicRequire** report alert.
4
+ */
5
+ export const dynamic = createSecuritySelectorFilter('dynamic', 'dynamicRequire');
6
+ //# sourceMappingURL=dynamic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic.js","sourceRoot":"","sources":["../../../src/pseudo/dynamic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CACjD,SAAS,EACT,gBAAgB,CACjB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **dynamicRequire** report alert.\n */\nexport const dynamic = createSecuritySelectorFilter(\n 'dynamic',\n 'dynamicRequire',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **highEntropyStrings** report alert.
3
+ */
4
+ export declare const entropic: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=entropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entropic.d.ts","sourceRoot":"","sources":["../../../src/pseudo/entropic.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,QAAQ,0FAGpB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **highEntropyStrings** report alert.
4
+ */
5
+ export const entropic = createSecuritySelectorFilter('entropic', 'highEntropyStrings');
6
+ //# sourceMappingURL=entropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entropic.js","sourceRoot":"","sources":["../../../src/pseudo/entropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,4BAA4B,CAClD,UAAU,EACV,oBAAoB,CACrB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **highEntropyStrings** report alert.\n */\nexport const entropic = createSecuritySelectorFilter(\n 'entropic',\n 'highEntropyStrings',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **envVars** report alert.
3
+ */
4
+ export declare const env: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/pseudo/env.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,GAAG,0FAAiD,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **envVars** report alert.
4
+ */
5
+ export const env = createSecuritySelectorFilter('env', 'envVars');
6
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/pseudo/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,4BAA4B,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **envVars** report alert.\n */\nexport const env = createSecuritySelectorFilter('env', 'envVars')\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **usesEval** report alert.
3
+ */
4
+ export declare const evalParser: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=eval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../../src/pseudo/eval.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,UAAU,0FAGtB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **usesEval** report alert.
4
+ */
5
+ export const evalParser = createSecuritySelectorFilter('eval', 'usesEval');
6
+ //# sourceMappingURL=eval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval.js","sourceRoot":"","sources":["../../../src/pseudo/eval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CACpD,MAAM,EACN,UAAU,CACX,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **usesEval** report alert.\n */\nexport const evalParser = createSecuritySelectorFilter(\n 'eval',\n 'usesEval',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **filesystemAccess** report alert.
3
+ */
4
+ export declare const fs: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src/pseudo/fs.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,EAAE,0FAGd,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **filesystemAccess** report alert.
4
+ */
5
+ export const fs = createSecuritySelectorFilter('fs', 'filesystemAccess');
6
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/pseudo/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,4BAA4B,CAC5C,IAAI,EACJ,kBAAkB,CACnB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **filesystemAccess** report alert.\n */\nexport const fs = createSecuritySelectorFilter(\n 'fs',\n 'filesystemAccess',\n)\n"]}
@@ -12,4 +12,8 @@ export declare const removeDanglingEdges: (state: ParserState) => void;
12
12
  * Removes quotes from a string value.
13
13
  */
14
14
  export declare const removeQuotes: (value: string) => string;
15
+ /**
16
+ * Reusable security selector alert filter.
17
+ */
18
+ export declare const createSecuritySelectorFilter: (name: string, type: string) => (state: ParserState) => Promise<ParserState>;
15
19
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/pseudo/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,UAAU,UAAW,WAAW,QAAQ,QAAQ,SAK5D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,UAAW,WAAW,SAMrD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,WACR,CAAA"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/pseudo/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,UAAU,UAAW,WAAW,QAAQ,QAAQ,SAK5D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,UAAW,WAAW,SAMrD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,WACR,CAAA;AAElC;;GAEG;AACH,eAAO,MAAM,4BAA4B,SACjC,MAAM,QACN,MAAM,aAES,WAAW,yBAqBjC,CAAA"}
@@ -21,4 +21,23 @@ export const removeDanglingEdges = (state) => {
21
21
  * Removes quotes from a string value.
22
22
  */
23
23
  export const removeQuotes = (value) => value.replace(/^"(.*?)"$/, '$1');
24
+ /**
25
+ * Reusable security selector alert filter.
26
+ */
27
+ export const createSecuritySelectorFilter = (name, type) => {
28
+ return async (state) => {
29
+ if (!state.securityArchive) {
30
+ throw new Error(`Missing security archive while trying to parse the :${name} security selector`);
31
+ }
32
+ for (const node of state.partial.nodes) {
33
+ const report = state.securityArchive.get(node.id);
34
+ const exclude = !report?.alerts.some(alert => alert.type === type);
35
+ if (exclude) {
36
+ removeNode(state, node);
37
+ }
38
+ }
39
+ removeDanglingEdges(state);
40
+ return state;
41
+ };
42
+ };
24
43
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/pseudo/helpers.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAkB,EAAE,IAAc,EAAE,EAAE;IAC/D,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAClC,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAkB,EAAE,EAAE;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAC5C,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA","sourcesContent":["import type { NodeLike } from '@vltpkg/graph'\nimport type { ParserState } from '../types.js'\n\n/**\n * Removes a node and its incoming edges from the results.\n */\nexport const removeNode = (state: ParserState, node: NodeLike) => {\n for (const edge of node.edgesIn) {\n state.partial.edges.delete(edge)\n }\n state.partial.nodes.delete(node)\n}\n\n/**\n * Removes any edges that have no destination node from the results.\n */\nexport const removeDanglingEdges = (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (!edge.to) {\n state.partial.edges.delete(edge)\n }\n }\n}\n\n/**\n * Removes quotes from a string value.\n */\nexport const removeQuotes = (value: string) =>\n value.replace(/^\"(.*?)\"$/, '$1')\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/pseudo/helpers.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAkB,EAAE,IAAc,EAAE,EAAE;IAC/D,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAClC,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAkB,EAAE,EAAE;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAC5C,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,IAAY,EACZ,IAAY,EACZ,EAAE;IACF,OAAO,KAAK,EAAE,KAAkB,EAAE,EAAE;QAClC,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,uDAAuD,IAAI,oBAAoB,CAChF,CAAA;QACH,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACvC,MAAM,MAAM,GAAG,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACjD,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAClC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAC7B,CAAA;YACD,IAAI,OAAO,EAAE,CAAC;gBACZ,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;QAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;QAE1B,OAAO,KAAK,CAAA;IACd,CAAC,CAAA;AACH,CAAC,CAAA","sourcesContent":["import type { NodeLike } from '@vltpkg/graph'\nimport type { ParserState } from '../types.js'\n\n/**\n * Removes a node and its incoming edges from the results.\n */\nexport const removeNode = (state: ParserState, node: NodeLike) => {\n for (const edge of node.edgesIn) {\n state.partial.edges.delete(edge)\n }\n state.partial.nodes.delete(node)\n}\n\n/**\n * Removes any edges that have no destination node from the results.\n */\nexport const removeDanglingEdges = (state: ParserState) => {\n for (const edge of state.partial.edges) {\n if (!edge.to) {\n state.partial.edges.delete(edge)\n }\n }\n}\n\n/**\n * Removes quotes from a string value.\n */\nexport const removeQuotes = (value: string) =>\n value.replace(/^\"(.*?)\"$/, '$1')\n\n/**\n * Reusable security selector alert filter.\n */\nexport const createSecuritySelectorFilter = (\n name: string,\n type: string,\n) => {\n return async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n `Missing security archive while trying to parse the :${name} security selector`,\n )\n }\n\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(\n alert => alert.type === type,\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **minifiedFile** report alert.
3
+ */
4
+ export declare const minified: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=minified.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minified.d.ts","sourceRoot":"","sources":["../../../src/pseudo/minified.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,QAAQ,0FAGpB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **minifiedFile** report alert.
4
+ */
5
+ export const minified = createSecuritySelectorFilter('minified', 'minifiedFile');
6
+ //# sourceMappingURL=minified.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minified.js","sourceRoot":"","sources":["../../../src/pseudo/minified.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,4BAA4B,CAClD,UAAU,EACV,cAAc,CACf,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **minifiedFile** report alert.\n */\nexport const minified = createSecuritySelectorFilter(\n 'minified',\n 'minifiedFile',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **hasNativeCode** report alert.
3
+ */
4
+ export declare const nativeParser: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/pseudo/native.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,YAAY,0FAGxB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **hasNativeCode** report alert.
4
+ */
5
+ export const nativeParser = createSecuritySelectorFilter('native', 'hasNativeCode');
6
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../../../src/pseudo/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,4BAA4B,CACtD,QAAQ,EACR,eAAe,CAChB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **hasNativeCode** report alert.\n */\nexport const nativeParser = createSecuritySelectorFilter(\n 'native',\n 'hasNativeCode',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have a **networkAccess** report alert.
3
+ */
4
+ export declare const network: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../src/pseudo/network.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO,0FAGnB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have a **networkAccess** report alert.
4
+ */
5
+ export const network = createSecuritySelectorFilter('network', 'networkAccess');
6
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../../src/pseudo/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CACjD,SAAS,EACT,eAAe,CAChB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **networkAccess** report alert.\n */\nexport const network = createSecuritySelectorFilter(\n 'network',\n 'networkAccess',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have an **obfuscatedFile** report alert.
3
+ */
4
+ export declare const obfuscated: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=obfuscated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"obfuscated.d.ts","sourceRoot":"","sources":["../../../src/pseudo/obfuscated.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,UAAU,0FAGtB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { createSecuritySelectorFilter } from "./helpers.js";
2
+ /**
3
+ * Filters out any node that does not have an **obfuscatedFile** report alert.
4
+ */
5
+ export const obfuscated = createSecuritySelectorFilter('obfuscated', 'obfuscatedFile');
6
+ //# sourceMappingURL=obfuscated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"obfuscated.js","sourceRoot":"","sources":["../../../src/pseudo/obfuscated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CACpD,YAAY,EACZ,gBAAgB,CACjB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have an **obfuscatedFile** report alert.\n */\nexport const obfuscated = createSecuritySelectorFilter(\n 'obfuscated',\n 'obfuscatedFile',\n)\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Filters out any node that does not have an **installScripts** report alert.
3
+ */
4
+ export declare const scripts: (state: import("../types.ts").ParserState) => Promise<import("../types.ts").ParserState>;
5
+ //# sourceMappingURL=scripts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../src/pseudo/scripts.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO,0FAGnB,CAAA"}