@commandgarden/cli 1.2.3 → 1.3.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.
Files changed (51) hide show
  1. package/dist/main.js +8907 -8895
  2. package/node_modules/@commandgarden/app/dist/client/assets/index-B-_w54e9.css +1 -0
  3. package/node_modules/@commandgarden/app/dist/client/assets/index-Bb1BOK1E.js +252 -0
  4. package/node_modules/@commandgarden/app/dist/client/index.html +19 -19
  5. package/node_modules/@commandgarden/app/dist/server/daemon-client.test.js +47 -0
  6. package/node_modules/@commandgarden/app/dist/server/main.d.ts +1 -0
  7. package/node_modules/@commandgarden/app/dist/server/main.js +3 -3
  8. package/node_modules/@commandgarden/app/dist/server/routes/audit.d.ts +3 -0
  9. package/node_modules/@commandgarden/app/dist/server/routes/config.d.ts +3 -0
  10. package/node_modules/@commandgarden/app/dist/server/routes/connectors.d.ts +3 -0
  11. package/node_modules/@commandgarden/app/dist/server/routes/goals.d.ts +3 -0
  12. package/node_modules/@commandgarden/app/dist/server/routes/goals.js +31 -0
  13. package/node_modules/@commandgarden/app/dist/server/routes/index.d.ts +4 -0
  14. package/node_modules/@commandgarden/app/dist/server/routes/index.js +4 -0
  15. package/node_modules/@commandgarden/app/dist/server/routes/preferences.d.ts +3 -0
  16. package/node_modules/@commandgarden/app/dist/server/routes/routes.test.js +137 -0
  17. package/node_modules/@commandgarden/app/dist/server/routes/run.d.ts +3 -0
  18. package/node_modules/@commandgarden/app/dist/server/routes/status.d.ts +3 -0
  19. package/node_modules/@commandgarden/app/dist/server/routes/timetracking-cache.d.ts +3 -0
  20. package/node_modules/@commandgarden/app/dist/server/routes/timetracking-cache.js +35 -0
  21. package/node_modules/@commandgarden/app/dist/server/store.d.ts +47 -0
  22. package/node_modules/@commandgarden/app/dist/server/store.js +112 -10
  23. package/node_modules/@commandgarden/app/dist/server/store.test.js +59 -0
  24. package/node_modules/@commandgarden/app/package.json +42 -41
  25. package/node_modules/@commandgarden/daemon/connectors/lib/msal-token.js +20 -0
  26. package/node_modules/@commandgarden/daemon/connectors/teams-room-availability.eval.js +341 -338
  27. package/node_modules/@commandgarden/daemon/connectors/teams-room-availability.yaml +46 -45
  28. package/node_modules/@commandgarden/daemon/connectors/timetracking-projects.eval.js +52 -0
  29. package/node_modules/@commandgarden/daemon/connectors/timetracking-projects.yaml +42 -0
  30. package/node_modules/@commandgarden/daemon/connectors/timetracking-report.eval.js +81 -60
  31. package/node_modules/@commandgarden/daemon/connectors/timetracking-report.yaml +52 -48
  32. package/node_modules/@commandgarden/daemon/dist/audit-store.js +8 -8
  33. package/node_modules/@commandgarden/daemon/dist/cdp-client.d.ts +24 -0
  34. package/node_modules/@commandgarden/daemon/dist/cdp-client.d.ts.map +1 -0
  35. package/node_modules/@commandgarden/daemon/dist/cdp-client.js +150 -0
  36. package/node_modules/@commandgarden/daemon/dist/cdp-client.js.map +1 -0
  37. package/node_modules/@commandgarden/daemon/dist/config.js +1 -1
  38. package/node_modules/@commandgarden/daemon/dist/config.js.map +1 -1
  39. package/node_modules/@commandgarden/daemon/package.json +30 -30
  40. package/node_modules/@commandgarden/shared/dist/daemon-client.d.ts +19 -0
  41. package/node_modules/@commandgarden/shared/dist/daemon-client.d.ts.map +1 -0
  42. package/node_modules/@commandgarden/shared/dist/daemon-client.js +129 -0
  43. package/node_modules/@commandgarden/shared/dist/daemon-client.js.map +1 -0
  44. package/node_modules/@commandgarden/shared/dist/index.d.ts +1 -0
  45. package/node_modules/@commandgarden/shared/dist/index.d.ts.map +1 -1
  46. package/node_modules/@commandgarden/shared/dist/index.js +2 -0
  47. package/node_modules/@commandgarden/shared/dist/index.js.map +1 -1
  48. package/node_modules/@commandgarden/shared/package.json +32 -32
  49. package/package.json +55 -55
  50. package/node_modules/@commandgarden/app/dist/client/assets/index-58UrF1aG.js +0 -197
  51. package/node_modules/@commandgarden/app/dist/client/assets/index-DErcb2Kp.css +0 -1
