@dataparade/cli 0.0.2 → 0.0.4

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 (74) hide show
  1. package/README.md +25 -0
  2. package/dist/package.json +85 -0
  3. package/dist/src/ai-enrichment/agent-orchestrator.d.ts +2 -0
  4. package/dist/src/ai-enrichment/agent-orchestrator.js +8 -5
  5. package/dist/src/ai-enrichment/providers/hosted-worker-infer-provider.d.ts +10 -0
  6. package/dist/src/ai-enrichment/providers/hosted-worker-infer-provider.js +47 -0
  7. package/dist/src/cli.js +85 -1
  8. package/dist/src/config/env.js +2 -0
  9. package/dist/src/config/resolve.js +3 -0
  10. package/dist/src/config/scan-env.d.ts +1 -0
  11. package/dist/src/config/scan-env.js +5 -0
  12. package/dist/src/config/types.d.ts +1 -0
  13. package/dist/src/config/upload-env.d.ts +1 -0
  14. package/dist/src/config/upload-env.js +10 -0
  15. package/dist/src/config/validate-scan-ai.d.ts +1 -1
  16. package/dist/src/config/validate-scan-ai.js +5 -0
  17. package/dist/src/core/pipeline/ai-orchestrator-options.js +5 -0
  18. package/dist/src/core/pipeline/graph-mapping.js +5 -0
  19. package/dist/src/core/pipeline/infer-data-flow-protocol.d.ts +7 -0
  20. package/dist/src/core/pipeline/infer-data-flow-protocol.js +39 -0
  21. package/dist/src/core/schema/scan-config.schema.d.ts +2 -0
  22. package/dist/src/core/schema/scan-config.schema.js +2 -1
  23. package/dist/src/core/types/config.d.ts +3 -1
  24. package/dist/src/observability/scan-sentry.d.ts +1 -1
  25. package/dist/src/platform-api/dataparade-app-base-url.d.ts +7 -0
  26. package/dist/src/platform-api/dataparade-app-base-url.js +14 -0
  27. package/dist/src/platform-api/upload-client.d.ts +3 -0
  28. package/dist/src/platform-api/upload-client.js +38 -0
  29. package/dist/src/platform-api/upload.types.d.ts +10 -0
  30. package/dist/src/platform-api/upload.types.js +2 -0
  31. package/dist/src/upload/build-preview-url.d.ts +1 -0
  32. package/dist/src/upload/build-preview-url.js +10 -0
  33. package/dist/src/upload/run-upload.d.ts +2 -0
  34. package/dist/src/upload/run-upload.js +18 -0
  35. package/dist/src/upload/types.d.ts +11 -0
  36. package/dist/src/upload/types.js +2 -0
  37. package/dist/tests/unit/analyzers/typescript/property-detection.spec.js +22 -0
  38. package/dist/tests/unit/cli/scan-quota-flow.spec.js +2 -0
  39. package/dist/tests/unit/config/upload-env.spec.d.ts +1 -0
  40. package/dist/tests/unit/config/upload-env.spec.js +12 -0
  41. package/dist/tests/unit/config/validate-scan-ai.spec.js +8 -0
  42. package/dist/tests/unit/core/graph-mapping.spec.js +52 -0
  43. package/dist/tests/unit/core/infer-data-flow-protocol.spec.d.ts +1 -0
  44. package/dist/tests/unit/core/infer-data-flow-protocol.spec.js +37 -0
  45. package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.d.ts +1 -0
  46. package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +13 -0
  47. package/dist/tests/unit/platform-api/upload-client.spec.d.ts +1 -0
  48. package/dist/tests/unit/platform-api/upload-client.spec.js +40 -0
  49. package/dist/tests/unit/publish-manifest.spec.d.ts +1 -0
  50. package/dist/tests/unit/publish-manifest.spec.js +18 -0
  51. package/dist/tests/unit/upload/build-preview-url.spec.d.ts +1 -0
  52. package/dist/tests/unit/upload/build-preview-url.spec.js +19 -0
  53. package/package.json +4 -3
  54. package/patterns/README.md +322 -0
  55. package/patterns/actor.patterns.yaml +51 -0
  56. package/patterns/aws-terraform-catalog.snapshot.json +1760 -0
  57. package/patterns/aws-terraform-service-hints.generated.json +1446 -0
  58. package/patterns/azure-terraform-catalog.snapshot.json +1195 -0
  59. package/patterns/azure-terraform-service-hints.generated.json +864 -0
  60. package/patterns/classifier/actors.classifier.yaml +17 -0
  61. package/patterns/classifier/components.classifier.yaml +110 -0
  62. package/patterns/classifier/third-party.classifier.yaml +169 -0
  63. package/patterns/kubernetes-terraform-catalog.snapshot.json +94 -0
  64. package/patterns/kubernetes-terraform-service-hints.generated.json +258 -0
  65. package/patterns/non-pii-signals.rules.yaml +84 -0
  66. package/patterns/pii-signals.rules.yaml +115 -0
  67. package/patterns/property.patterns.yaml +431 -0
  68. package/patterns/provider-topology.rules.yaml +765 -0
  69. package/patterns/python.md +211 -0
  70. package/patterns/python.patterns.yaml +160 -0
  71. package/patterns/terraform.md +37 -0
  72. package/patterns/terraform.patterns.yaml +495 -0
  73. package/patterns/third-party.patterns.yaml +167 -0
  74. package/patterns/typescript.patterns.yaml +139 -0
