UNPKG

@vigilbase/cli

Version:

Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.

42 lines (41 loc) • 2.93 kB
/** * CLI-authored hints for One errors the CLI recognises. They are chosen only * from the request (method, route, whether a customer was selected), the HTTP * status and One's own error codes. One's free-text messages are never shown: * they can describe its configuration. */ export const STAFF_CUSTOMER_SCOPE_HINT = 'Vigilbase staff: add --customer-id <uuid>.'; export const BROWSER_SESSION_HINT = 'Invitations need a One browser session: manage them at https://one.vigilbase.com.'; export const VIGIL_UI_DISABLED_HINT = "Vigil investigations aren't enabled in Vigilbase One."; const RULES = [ // Staff sessions must name the customer; One answers 400 without one. { method: 'GET', route: /^\/api\/support\/tickets$/u, status: 400, hasCustomerScope: false, hint: STAFF_CUSTOMER_SCOPE_HINT }, { method: 'GET', route: /^\/api\/services\/cloudflare\/checkups$/u, status: 400, hasCustomerScope: false, hint: STAFF_CUSTOMER_SCOPE_HINT }, { method: 'POST', route: /^\/api\/services\/cloudflare\/checkups\/start$/u, status: 400, hasCustomerScope: false, hint: STAFF_CUSTOMER_SCOPE_HINT }, { method: 'GET', route: /^\/api\/services\/cloudflare\/workspace(?:\/[a-z-]+)?$/u, status: 400, hasCustomerScope: false, hint: STAFF_CUSTOMER_SCOPE_HINT }, // The same answers from One's v1 operations (paths relative to /one/v1). { method: 'GET', route: /^\/support-tickets$/u, status: 400, hasCustomerScope: false, hint: STAFF_CUSTOMER_SCOPE_HINT }, { method: 'GET', route: /^\/cloudflare\/checkups$/u, status: 400, hasCustomerScope: false, hint: STAFF_CUSTOMER_SCOPE_HINT }, // Identity's management API accepts only One browser sessions, so CLI tokens can't read or send invitations. { method: 'GET', route: /^\/api\/auth\/orgs\/invitations$/u, status: 403, hasCustomerScope: false, hint: BROWSER_SESSION_HINT, code: 'browser_session_required' }, { method: 'POST', route: /^\/api\/auth\/orgs\/invite$/u, status: 403, hasCustomerScope: false, hint: BROWSER_SESSION_HINT, code: 'browser_session_required' }, // One answers authorized staff 501 VIGIL_UI_DISABLED while the investigation UI ships dark. { method: 'GET', route: /^\/api\/customers\/[0-9a-f-]{36}\/vigil\/investigations(?:\/[0-9a-f-]{36})?$/iu, status: 501, hasCustomerScope: false, hint: VIGIL_UI_DISABLED_HINT, code: 'VIGIL_UI_DISABLED', }, ]; export function oneErrorHint(context) { const [pathname = '', query = ''] = context.path.split('?', 2); const hasCustomerScope = context.hasCustomerScope ?? new URLSearchParams(query).has('customerId'); const method = context.method.toUpperCase(); return RULES.find((rule) => rule.method === method && rule.status === context.status && rule.hasCustomerScope === hasCustomerScope && rule.route.test(pathname) && (rule.code === undefined || rule.code === context.code))?.hint; }