@velaro/cli 1.4.240 → 1.4.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/velaro.js +360 -370
- package/lib/commands/article.js +772 -763
- package/lib/commands/billing-subscription.js +909 -907
- package/lib/commands/index.js +259 -322
- package/lib/commands/ingest.js +36 -32
- package/lib/commands/mcp-key.js +218 -209
- package/lib/confirm.js +14 -0
- package/package.json +40 -45
- package/assets/billing-doc-patterns/concentric-arcs.png +0 -0
- package/assets/billing-doc-patterns/diagonal-hatch.png +0 -0
- package/assets/billing-doc-patterns/dot-grid.png +0 -0
- package/assets/billing-doc-patterns/hex-grid.png +0 -0
- package/assets/billing-doc-patterns/wave-lines.png +0 -0
- package/assets/velaro-logo-lockup-full-color.png +0 -0
- package/lib/commands/db.js +0 -105
- package/lib/commands/deploy-state.js +0 -26
- package/lib/commands/deployment.js +0 -107
- package/lib/commands/schedule-adherence.js +0 -33
- package/lib/commands/sharepoint.js +0 -168
- package/lib/deploy-state.js +0 -408
- package/lib/deploy-state.test.js +0 -133
- package/lib/kb-screenshot.js +0 -433
- package/lib/migrations/amscro.json +0 -72
- package/lib/migrations/azenta.json +0 -68
- package/lib/migrations/bluefire.json +0 -49
- package/lib/migrations/donaldson.json +0 -75
- package/lib/pdf/billing-document.js +0 -534
- package/lib/pdf/billing-document.test.js +0 -349
- package/lib/sharepoint-auth.js +0 -138
package/lib/commands/db.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { runCommand } from '../run.js';
|
|
2
|
-
|
|
3
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
4
|
-
// Direct database query tool — read-only by default.
|
|
5
|
-
//
|
|
6
|
-
// Built 2026-08-17 after a session burned significant time trying to answer
|
|
7
|
-
// one question ("did migration X actually apply to staging?") through the
|
|
8
|
-
// Azure Portal's browser-based Query Editor, which stopped responding to
|
|
9
|
-
// clicks under host memory pressure. This is the durable replacement: a
|
|
10
|
-
// scriptable, non-interactive way to run a SQL query against any of the
|
|
11
|
-
// named databases below, with connection strings sourced from Key Vault
|
|
12
|
-
// (never hardcoded) per this repo's KV-first secrets rule.
|
|
13
|
-
//
|
|
14
|
-
// SAFE BY DEFAULT: only SELECT statements are allowed unless --allow-write
|
|
15
|
-
// is passed explicitly. This tool is for diagnostics, not migrations —
|
|
16
|
-
// schema changes still go through `dotnet ef migrations add` per this
|
|
17
|
-
// repo's EF-migrations-are-the-source-of-truth rule.
|
|
18
|
-
// ────────────────────────────────────────────────────────────────────────────
|
|
19
|
-
|
|
20
|
-
// Maps a short --db name to the Key Vault secret holding its connection string.
|
|
21
|
-
// Add a new entry here (and set the secret in the vault) whenever a new
|
|
22
|
-
// database needs to be queryable this way — never hardcode a connection
|
|
23
|
-
// string in this file.
|
|
24
|
-
const DB_SECRETS = {
|
|
25
|
-
kb: {
|
|
26
|
-
staging: { vault: 'velaro-eastus-stg-kv', secret: 'KnowledgeBaseConnectionString-Staging' },
|
|
27
|
-
},
|
|
28
|
-
messaging: {
|
|
29
|
-
staging: { vault: 'velaro-eastus-stg-kv', secret: 'MessagingConnectionString-Staging' },
|
|
30
|
-
prod: { vault: 'velaro-eastus-prd-kv', secret: 'MessagingReadOnlyConnectionString' },
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
async function getConnectionString(dbName, env, connectionStringFile) {
|
|
35
|
-
if (connectionStringFile) {
|
|
36
|
-
const { readFileSync } = await import('fs');
|
|
37
|
-
return readFileSync(connectionStringFile, 'utf8').trim();
|
|
38
|
-
}
|
|
39
|
-
const entry = DB_SECRETS[dbName]?.[env];
|
|
40
|
-
if (!entry) {
|
|
41
|
-
const known = Object.entries(DB_SECRETS)
|
|
42
|
-
.flatMap(([db, envs]) => Object.keys(envs).map((e) => `${db}/${e}`))
|
|
43
|
-
.join(', ');
|
|
44
|
-
throw new Error(`No connection string registered for --db ${dbName} --env ${env}. Known: ${known}. Or pass --connection-string-file for a one-off ad-hoc connection (never commit that file).`);
|
|
45
|
-
}
|
|
46
|
-
const { SecretClient } = await import('@azure/keyvault-secrets');
|
|
47
|
-
const { DefaultAzureCredential } = await import('@azure/identity');
|
|
48
|
-
const client = new SecretClient(`https://${entry.vault}.vault.azure.net`, new DefaultAzureCredential());
|
|
49
|
-
const secret = await client.getSecret(entry.secret);
|
|
50
|
-
return secret.value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Conservative guard: block anything that isn't a plain read. This is a
|
|
54
|
-
// string check, not a real SQL parser — it exists to stop accidental writes
|
|
55
|
-
// from a mistyped query, not to be airtight against a determined bypass.
|
|
56
|
-
// Real write protection is the underlying SQL user's own grants.
|
|
57
|
-
function assertReadOnly(query) {
|
|
58
|
-
const normalized = query.trim().replace(/^\s*;+/, '').toUpperCase();
|
|
59
|
-
const writeVerbs = ['INSERT', 'UPDATE', 'DELETE', 'DROP', 'ALTER', 'TRUNCATE', 'EXEC', 'MERGE', 'CREATE'];
|
|
60
|
-
const firstWord = normalized.split(/\s+/)[0];
|
|
61
|
-
if (writeVerbs.includes(firstWord)) {
|
|
62
|
-
throw new Error(`Query looks like a write (${firstWord}) — pass --allow-write to run it, or use a proper EF migration for schema changes.`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const dbCommand = {
|
|
67
|
-
command: 'db <subcommand>',
|
|
68
|
-
describe: 'Run direct SQL queries against a named database (diagnostics only — read-only unless --allow-write)',
|
|
69
|
-
builder: (yargs) =>
|
|
70
|
-
yargs
|
|
71
|
-
.command({
|
|
72
|
-
command: 'query <sql>',
|
|
73
|
-
describe: 'Run a SQL query. Wrap the query in quotes.',
|
|
74
|
-
builder: (y) =>
|
|
75
|
-
y
|
|
76
|
-
.positional('sql', { type: 'string', describe: 'SQL query to run' })
|
|
77
|
-
.option('db', { type: 'string', describe: `Database name (${Object.keys(DB_SECRETS).join(', ')})` })
|
|
78
|
-
.option('env', { type: 'string', default: 'staging', choices: ['staging', 'prod'], describe: 'Environment' })
|
|
79
|
-
.option('connection-string-file', { type: 'string', describe: 'Path to a local file containing a raw connection string, for one-off ad-hoc queries not yet registered in Key Vault' })
|
|
80
|
-
.option('allow-write', { type: 'boolean', default: false, describe: 'Allow INSERT/UPDATE/DELETE/DDL statements' }),
|
|
81
|
-
handler: runCommand(async (argv) => {
|
|
82
|
-
if (!argv['allow-write']) assertReadOnly(argv.sql);
|
|
83
|
-
|
|
84
|
-
const sql = await import('mssql');
|
|
85
|
-
const connectionString = await getConnectionString(argv.db, argv.env, argv['connection-string-file']);
|
|
86
|
-
const pool = await sql.default.connect(connectionString);
|
|
87
|
-
try {
|
|
88
|
-
const result = await pool.request().query(argv.sql);
|
|
89
|
-
const rows = Array.isArray(result.recordset) ? result.recordset : [];
|
|
90
|
-
if (rows.length === 0) {
|
|
91
|
-
console.log(argv['allow-write']
|
|
92
|
-
? `Done. Rows affected: ${result.rowsAffected?.join(', ') ?? 0}`
|
|
93
|
-
: 'No rows returned.');
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
console.table(rows);
|
|
97
|
-
console.log(`\n${rows.length} row(s).`);
|
|
98
|
-
} finally {
|
|
99
|
-
await pool.close();
|
|
100
|
-
}
|
|
101
|
-
}),
|
|
102
|
-
})
|
|
103
|
-
.demandCommand(1, 'Specify: query'),
|
|
104
|
-
handler: () => {},
|
|
105
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { collectAll, render, PRODUCTS } from '../deploy-state.js';
|
|
2
|
-
|
|
3
|
-
// velaro deploy-state: what is on the staging environment, on staging slot 1 of production and in
|
|
4
|
-
// production for Admin and Messaging, what is merged to dev but not in production, which gate is
|
|
5
|
-
// waiting and the merge-freeze file. Uses only `gh` (logged in) and public /Version endpoints.
|
|
6
|
-
export const deployStateCommand = {
|
|
7
|
-
command: 'deploy-state',
|
|
8
|
-
describe: 'Where each push landed: staging environment, staging slot 1 of production, production (Velaro staff, needs gh)',
|
|
9
|
-
builder: (yargs) => yargs
|
|
10
|
-
.option('product', { type: 'string', choices: ['admin', 'messaging'], describe: 'Only one product (default both)' })
|
|
11
|
-
.option('json', { type: 'boolean', describe: 'Print the raw state as JSON' })
|
|
12
|
-
.option('compact', { type: 'boolean', describe: 'One line per place' }),
|
|
13
|
-
handler: async (argv) => {
|
|
14
|
-
try {
|
|
15
|
-
const products = argv.product
|
|
16
|
-
? [Object.keys(PRODUCTS).find((n) => n.toLowerCase() === argv.product)]
|
|
17
|
-
: undefined;
|
|
18
|
-
const state = await collectAll({ products });
|
|
19
|
-
console.log(argv.json ? JSON.stringify(state, null, 2) : render(state, { compact: !!argv.compact }));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
console.error(`deploy-state failed: ${e.message}`);
|
|
22
|
-
console.error('This command needs the GitHub CLI (gh) installed and logged in with access to velaro/velaro-admin and velaro/velaro-messaging. Run: gh auth login');
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { messagingGet as get, messagingPost as post } from '../api.js';
|
|
2
|
-
import { runCommand } from '../run.js';
|
|
3
|
-
|
|
4
|
-
export const deploymentCommand = {
|
|
5
|
-
command: 'deployment <subcommand>',
|
|
6
|
-
describe: 'Manage chat widget deployments',
|
|
7
|
-
builder: (yargs) =>
|
|
8
|
-
yargs
|
|
9
|
-
.command(deploymentListCommand)
|
|
10
|
-
.command(deploymentRenameCommand)
|
|
11
|
-
.command(deploymentAssignCommand)
|
|
12
|
-
.demandCommand(1, 'Specify a subcommand: list, rename, assign-team'),
|
|
13
|
-
handler: () => {},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// ── list ───────────────────────────────────────────────────────────────────────
|
|
17
|
-
|
|
18
|
-
const deploymentListCommand = {
|
|
19
|
-
command: 'list',
|
|
20
|
-
describe: 'List chat widget deployments',
|
|
21
|
-
handler: runCommand(async () => {
|
|
22
|
-
const [deployments, teams] = await Promise.all([
|
|
23
|
-
get('/Deployment'),
|
|
24
|
-
get('/Teams/List'),
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
if (!deployments?.length) {
|
|
28
|
-
console.log('No deployments found.');
|
|
29
|
-
console.log('\nA deployment is a chat widget embed — one per page or team you want to serve.');
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const teamMap = Object.fromEntries((teams ?? []).map(t => [t.id, t.name]));
|
|
34
|
-
|
|
35
|
-
const rows = deployments.map(d => ({
|
|
36
|
-
id: `[${d.id}]`,
|
|
37
|
-
key: d.deploymentId ?? '—',
|
|
38
|
-
team: teamMap[d.teamId] ?? `team ${d.teamId}`,
|
|
39
|
-
name: d.displayName ?? '(unnamed)',
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
const idW = Math.max(...rows.map(r => r.id.length));
|
|
43
|
-
const keyW = Math.max('embed-key'.length, ...rows.map(r => r.key.length));
|
|
44
|
-
const teamW = Math.max('team'.length, ...rows.map(r => r.team.length));
|
|
45
|
-
|
|
46
|
-
console.log(`\n${'id'.padStart(idW)} ${'embed-key'.padEnd(keyW)} ${'team'.padEnd(teamW)} name`);
|
|
47
|
-
console.log(`${'-'.repeat(idW)} ${'-'.repeat(keyW)} ${'-'.repeat(teamW)} ----`);
|
|
48
|
-
for (const r of rows) {
|
|
49
|
-
console.log(`${r.id.padStart(idW)} ${r.key.padEnd(keyW)} ${r.team.padEnd(teamW)} ${r.name}`);
|
|
50
|
-
}
|
|
51
|
-
console.log(`\n${rows.length} deployment(s)`);
|
|
52
|
-
console.log('\nThe embed-key goes in your widget JavaScript snippet.');
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// ── rename ─────────────────────────────────────────────────────────────────────
|
|
57
|
-
|
|
58
|
-
const deploymentRenameCommand = {
|
|
59
|
-
command: 'rename <id> <name>',
|
|
60
|
-
describe: 'Rename a deployment',
|
|
61
|
-
builder: (y) =>
|
|
62
|
-
y
|
|
63
|
-
.positional('id', { type: 'number', describe: 'Deployment numeric ID' })
|
|
64
|
-
.positional('name', { type: 'string', describe: 'New display name' }),
|
|
65
|
-
handler: runCommand(async (argv) => {
|
|
66
|
-
const dep = await get(`/Deployment/${argv.id}`);
|
|
67
|
-
if (!dep) {
|
|
68
|
-
console.error(`Deployment ${argv.id} not found.`);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
await post('/Deployment', { ...dep, id: argv.id, displayName: argv.name });
|
|
73
|
-
console.log(`Deployment ${argv.id} renamed to "${argv.name}".`);
|
|
74
|
-
}),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// ── assign-team ────────────────────────────────────────────────────────────────
|
|
78
|
-
|
|
79
|
-
const deploymentAssignCommand = {
|
|
80
|
-
command: 'assign-team <id> <team-id>',
|
|
81
|
-
describe: 'Assign a team to a deployment',
|
|
82
|
-
builder: (y) =>
|
|
83
|
-
y
|
|
84
|
-
.positional('id', { type: 'number', describe: 'Deployment numeric ID' })
|
|
85
|
-
.positional('team-id', { type: 'number', describe: 'Team ID to assign' }),
|
|
86
|
-
handler: runCommand(async (argv) => {
|
|
87
|
-
const [dep, teams] = await Promise.all([
|
|
88
|
-
get(`/Deployment/${argv.id}`),
|
|
89
|
-
get('/Teams/List'),
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
if (!dep) {
|
|
93
|
-
console.error(`Deployment ${argv.id} not found.`);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const team = (teams ?? []).find(t => t.id === argv['team-id']);
|
|
98
|
-
if (!team) {
|
|
99
|
-
console.error(`Team ${argv['team-id']} not found.`);
|
|
100
|
-
console.error('Run: velaro team list');
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
await post('/Deployment', { ...dep, id: argv.id, teamId: argv['team-id'] });
|
|
105
|
-
console.log(`Deployment ${argv.id} ("${dep.displayName}") assigned to team "${team.name}".`);
|
|
106
|
-
}),
|
|
107
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { messagingGet } from '../api.js';
|
|
2
|
-
import { runCommand } from '../run.js';
|
|
3
|
-
|
|
4
|
-
// -- velaro schedule-adherence --------------------------------------------------
|
|
5
|
-
// Staff-only. siteId is an EXPLICIT argument (SupportTools-style), never derived from the caller.
|
|
6
|
-
// Backend: velaro-messaging GET /Reports/sites/{siteId}/schedule-adherence-diagnostics
|
|
7
|
-
// (server-side staff gate; role=agent requires agentId, fails closed).
|
|
8
|
-
|
|
9
|
-
export const scheduleAdherenceCommand = {
|
|
10
|
-
command: 'schedule-adherence <siteId>',
|
|
11
|
-
describe: 'Staff: schedule adherence overview/breakdown/intraday/timeline for a site as manager or agent',
|
|
12
|
-
builder: (y) => y
|
|
13
|
-
.positional('siteId', { type: 'number', describe: 'Target customer site ID' })
|
|
14
|
-
.option('role', { type: 'string', choices: ['manager', 'agent'], default: 'manager', describe: 'Scope to apply' })
|
|
15
|
-
.option('agent-id', { type: 'number', describe: 'WorkspaceUser id (required for --role agent)' })
|
|
16
|
-
.option('start', { type: 'string', describe: 'yyyy-MM-dd' })
|
|
17
|
-
.option('end', { type: 'string', describe: 'yyyy-MM-dd' })
|
|
18
|
-
.option('tz', { type: 'string', describe: 'IANA time zone override' })
|
|
19
|
-
.option('json', { type: 'boolean', default: false, describe: 'Raw JSON output' }),
|
|
20
|
-
handler: runCommand(async (argv) => {
|
|
21
|
-
if (argv.role === 'agent' && !argv.agentId) throw new Error('--agent-id is required with --role agent');
|
|
22
|
-
const qs = new URLSearchParams({ detail: 'true', role: argv.role });
|
|
23
|
-
if (argv.agentId) qs.set('agentId', String(argv.agentId));
|
|
24
|
-
for (const k of ['start', 'end', 'tz']) if (argv[k]) qs.set(k, argv[k]);
|
|
25
|
-
const d = await messagingGet(`/Reports/sites/${argv.siteId}/schedule-adherence-diagnostics?${qs}`);
|
|
26
|
-
if (argv.json) { console.log(JSON.stringify(d, null, 2)); return; }
|
|
27
|
-
console.log(`\nSite ${d.siteId} scope=${d.scope} ${d.range?.start}..${d.range?.end} tz=${d.timeZone} invariantsPass=${d.invariantsPass}`);
|
|
28
|
-
console.log(` Totals: sched ${d.totals?.scheduledMinutes}m adherent ${d.totals?.adherentMinutes}m avg ${d.totals?.avgAdherencePercent}%`);
|
|
29
|
-
for (const a of d.agents ?? []) {
|
|
30
|
-
console.log(` [${a.agentId}] ${a.agentName}: ${a.adherencePercent}% status=${a.currentStatus ?? '-'} days=${a.days?.length ?? 0} shiftsToday=${a.timeline?.shifts?.length ?? 0}`);
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
};
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* velaro sharepoint — SharePoint / tracker access commands
|
|
3
|
-
*
|
|
4
|
-
* velaro sharepoint login One-time device-code auth against nocvelaro M365 tenant
|
|
5
|
-
* velaro sharepoint read-tracker Download + parse the Integrations Status Tracker Excel file
|
|
6
|
-
* velaro sharepoint whoami Show the currently logged-in M365 account
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { readConfig, writeConfig } from '../config.js';
|
|
10
|
-
import { spRequestDeviceCode, spPollForToken, getSpAccessToken, downloadSharePointFile } from '../sharepoint-auth.js';
|
|
11
|
-
|
|
12
|
-
// The tracker file. Update the URL here if SharePoint ever moves it.
|
|
13
|
-
const TRACKER_URL = 'https://nocvelaro.sharepoint.com/sites/DevOps/Shared%20Documents/DevOps/Integrations%20and%20Partnerships/Velaro%20Integrations%20Status%20Tracker.xlsx';
|
|
14
|
-
|
|
15
|
-
// ── login ─────────────────────────────────────────────────────────────────────
|
|
16
|
-
|
|
17
|
-
const loginCommand = {
|
|
18
|
-
command: 'login',
|
|
19
|
-
describe: 'Authenticate with SharePoint (nocvelaro M365 tenant). Run once.',
|
|
20
|
-
handler: async () => {
|
|
21
|
-
const deviceData = await spRequestDeviceCode();
|
|
22
|
-
console.log('\n\x1b[1mSign in to access the Velaro SharePoint tracker\x1b[0m');
|
|
23
|
-
console.log(`\n Go to: \x1b[36m${deviceData.verification_uri}\x1b[0m`);
|
|
24
|
-
console.log(` Enter code: \x1b[33m${deviceData.user_code}\x1b[0m`);
|
|
25
|
-
console.log('\nWaiting for sign-in...');
|
|
26
|
-
|
|
27
|
-
const tokenData = await spPollForToken(deviceData.device_code, deviceData.interval || 5);
|
|
28
|
-
|
|
29
|
-
const sp = {
|
|
30
|
-
accessToken: tokenData.access_token,
|
|
31
|
-
refreshToken: tokenData.refresh_token,
|
|
32
|
-
expiresAt: new Date(Date.now() + tokenData.expires_in * 1000).toISOString(),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const cfg = readConfig();
|
|
36
|
-
cfg.sharepoint = sp;
|
|
37
|
-
writeConfig(cfg);
|
|
38
|
-
|
|
39
|
-
// Get display name via Graph
|
|
40
|
-
try {
|
|
41
|
-
const meRes = await fetch('https://graph.microsoft.com/v1.0/me', {
|
|
42
|
-
headers: { Authorization: `Bearer ${tokenData.access_token}` },
|
|
43
|
-
});
|
|
44
|
-
const me = await meRes.json();
|
|
45
|
-
console.log(`\n\x1b[32m✓ Logged in as ${me.displayName} (${me.userPrincipalName})\x1b[0m`);
|
|
46
|
-
} catch {
|
|
47
|
-
console.log('\n\x1b[32m✓ SharePoint login saved.\x1b[0m');
|
|
48
|
-
}
|
|
49
|
-
console.log(' Run: velaro sharepoint read-tracker\n');
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// ── whoami ────────────────────────────────────────────────────────────────────
|
|
54
|
-
|
|
55
|
-
const whoamiCommand = {
|
|
56
|
-
command: 'whoami',
|
|
57
|
-
describe: 'Show the M365 account currently logged into SharePoint',
|
|
58
|
-
handler: async () => {
|
|
59
|
-
const cfg = readConfig();
|
|
60
|
-
let token;
|
|
61
|
-
try {
|
|
62
|
-
const result = await getSpAccessToken(cfg);
|
|
63
|
-
token = result.accessToken;
|
|
64
|
-
if (result.refreshed) { cfg.sharepoint = { ...cfg.sharepoint, ...result.refreshed }; writeConfig(cfg); }
|
|
65
|
-
} catch (e) {
|
|
66
|
-
console.error(`\x1b[31m✗ ${e.message}\x1b[0m`);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const res = await fetch('https://graph.microsoft.com/v1.0/me', {
|
|
71
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
72
|
-
});
|
|
73
|
-
const me = await res.json();
|
|
74
|
-
console.log(`\n \x1b[1m${me.displayName}\x1b[0m (${me.userPrincipalName})`);
|
|
75
|
-
console.log(` Token expires: ${cfg.sharepoint?.expiresAt ?? 'unknown'}\n`);
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// ── read-tracker ──────────────────────────────────────────────────────────────
|
|
80
|
-
|
|
81
|
-
const readTrackerCommand = {
|
|
82
|
-
command: 'read-tracker',
|
|
83
|
-
describe: 'Download and parse the Velaro Integrations Status Tracker spreadsheet',
|
|
84
|
-
builder: (y) =>
|
|
85
|
-
y
|
|
86
|
-
.option('sheet', { type: 'string', describe: 'Sheet name to show (default: all)' })
|
|
87
|
-
.option('json', { type: 'boolean', describe: 'Output raw JSON instead of formatted table' }),
|
|
88
|
-
handler: async (argv) => {
|
|
89
|
-
const cfg = readConfig();
|
|
90
|
-
let accessToken;
|
|
91
|
-
try {
|
|
92
|
-
const result = await getSpAccessToken(cfg);
|
|
93
|
-
accessToken = result.accessToken;
|
|
94
|
-
if (result.refreshed) { cfg.sharepoint = { ...cfg.sharepoint, ...result.refreshed }; writeConfig(cfg); }
|
|
95
|
-
} catch (e) {
|
|
96
|
-
console.error(`\x1b[31m✗ ${e.message}\x1b[0m`);
|
|
97
|
-
process.exit(1);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
console.log('Downloading tracker...');
|
|
101
|
-
let buf;
|
|
102
|
-
try {
|
|
103
|
-
buf = await downloadSharePointFile(TRACKER_URL, accessToken);
|
|
104
|
-
} catch (e) {
|
|
105
|
-
console.error(`\x1b[31m✗ ${e.message}\x1b[0m`);
|
|
106
|
-
process.exit(1);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Dynamically import xlsx (ESM-compatible)
|
|
110
|
-
let XLSX;
|
|
111
|
-
try {
|
|
112
|
-
XLSX = (await import('xlsx')).default;
|
|
113
|
-
} catch (e) {
|
|
114
|
-
console.error('\x1b[31mERROR: xlsx package not installed. Run: npm install --prefix cli\x1b[0m');
|
|
115
|
-
console.error(e.message);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const workbook = XLSX.read(buf, { type: 'buffer', cellDates: true });
|
|
120
|
-
const targetSheets = argv.sheet
|
|
121
|
-
? workbook.SheetNames.filter(n => n.toLowerCase().includes(argv.sheet.toLowerCase()))
|
|
122
|
-
: workbook.SheetNames;
|
|
123
|
-
|
|
124
|
-
if (!targetSheets.length) {
|
|
125
|
-
console.error(`\x1b[31m✗ No sheet matching "${argv.sheet}". Available: ${workbook.SheetNames.join(', ')}\x1b[0m`);
|
|
126
|
-
process.exit(1);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
for (const sheetName of targetSheets) {
|
|
130
|
-
const ws = workbook.Sheets[sheetName];
|
|
131
|
-
const rows = XLSX.utils.sheet_to_json(ws, { defval: '' });
|
|
132
|
-
|
|
133
|
-
if (argv.json) {
|
|
134
|
-
console.log(JSON.stringify({ sheet: sheetName, rows }, null, 2));
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
console.log(`\n\x1b[1m━━ ${sheetName} \x1b[0m(${rows.length} rows)\n`);
|
|
139
|
-
if (!rows.length) { console.log(' (empty)\n'); continue; }
|
|
140
|
-
|
|
141
|
-
// Print as simple key: value blocks — avoids terminal width issues with wide tables
|
|
142
|
-
for (const [i, row] of rows.entries()) {
|
|
143
|
-
const keys = Object.keys(row).filter(k => row[k] !== '');
|
|
144
|
-
if (!keys.length) continue;
|
|
145
|
-
console.log(` \x1b[36m[${i + 1}]\x1b[0m`);
|
|
146
|
-
for (const k of keys) {
|
|
147
|
-
const val = String(row[k]).replace(/\n/g, ' ↵ ').slice(0, 200);
|
|
148
|
-
console.log(` \x1b[33m${k}\x1b[0m: ${val}`);
|
|
149
|
-
}
|
|
150
|
-
console.log('');
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// ── export ────────────────────────────────────────────────────────────────────
|
|
157
|
-
|
|
158
|
-
export const sharepointCommand = {
|
|
159
|
-
command: 'sharepoint <subcommand>',
|
|
160
|
-
describe: 'Access the Velaro SharePoint tracker and M365 files',
|
|
161
|
-
builder: (yargs) =>
|
|
162
|
-
yargs
|
|
163
|
-
.command(loginCommand)
|
|
164
|
-
.command(whoamiCommand)
|
|
165
|
-
.command(readTrackerCommand)
|
|
166
|
-
.demandCommand(1, 'Specify a subcommand: login, whoami, read-tracker'),
|
|
167
|
-
handler: () => {},
|
|
168
|
-
};
|