@@ -0,0 +1,322 @@
1
+ # TypeScript / JavaScript Patterns
2
+
3
+ This document describes the TypeScript/JavaScript patterns implemented by the
4
+ CLI TS/JS analyzer for **DP-P0-CLI-104**. These patterns are heuristic and not
5
+ exhaustive; they are designed to provide useful structural signals for the
6
+ classifier and data-flow detector.
7
+
8
+ Patterns are configured in two layers:
9
+
10
+ - A **YAML configuration file** at `cli/patterns/typescript.patterns.yaml`
11
+ which defines pattern IDs, known libraries/SDKs, regexes, and confidences.
12
+ - A **TypeScript execution engine** (`cli/src/analyzers/typescript/typescript-detection.ts`
13
+ and `cli/src/analyzers/typescript/typescript-detection-config.ts`) that loads the YAML,
14
+ validates it, compiles regexes, and applies them to `FileInfo` plus the TS/JS
15
+ code model.
16
+
17
+ Each detected match produces a `RawFinding` object using the shared `PatternId`
18
+ union from `cli/src/core/types/detection.ts`. The YAML file controls **what**
19
+ we look for (libraries, regexes, keys); the TypeScript engine controls **how**
20
+ those patterns are applied.
21
+
22
+ ---
23
+
24
+ ## `express_route`
25
+
26
+ **Purpose:** Detect HTTP route handlers in common web frameworks.
27
+
28
+ **Frameworks covered (heuristic):**
29
+
30
+ - Express (imports from `"express"`)
31
+ - NestJS (imports from `"@nestjs/common"` / `"@nestjs/core"`)
32
+ - Next.js / React route handlers (file-path based heuristic such as
33
+ `pages/api/*`, `app/*`, `*route.ts`, `*route.js`)
34
+
35
+ **Examples:**
36
+
37
+ ```ts
38
+ // Express
39
+ import express from "express";
40
+
41
+ const app = express();
42
+ app.get("/users", (req, res) => {
43
+ res.send("ok");
44
+ });
45
+ ```
46
+
47
+ ```ts
48
+ // NestJS
49
+ import { Controller, Get } from "@nestjs/common";
50
+
51
+ @Controller("users")
52
+ export class UsersController {
53
+ @Get("/")
54
+ findAll() {}
55
+ }
56
+ ```
57
+
58
+ ```ts
59
+ // Next.js API route (pages/api/users.ts)
60
+ export default async function handler(req: NextApiRequest, res: NextApiResponse) {
61
+ res.status(200).json({ ok: true });
62
+ }
63
+ ```
64
+
65
+ **Properties set on `RawFinding.properties`:**
66
+
67
+ - `framework: "express" | "nest" | "next_or_react_route"`
68
+ - `httpMethods: string[]` – e.g. `["GET"]` when a method can be inferred
69
+ - `path?: string` – route path when it can be parsed (e.g. `"/users"`)
70
+
71
+ ---
72
+
73
+ ## `database_connection`
74
+
75
+ **Purpose:** Detect creation or usage of database and cache clients.
76
+
77
+ **Libraries covered (heuristic):**
78
+
79
+ - `pg` (`new Pool(...)`, `new Client(...)`)
80
+ - `mysql2` (`createConnection(...)`)
81
+ - Prisma (`new PrismaClient(...)`)
82
+ - Mongoose (`mongoose.connect(...)`)
83
+ - Redis (`createClient(...)`)
84
+ - Supabase (`createClient(...)` from `@supabase/supabase-js`)
85
+
86
+ **Examples:**
87
+
88
+ ```ts
89
+ import { Pool } from "pg";
90
+
91
+ const pool = new Pool({
92
+ connectionString: process.env.DATABASE_URL,
93
+ });
94
+ ```
95
+
96
+ ```ts
97
+ import { PrismaClient } from "@prisma/client";
98
+
99
+ const prisma = new PrismaClient();
100
+ ```
101
+
102
+ ```ts
103
+ import mongoose from "mongoose";
104
+
105
+ mongoose.connect(process.env.MONGO_URL!);
106
+ ```
107
+
108
+ **Properties set on `RawFinding.properties`:**
109
+
110
+ - `client: string` – e.g. `"pg"`, `"mysql2"`, `"prisma"`, `"mongoose"`, `"redis"`, `"supabase"`
111
+ - `databaseType: string` – e.g. `"postgres"`, `"mysql"`, `"mongo"`, `"redis"`, `"unknown"`
112
+ - For heuristic SQL keyword matches, an additional hint:
113
+ - `hint: "raw_sql_keyword"`
114
+
115
+ ---
116
+
117
+ ## `external_api_call`
118
+
119
+ **Purpose:** Detect calls to external HTTP APIs or third-party SDKs.
120
+
121
+ **HTTP clients covered (heuristic):**
122
+
123
+ - Global `fetch(...)`
124
+ - `axios.get/post/put/delete/patch(...)`
125
+ - `got(...)`
126
+
127
+ **Known SDK/service hints:**
128
+
129
+ - Stripe (`"stripe"`)
130
+ - SendGrid (`"sendgrid"`)
131
+ - Twilio (`"twilio"`)
132
+ - OpenAI (`"openai"`)
133
+ - AWS SDK (`"@aws-sdk/..."`)
134
+ - Firebase (`"firebase"`)
135
+
136
+ **Examples:**
137
+
138
+ ```ts
139
+ // Generic HTTP call
140
+ const res = await fetch("https://api.example.com/users");
141
+ ```
142
+
143
+ ```ts
144
+ // Axios with method
145
+ import axios from "axios";
146
+
147
+ await axios.post("https://api.example.com/users", { name: "Alice" });
148
+ ```
149
+
150
+ ```ts
151
+ // Stripe SDK import
152
+ import Stripe from "stripe";
153
+
154
+ const stripe = new Stripe(process.env.STRIPE_KEY!, { apiVersion: "2022-11-15" });
155
+ ```
156
+
157
+ **Properties set on `RawFinding.properties`:**
158
+
159
+ - For direct HTTP calls:
160
+ - `client: string` – e.g. `"fetch"`, `"axios.get"`, `"axios.post"`, `"got"`
161
+ - `url: string` – full URL if present in the call
162
+ - `httpMethod?: string` – uppercase method when derivable
163
+ - For SDK / service hints:
164
+ - `client: string` – service/client identifier, e.g. `"stripe"`
165
+ - `serviceName: string` – same as `client` for now
166
+
167
+ ---
168
+
169
+ ## `auth_middleware`
170
+
171
+ **Purpose:** Detect authentication/authorization-related middleware and guards.
172
+
173
+ **Libraries and patterns covered (heuristic):**
174
+
175
+ - Passport (`passport.authenticate(...)`, imports from `"passport"` or modules containing `"passport"`)
176
+ - JSON Web Tokens (`jsonwebtoken`, `jwt.sign(...)`, `jwt.verify(...)`)
177
+ - NestJS auth guards (`@nestjs/passport`, `UseGuards(...)`)
178
+
179
+ **Examples:**
180
+
181
+ ```ts
182
+ import passport from "passport";
183
+
184
+ app.get(
185
+ "/profile",
186
+ passport.authenticate("jwt", { session: false }),
187
+ (req, res) => res.send("ok"),
188
+ );
189
+ ```
190
+
191
+ ```ts
192
+ import jwt from "jsonwebtoken";
193
+
194
+ const token = jwt.sign({ sub: user.id }, process.env.JWT_SECRET!);
195
+ ```
196
+
197
+ ```ts
198
+ import { UseGuards } from "@nestjs/common";
199
+ import { AuthGuard } from "@nestjs/passport";
200
+
201
+ @UseGuards(AuthGuard("jwt"))
202
+ @Get("me")
203
+ getProfile() {}
204
+ ```
205
+
206
+ **Properties set on `RawFinding.properties`:**
207
+
208
+ - For Passport:
209
+ - `library: "passport"`
210
+ - `strategy?: string` – strategy name when parsed from `passport.authenticate("strategy", ...)`
211
+ - For JWT:
212
+ - `library: "jsonwebtoken"`
213
+ - For NestJS guards:
214
+ - `library: "nestjs_auth"`
215
+
216
+ ---
217
+
218
+ ## `env_variable`
219
+
220
+ **Purpose:** Detect environment variable usage in TS/JS code.
221
+
222
+ **Pattern:** `process.env.<KEY>`
223
+
224
+ **Examples:**
225
+
226
+ ```ts
227
+ const dbUrl = process.env.DATABASE_URL;
228
+ const apiKey = process.env.API_KEY;
229
+ ```
230
+
231
+ **Properties set on `RawFinding.properties`:**
232
+
233
+ - `key: string` – the environment variable key, e.g. `"DATABASE_URL"`, `"API_KEY"`
234
+
235
+ ---
236
+
237
+ ## `config_file`
238
+
239
+ **Purpose:** Detect access to configuration objects in TS/JS code that likely
240
+ point to configuration or secret values (for later mapping to assets or
241
+ environment configuration).
242
+
243
+ **Pattern:** `config.<field>` where `<field>` is one of:
244
+
245
+ - `database`
246
+ - `db`
247
+ - `apiKey`
248
+ - `api_key`
249
+ - `auth`
250
+ - `redis`
251
+
252
+ **Examples:**
253
+
254
+ ```ts
255
+ import config from "./config";
256
+
257
+ const dbConfig = config.database;
258
+ const redisConfig = config.redis;
259
+ ```
260
+
261
+ **Properties set on `RawFinding.properties`:**
262
+
263
+ - `key: string` – the accessed config key, e.g. `"database"`, `"apiKey"`
264
+
265
+ ---
266
+
267
+ ## Actor detection (`web_actor`, `service_actor`)
268
+
269
+ **Purpose:** Detect human and system actors so the classifier can emit
270
+ `DetectedComponent` entries with `type: "actor"` alongside assets and third
271
+ parties.
272
+
273
+ Actor detection is configured in a shared YAML file:
274
+
275
+ -- `cli/patterns/actor.patterns.yaml` – defines regexes and rules for emitting
276
+ `web_actor` and `service_actor` findings, and attaches basic properties such
277
+ as `actorType`, `roleNames`, and `sourceContext`.
278
+
279
+ The classifier maps these pattern IDs to actors via `classifier/components.classifier.yaml`:
280
+
281
+ - `web_actor` → `type: actor`, `subType: customer`
282
+ - `service_actor` → `type: actor`, `subType: employee`
283
+
284
+ ### Signals used by the TS/JS analyzer
285
+
286
+ The TypeScript/JavaScript analyzer loads `actor.patterns.yaml` through
287
+ `cli/src/config/actor-detection-config.ts` and applies rules in
288
+ `cli/src/analyzers/typescript/actor-detection.ts`. Current heuristics include:
289
+
290
+ - **Frontend session hook**
291
+ - File path matches `hooks/useSession.ts` / `hooks/useSession.tsx`.
292
+ - Emits a `web_actor` finding named `"Customer"` with:
293
+ - `properties.actorType = "customer"`
294
+ - `properties.sourceContext = "frontend_session"`.
295
+
296
+ - **Backend controllers using `req.user`**
297
+ - Content contains `req.user` (e.g. NestJS/Express controllers).
298
+ - Emits a `web_actor` finding named `"Customer"` with:
299
+ - `properties.actorType = "customer"`
300
+ - `properties.sourceContext = "backend_controller"`.
301
+
302
+ - **Backend admin role checks**
303
+ - Content contains simple admin role checks (e.g. `isAdmin`, `role: "admin"`).
304
+ - Emits a `service_actor` finding named `"Admin user"` with:
305
+ - `properties.actorType = "employee"`
306
+ - `properties.roleNames = ["admin"]`
307
+ - `properties.sourceContext = "backend_role_check"`.
308
+
309
+ Other language analyzers can reuse the same `web_actor` / `service_actor`
310
+ pattern IDs by loading `actor.patterns.yaml` and emitting compatible
311
+ `RawFinding`s; the classifier does not need to change for each language.
312
+
313
+ ---
314
+
315
+ These patterns are intentionally conservative and heuristic. They are meant to
316
+ provide a good baseline for:
317
+
318
+ - Component classification (assets, third parties, etc.).
319
+ - Structural data-flow detection (who talks to which DB / third-party).
320
+
321
+ Additional patterns and refinements can be added in future tasks and should be
322
+ documented by extending this file.
@@ -0,0 +1,51 @@
1
+ ---
2
+ # Shared actor-detection config: regexes and rules to emit actor-related findings.
3
+ # This is language-agnostic; analyzers (TypeScript, Python, etc.) can all load it.
4
+ #
5
+ # The classifier maps patternIds like web_actor / service_actor → type: actor and
6
+ # coarse subTypes (e.g. customer, employee) via classifier/components.classifier.yaml.
7
+ # This file focuses on *where* we see actors in code and which properties to attach.
8
+
9
+ regexes:
10
+ # Frontend: Next.js/React session hook file
11
+ ts_frontend_session_hook_file: "hooks/useSession\\.tsx?$"
12
+
13
+ # Backend: NestJS / Express controllers using req.user
14
+ ts_backend_req_user: "\\breq\\.user\\b"
15
+
16
+ # Backend: simple admin role checks
17
+ ts_role_admin: "\\b(isAdmin|is_admin)\\b|\\brole[s]?\\s*[:=]\\s*['\"]admin['\"]"
18
+
19
+ rules:
20
+ # Frontend web customer: useSession hook representing logged-in customer user
21
+ - id: web_actor_frontend_session
22
+ patternId: web_actor
23
+ name: Customer
24
+ file_path_regex: ts_frontend_session_hook_file
25
+ confidence: 0.9
26
+ properties:
27
+ actorType: customer
28
+ sourceContext: frontend_session
29
+
30
+ # Backend web customer: controllers using req.user (authenticated user context)
31
+ - id: web_actor_backend_req_user
32
+ patternId: web_actor
33
+ name: Customer
34
+ content_regex: ts_backend_req_user
35
+ confidence: 0.85
36
+ properties:
37
+ actorType: customer
38
+ sourceContext: backend_controller
39
+
40
+ # Backend admin employee: admin checks around user/role handling
41
+ - id: service_actor_admin_employee
42
+ patternId: service_actor
43
+ name: Admin user
44
+ content_regex: ts_role_admin
45
+ confidence: 0.8
46
+ properties:
47
+ actorType: employee
48
+ roleNames:
49
+ - admin
50
+ sourceContext: backend_role_check
51
+