@@ -1,45 +1,46 @@
1
- site: teams
2
- name: room-availability
3
- version: "1.0"
4
- description: "Meeting-room free/busy timeline for one room on a given day (Teams/Outlook calendar)"
5
- access: read
6
-
7
- domains:
8
- - "outlook.cloud.microsoft.mcas.ms"
9
- capabilities:
10
- - navigate
11
- - js_evaluate
12
-
13
- args:
14
- - name: room
15
- type: string
16
- required: true
17
- help: "Room name or mailbox email (e.g. 'MBTMY The Vista' or 'RES-RERE-M6VJ7ZUW@mercedes-benz.com')"
18
- - name: date
19
- type: string
20
- required: false
21
- help: "Day to check in YYYY-MM-DD format (default: today)"
22
- pattern: "^\\d{4}-\\d{2}-\\d{2}$"
23
-
24
- columns:
25
- - name: room
26
- type: string
27
- - name: date
28
- type: string
29
- - name: state
30
- type: string
31
- - name: start
32
- type: string
33
- - name: end
34
- type: string
35
- - name: durationMin
36
- type: number
37
-
38
- pipeline:
39
- - step: navigate
40
- url: "https://outlook.cloud.microsoft.mcas.ms/calendar/deeplink/compose"
41
- - step: wait
42
- selector: "body"
43
- timeout: 30000
44
- - step: js_evaluate
45
- file: teams-room-availability.eval.js
1
+ site: teams
2
+ name: room-availability
3
+ version: "1.0"
4
+ description: "Meeting-room free/busy timeline for one room on a given day (Teams/Outlook calendar)"
5
+ access: read
6
+
7
+ domains:
8
+ - "outlook.cloud.microsoft.mcas.ms"
9
+ capabilities:
10
+ - navigate
11
+ - js_evaluate
12
+
13
+ args:
14
+ - name: room
15
+ type: string
16
+ required: true
17
+ help: "Room name or mailbox email (e.g. 'MBTMY The Vista' or 'RES-RERE-M6VJ7ZUW@mercedes-benz.com')"
18
+ - name: date
19
+ type: string
20
+ required: false
21
+ help: "Day to check in YYYY-MM-DD format (default: today)"
22
+ pattern: "^\\d{4}-\\d{2}-\\d{2}$"
23
+
24
+ columns:
25
+ - name: room
26
+ type: string
27
+ - name: date
28
+ type: string
29
+ - name: state
30
+ type: string
31
+ - name: start
32
+ type: string
33
+ - name: end
34
+ type: string
35
+ - name: durationMin
36
+ type: number
37
+
38
+ pipeline:
39
+ - step: navigate
40
+ url: "https://outlook.cloud.microsoft.mcas.ms/calendar/deeplink/compose"
41
+ - step: wait
42
+ selector: "body"
43
+ timeout: 30000
44
+ - step: js_evaluate
45
+ file: teams-room-availability.eval.js
46
+
@@ -0,0 +1,52 @@
1
+ // Runs in page context via js_evaluate step.
2
+ // Fetches the Projects API to list all available projects and activities.
3
+ //
4
+ // Template variables interpolated before execution:
5
+ // ${{ args.month | default("") }}
6
+
7
+ // Poll for MSAL token (handles SSO redirects + MFA)
8
+ // Canonical source: connectors/lib/msal-token.js
9
+ const __deadline = Date.now() + 60000;
10
+ let token;
11
+ while (Date.now() < __deadline) {
12
+ const k = Object.keys(sessionStorage).find(x => x.includes('accesstoken'));
13
+ if (k) {
14
+ try {
15
+ const tokenData = JSON.parse(sessionStorage.getItem(k));
16
+ if (Number(tokenData.expiresOn) > Math.floor(Date.now() / 1000) + 30) {
17
+ token = tokenData.secret;
18
+ break;
19
+ }
20
+ } catch (_) {}
21
+ }
22
+ await new Promise(r => setTimeout(r, 1000));
23
+ }
24
+ if (!token) throw new Error('No valid MSAL access token after 60s — log in and retry');
25
+
26
+ let month = '${{ args.month | default("") }}';
27
+ if (!month) {
28
+ const now = new Date();
29
+ month = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
30
+ }
31
+
32
+ const resp = await fetch(
33
+ 'https://mbti-bam-wzde-prd-ejdchtb0g9afexhr.a01.azurefd.net/api/Projects?date=' + month + '-01',
34
+ { headers: { Authorization: 'Bearer ' + token, Accept: 'application/json' } }
35
+ );
36
+ if (!resp.ok) throw new Error('Projects API returned HTTP ' + resp.status);
37
+
38
+ const projects = await resp.json();
39
+ const rows = [];
40
+ for (const p of projects) {
41
+ for (const act of p.activities || []) {
42
+ rows.push({
43
+ projectId: p.mserp_projectid || null,
44
+ projectName: p.mserp_projectname || null,
45
+ activityNumber: act.mserp_activitynumber || null,
46
+ activityName: act.mserp_description || null,
47
+ category: act.mserp_category || null,
48
+ linePropertyId: act.mserp_linepropertyid || null,
49
+ });
50
+ }
51
+ }
52
+ return rows;
@@ -0,0 +1,42 @@
1
+ site: timetracking
2
+ name: projects
3
+ version: "1.0"
4
+ description: "List all available projects and activities for the current user"
5
+ access: read
6
+
7
+ domains:
8
+ - "timetracking.mercedes-benz-techinnovation.com"
9
+ - "mbti-bam-wzde-prd-ejdchtb0g9afexhr.a01.azurefd.net"
10
+ capabilities:
11
+ - navigate
12
+ - js_evaluate
13
+
14
+ args:
15
+ - name: month
16
+ type: string
17
+ required: false
18
+ help: "Month in YYYY-MM format (default: current month)"
19
+ pattern: "^\\d{4}-\\d{2}$"
20
+
21
+ columns:
22
+ - name: projectId
23
+ type: string
24
+ - name: projectName
25
+ type: string
26
+ - name: activityNumber
27
+ type: string
28
+ - name: activityName
29
+ type: string
30
+ - name: category
31
+ type: string
32
+ - name: linePropertyId
33
+ type: string
34
+
35
+ pipeline:
36
+ - step: navigate
37
+ url: "https://timetracking.mercedes-benz-techinnovation.com/"
38
+ - step: wait
39
+ selector: "body"
40
+ timeout: 10000
41
+ - step: js_evaluate
42
+ file: timetracking-projects.eval.js
@@ -1,60 +1,81 @@
1
- // Runs in page context via js_evaluate step.
2
- // Reads the MSAL access token from sessionStorage, fetches the ReportFAK API,
3
- // and flattens day objects into one row per booking line.
4
- //
5
- // SSO/MFA: polls sessionStorage for up to 60s, giving the user time to
6
- // complete login and get redirected back to the app.
7
- //
8
- // Template variables interpolated before execution:
9
- // ${{ args.month | default("") }}
10
-
11
- // Poll for MSAL token (handles SSO redirects + MFA)
12
- const __deadline = Date.now() + 60000;
13
- let token;
14
- while (Date.now() < __deadline) {
15
- const k = Object.keys(sessionStorage).find(x => x.includes('accesstoken'));
16
- if (k) {
17
- try {
18
- const tokenData = JSON.parse(sessionStorage.getItem(k));
19
- if (Number(tokenData.expiresOn) > Math.floor(Date.now() / 1000) + 30) {
20
- token = tokenData.secret;
21
- break;
22
- }
23
- } catch (_) {}
24
- }
25
- await new Promise(r => setTimeout(r, 1000));
26
- }
27
- if (!token) throw new Error('No valid MSAL access token after 60s — log in and retry');
28
-
29
- let month = '${{ args.month | default("") }}';
30
- if (!month) {
31
- const now = new Date();
32
- month = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
33
- }
34
-
35
- const resp = await fetch(
36
- 'https://mbti-bam-wzde-prd-ejdchtb0g9afexhr.a01.azurefd.net/api/ReportFAK?date=' + month + '-01',
37
- { headers: { Authorization: 'Bearer ' + token, Accept: 'application/json' } }
38
- );
39
- if (!resp.ok) throw new Error('ReportFAK returned HTTP ' + resp.status);
40
-
41
- const days = await resp.json();
42
- const rows = [];
43
- for (const day of days) {
44
- const header = day.calendarHeader || {};
45
- const dayDate = (day.date || '').slice(0, 10);
46
- for (const line of day.calendarLines || []) {
47
- rows.push({
48
- month: month,
49
- date: dayDate,
50
- projectId: line.mserp_projectid || null,
51
- category: line.mserp_category || null,
52
- activity: line.mserp_activitynumber || null,
53
- hours: typeof line.mserp_hours === 'number' ? line.mserp_hours : null,
54
- status: header.status || null,
55
- journalId: line.mserp_journalid || null,
56
- lineNumber: typeof line.mserp_linenumber === 'number' ? line.mserp_linenumber : null,
57
- });
58
- }
59
- }
60
- return rows;
1
+ // Runs in page context via js_evaluate step.
2
+ // Reads the MSAL access token from sessionStorage, fetches the ReportFAK API,
3
+ // and flattens day objects into one row per booking line.
4
+ //
5
+ // SSO/MFA: polls sessionStorage for up to 60s, giving the user time to
6
+ // complete login and get redirected back to the app.
7
+ //
8
+ // Template variables interpolated before execution:
9
+ // ${{ args.month | default("") }}
10
+
11
+ // Poll for MSAL token (handles SSO redirects + MFA)
12
+ // Canonical source: connectors/lib/msal-token.js
13
+ const __deadline = Date.now() + 60000;
14
+ let token;
15
+ while (Date.now() < __deadline) {
16
+ const k = Object.keys(sessionStorage).find(x => x.includes('accesstoken'));
17
+ if (k) {
18
+ try {
19
+ const tokenData = JSON.parse(sessionStorage.getItem(k));
20
+ if (Number(tokenData.expiresOn) > Math.floor(Date.now() / 1000) + 30) {
21
+ token = tokenData.secret;
22
+ break;
23
+ }
24
+ } catch (_) {}
25
+ }
26
+ await new Promise(r => setTimeout(r, 1000));
27
+ }
28
+ if (!token) throw new Error('No valid MSAL access token after 60s — log in and retry');
29
+
30
+ let month = '${{ args.month | default("") }}';
31
+ if (!month) {
32
+ const now = new Date();
33
+ month = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
34
+ }
35
+
36
+ const apiBase = 'https://mbti-bam-wzde-prd-ejdchtb0g9afexhr.a01.azurefd.net/api/';
37
+ const authHeaders = { Authorization: 'Bearer ' + token, Accept: 'application/json' };
38
+
39
+ const [resp, projResp] = await Promise.all([
40
+ fetch(apiBase + 'ReportFAK?date=' + month + '-01', { headers: authHeaders }),
41
+ fetch(apiBase + 'Projects?date=' + month + '-01', { headers: authHeaders }).catch(() => null),
42
+ ]);
43
+ if (!resp.ok) throw new Error('ReportFAK returned HTTP ' + resp.status);
44
+
45
+ const projectNames = new Map();
46
+ const activityNames = new Map(); // key: "projectId\0activityNumber" description
47
+ if (projResp && projResp.ok) {
48
+ for (const p of await projResp.json()) {
49
+ projectNames.set(p.mserp_projectid, p.mserp_projectname);
50
+ for (const act of p.activities || []) {
51
+ if (act.mserp_activitynumber && act.mserp_description) {
52
+ activityNames.set(act.mserp_projectid + '\0' + act.mserp_activitynumber, act.mserp_description);
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ const days = await resp.json();
59
+ const rows = [];
60
+ for (const day of days) {
61
+ const header = day.calendarHeader || {};
62
+ const dayDate = (day.date || '').slice(0, 10);
63
+ for (const line of day.calendarLines || []) {
64
+ const pid = line.mserp_projectid || null;
65
+ const actNum = line.mserp_activitynumber || null;
66
+ rows.push({
67
+ month: month,
68
+ date: dayDate,
69
+ projectId: pid,
70
+ projectName: projectNames.get(pid) || null,
71
+ category: line.mserp_category || null,
72
+ activity: actNum,
73
+ activityName: (pid && actNum) ? (activityNames.get(pid + '\0' + actNum) || null) : null,
74
+ hours: typeof line.mserp_hours === 'number' ? line.mserp_hours : null,
75
+ status: header.status || null,
76
+ journalId: line.mserp_journalid || null,
77
+ lineNumber: typeof line.mserp_linenumber === 'number' ? line.mserp_linenumber : null,
78
+ });
79
+ }
80
+ }
81
+ return rows;
@@ -1,48 +1,52 @@
1
- site: timetracking
2
- name: report
3
- version: "1.0"
4
- description: "MBTI Time Tracking monthly report — one row per booking line"
5
- access: read
6
-
7
- domains:
8
- - "timetracking.mercedes-benz-techinnovation.com"
9
- - "mbti-bam-wzde-prd-ejdchtb0g9afexhr.a01.azurefd.net"
10
- capabilities:
11
- - navigate
12
- - js_evaluate
13
-
14
- args:
15
- - name: month
16
- type: string
17
- required: false
18
- help: "Month in YYYY-MM format (default: current month)"
19
- pattern: "^\\d{4}-\\d{2}$"
20
-
21
- columns:
22
- - name: month
23
- type: string
24
- - name: date
25
- type: string
26
- - name: projectId
27
- type: string
28
- - name: category
29
- type: string
30
- - name: activity
31
- type: string
32
- - name: hours
33
- type: number
34
- - name: status
35
- type: string
36
- - name: journalId
37
- type: string
38
- - name: lineNumber
39
- type: number
40
-
41
- pipeline:
42
- - step: navigate
43
- url: "https://timetracking.mercedes-benz-techinnovation.com/"
44
- - step: wait
45
- selector: "body"
46
- timeout: 10000
47
- - step: js_evaluate
48
- file: timetracking-report.eval.js
1
+ site: timetracking
2
+ name: report
3
+ version: "1.0"
4
+ description: "MBTI Time Tracking monthly report — one row per booking line"
5
+ access: read
6
+
7
+ domains:
8
+ - "timetracking.mercedes-benz-techinnovation.com"
9
+ - "mbti-bam-wzde-prd-ejdchtb0g9afexhr.a01.azurefd.net"
10
+ capabilities:
11
+ - navigate
12
+ - js_evaluate
13
+
14
+ args:
15
+ - name: month
16
+ type: string
17
+ required: false
18
+ help: "Month in YYYY-MM format (default: current month)"
19
+ pattern: "^\\d{4}-\\d{2}$"
20
+
21
+ columns:
22
+ - name: month
23
+ type: string
24
+ - name: date
25
+ type: string
26
+ - name: projectId
27
+ type: string
28
+ - name: projectName
29
+ type: string
30
+ - name: category
31
+ type: string
32
+ - name: activity
33
+ type: string
34
+ - name: activityName
35
+ type: string
36
+ - name: hours
37
+ type: number
38
+ - name: status
39
+ type: string
40
+ - name: journalId
41
+ type: string
42
+ - name: lineNumber
43
+ type: number
44
+
45
+ pipeline:
46
+ - step: navigate
47
+ url: "https://timetracking.mercedes-benz-techinnovation.com/"
48
+ - step: wait
49
+ selector: "body"
50
+ timeout: 10000
51
+ - step: js_evaluate
52
+ file: timetracking-report.eval.js
@@ -19,11 +19,11 @@ export class AuditStore {
19
19
  else {
20
20
  db = new SQL.Database();
21
21
  }
22
- db.run(`CREATE TABLE IF NOT EXISTS audit_events (
23
- id TEXT PRIMARY KEY, timestamp TEXT NOT NULL, type TEXT NOT NULL,
24
- user TEXT NOT NULL, connector TEXT NOT NULL, args TEXT NOT NULL,
25
- domains TEXT NOT NULL, capabilities TEXT NOT NULL, row_count INTEGER,
26
- columns TEXT, duration_ms INTEGER NOT NULL, error TEXT, denial_reason TEXT
22
+ db.run(`CREATE TABLE IF NOT EXISTS audit_events (
23
+ id TEXT PRIMARY KEY, timestamp TEXT NOT NULL, type TEXT NOT NULL,
24
+ user TEXT NOT NULL, connector TEXT NOT NULL, args TEXT NOT NULL,
25
+ domains TEXT NOT NULL, capabilities TEXT NOT NULL, row_count INTEGER,
26
+ columns TEXT, duration_ms INTEGER NOT NULL, error TEXT, denial_reason TEXT
27
27
  )`);
28
28
  const store = new AuditStore(db, dbPath);
29
29
  store.migrate();
@@ -77,9 +77,9 @@ export class AuditStore {
77
77
  }
78
78
  }
79
79
  insert(event) {
80
- this.db.run(`INSERT INTO audit_events (id, timestamp, type, user, connector, args, domains,
81
- capabilities, row_count, columns, duration_ms, error, denial_reason,
82
- correlation_id, connector_hash, steps, source, previous_value, new_value)
80
+ this.db.run(`INSERT INTO audit_events (id, timestamp, type, user, connector, args, domains,
81
+ capabilities, row_count, columns, duration_ms, error, denial_reason,
82
+ correlation_id, connector_hash, steps, source, previous_value, new_value)
83
83
  VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, [
84
84
  event.id, event.timestamp, event.type, event.user, event.connector,
85
85
  JSON.stringify(event.args), JSON.stringify(event.domains),
@@ -0,0 +1,24 @@
1
+ export declare class CdpClient {
2
+ private port;
3
+ private ws;
4
+ private msgId;
5
+ private pending;
6
+ private sessionIds;
7
+ constructor(port: number);
8
+ /** Connect to Chrome's browser-level CDP endpoint. */
9
+ connect(): Promise<void>;
10
+ /** Send a CDP command to the browser target. */
11
+ private send;
12
+ /** Send a CDP command to a specific session (tab). */
13
+ private sendToSession;
14
+ /**
15
+ * Enable Network domain on all matching tabs and future tabs.
16
+ * Uses Target.setAutoAttach to automatically attach to new targets
17
+ * (tabs created by the extension) and enable Network on them.
18
+ */
19
+ enableNetworkCapture(urlPattern?: string): Promise<void>;
20
+ /** Disconnect from CDP. */
21
+ disconnect(): void;
22
+ get connected(): boolean;
23
+ }
24
+ //# sourceMappingURL=cdp-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdp-client.d.ts","sourceRoot":"","sources":["../src/cdp-client.ts"],"names":[],"mappings":"AA6BA,qBAAa,SAAS;IAMR,OAAO,CAAC,IAAI;IALxB,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,OAAO,CAAoF;IACnG,OAAO,CAAC,UAAU,CAAqB;gBAEnB,IAAI,EAAE,MAAM;IAEhC,sDAAsD;IAChD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkD9B,gDAAgD;IAChD,OAAO,CAAC,IAAI;IAgBZ,sDAAsD;IACtD,OAAO,CAAC,aAAa;IAgBrB;;;;OAIG;IACG,oBAAoB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9D,2BAA2B;IAC3B,UAAU,IAAI,IAAI;IAYlB,IAAI,SAAS,IAAI,OAAO,CAA6B;CACtD"}
@@ -0,0 +1,150 @@
1
+ // src/cdp-client.ts
2
+ //
3
+ // Lightweight CDP (Chrome DevTools Protocol) client that connects to Chrome's
4
+ // --remote-debugging-port and calls Network.enable on target tabs. This forces
5
+ // Chrome to route Service Worker-handled requests through the observable path,
6
+ // making them visible to window.fetch interceptors in the page context.
7
+ //
8
+ // Without Network.enable, OWA's getSchedule GraphQL call goes through the
9
+ // Service Worker's internal fetch — invisible to any page-level interception.
10
+ import { WebSocket } from 'ws';
11
+ export class CdpClient {
12
+ port;
13
+ ws = null;
14
+ msgId = 0;
15
+ pending = new Map();
16
+ sessionIds = new Set();
17
+ constructor(port) {
18
+ this.port = port;
19
+ }
20
+ /** Connect to Chrome's browser-level CDP endpoint. */
21
+ async connect() {
22
+ const versionUrl = `http://127.0.0.1:${this.port}/json/version`;
23
+ const resp = await fetch(versionUrl);
24
+ if (!resp.ok)
25
+ throw new Error(`CDP version endpoint returned ${resp.status}`);
26
+ const info = await resp.json();
27
+ const wsUrl = info.webSocketDebuggerUrl;
28
+ if (!wsUrl)
29
+ throw new Error('No webSocketDebuggerUrl in CDP version response');
30
+ return new Promise((resolve, reject) => {
31
+ const ws = new WebSocket(wsUrl);
32
+ const timeout = setTimeout(() => {
33
+ ws.close();
34
+ reject(new Error('CDP WebSocket connection timed out'));
35
+ }, 5000);
36
+ ws.on('open', () => {
37
+ clearTimeout(timeout);
38
+ this.ws = ws;
39
+ resolve();
40
+ });
41
+ ws.on('error', (err) => {
42
+ clearTimeout(timeout);
43
+ reject(new Error(`CDP WebSocket error: ${err.message}`));
44
+ });
45
+ ws.on('message', (data) => {
46
+ try {
47
+ const msg = JSON.parse(String(data));
48
+ // Handle responses to our commands
49
+ if (msg.id !== undefined) {
50
+ const entry = this.pending.get(msg.id);
51
+ if (entry) {
52
+ this.pending.delete(msg.id);
53
+ if (msg.error)
54
+ entry.reject(new Error(msg.error.message));
55
+ else
56
+ entry.resolve(msg.result);
57
+ }
58
+ }
59
+ // Handle Target.attachedToTarget — auto-enable Network on new sessions
60
+ if (msg.method === 'Target.attachedToTarget' && msg.params) {
61
+ const sessionId = msg.params.sessionId;
62
+ if (sessionId) {
63
+ this.sessionIds.add(sessionId);
64
+ this.sendToSession(sessionId, 'Network.enable', {}).catch(() => { });
65
+ }
66
+ }
67
+ }
68
+ catch { /* ignore parse errors */ }
69
+ });
70
+ ws.on('close', () => { this.ws = null; });
71
+ });
72
+ }
73
+ /** Send a CDP command to the browser target. */
74
+ send(method, params = {}) {
75
+ if (!this.ws)
76
+ return Promise.reject(new Error('CDP not connected'));
77
+ const id = ++this.msgId;
78
+ return new Promise((resolve, reject) => {
79
+ const timer = setTimeout(() => {
80
+ this.pending.delete(id);
81
+ reject(new Error(`CDP command ${method} timed out`));
82
+ }, 10000);
83
+ this.pending.set(id, {
84
+ resolve: (r) => { clearTimeout(timer); resolve(r); },
85
+ reject: (e) => { clearTimeout(timer); reject(e); },
86
+ });
87
+ this.ws.send(JSON.stringify({ id, method, params }));
88
+ });
89
+ }
90
+ /** Send a CDP command to a specific session (tab). */
91
+ sendToSession(sessionId, method, params = {}) {
92
+ if (!this.ws)
93
+ return Promise.reject(new Error('CDP not connected'));
94
+ const id = ++this.msgId;
95
+ return new Promise((resolve, reject) => {
96
+ const timer = setTimeout(() => {
97
+ this.pending.delete(id);
98
+ reject(new Error(`CDP command ${method} timed out`));
99
+ }, 10000);
100
+ this.pending.set(id, {
101
+ resolve: (r) => { clearTimeout(timer); resolve(r); },
102
+ reject: (e) => { clearTimeout(timer); reject(e); },
103
+ });
104
+ this.ws.send(JSON.stringify({ id, method, params, sessionId }));
105
+ });
106
+ }
107
+ /**
108
+ * Enable Network domain on all matching tabs and future tabs.
109
+ * Uses Target.setAutoAttach to automatically attach to new targets
110
+ * (tabs created by the extension) and enable Network on them.
111
+ */
112
+ async enableNetworkCapture(urlPattern) {
113
+ // Auto-attach to existing and new targets
114
+ await this.send('Target.setAutoAttach', {
115
+ autoAttach: true,
116
+ waitForDebuggerOnStart: false,
117
+ flatten: true,
118
+ filter: [{ type: 'page' }],
119
+ });
120
+ // Also manually attach to existing tabs matching the URL pattern
121
+ if (urlPattern) {
122
+ const resp = await fetch(`http://127.0.0.1:${this.port}/json`);
123
+ if (resp.ok) {
124
+ const targets = await resp.json();
125
+ for (const t of targets) {
126
+ if (t.type === 'page' && t.url.includes(urlPattern)) {
127
+ try {
128
+ await this.send('Target.attachToTarget', { targetId: t.id, flatten: true });
129
+ }
130
+ catch { /* may already be attached */ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
136
+ /** Disconnect from CDP. */
137
+ disconnect() {
138
+ this.sessionIds.clear();
139
+ for (const [, entry] of this.pending) {
140
+ entry.reject(new Error('CDP disconnected'));
141
+ }
142
+ this.pending.clear();
143
+ if (this.ws) {
144
+ this.ws.close();
145
+ this.ws = null;
146
+ }
147
+ }
148
+ get connected() { return this.ws !== null; }
149
+ }
150
+ //# sourceMappingURL=cdp-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdp-client.js","sourceRoot":"","sources":["../src/cdp-client.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,wEAAwE;AACxE,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAE9E,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAmB/B,MAAM,OAAO,SAAS;IAMA;IALZ,EAAE,GAAqB,IAAI,CAAC;IAC5B,KAAK,GAAG,CAAC,CAAC;IACV,OAAO,GAAG,IAAI,GAAG,EAAyE,CAAC;IAC3F,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IAEvC,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAEpC,sDAAsD;IACtD,KAAK,CAAC,OAAO;QACX,MAAM,UAAU,GAAG,oBAAoB,IAAI,CAAC,IAAI,eAAe,CAAC;QAChE,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,C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K,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;wBACpD,IAAI,CAAC;4BACH,MAAM,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;wBAC9E,CAAC;wBAAC,MAAM,CAAC,CAAC,6BAA6B,CAAC,CAAC;oBAC3C,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,2BAA2B;IAC3B,UAAU;QACR,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACrC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;IAED,IAAI,SAAS,KAAc,OAAO,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC;CACtD"}
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url';
8
8
  const BUNDLED_CONNECTORS_DIR = join(dirname(fileURLToPath(import.meta.url)), '../connectors');
9
9
  export const configSchema = z.object({
10
10
  daemon: z.object({
11
- port: z.number().int().min(1024).max(65535).default(19825),
11
+ port: z.number().int().min(1024).max(65535).default(9091),
12
12
  host: z.string().default('127.0.0.1'),
13
13
  }).default({}),
14
14
  security: z.object({