@vigilbase/cli
Version:
Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.
81 lines (80 loc) • 3.83 kB
JavaScript
import { z } from 'zod';
export const cloudflareScopeSchema = z.object({
customerId: z.string().uuid('Customer ID must be a UUID.').optional(),
accountId: z.string().regex(/^[a-f0-9]{32}$/i, 'Cloudflare account ID must contain 32 hexadecimal characters.').optional(),
zoneId: z.string().regex(/^[a-f0-9]{32}$/i, 'Cloudflare zone ID must contain 32 hexadecimal characters.').optional(),
});
export const workspaceSectionSchema = z.enum([
'overview', 'reports', 'zones', 'rule-analyzer', 'accounts', 'checkups', 'settings',
]);
export const accountResourceSchema = z.enum(['audit-logs', 'zero-trust', 'developer-platform', 'magic-transit']);
/** All requests use One's tenant and permission checks, never provider credentials. */
export class CloudflareClient {
one;
constructor(one) {
this.one = one;
}
workspace(scope, section) {
const params = new URLSearchParams();
if (scope.customerId)
params.set('customerId', scope.customerId);
if (scope.accountId)
params.set('account', scope.accountId);
if (scope.zoneId)
params.set('zone', scope.zoneId);
return this.one.requestJson(this.path(`/api/services/cloudflare/workspace${section ? `/${section}` : ''}`, params));
}
zoneRecords(kind, zoneId, customerId) {
const params = new URLSearchParams();
if (customerId)
params.set('customerId', customerId);
return this.one.requestJson(this.path(`/api/services/cloudflare/zones/${encodeURIComponent(zoneId)}/${kind}`, params));
}
accountResource(resource, accountId, customerId) {
const params = new URLSearchParams();
if (customerId)
params.set('customerId', customerId);
return this.one.requestJson(this.path(`/api/cloudflare/accounts/${encodeURIComponent(accountId)}/${resource}`, params));
}
zoneDetail(customerId, zoneId) {
return this.one.requestJson(`/api/customers/${encodeURIComponent(customerId)}/cloudflare/zones/${encodeURIComponent(zoneId)}`);
}
speedSettings(zoneId, customerId) {
const params = new URLSearchParams();
if (customerId)
params.set('customerId', customerId);
return this.one.requestJson(this.path(`/api/cloudflare/zones/${encodeURIComponent(zoneId)}/speed-settings`, params));
}
analytics(scope, days) {
const params = new URLSearchParams({ days: String(days) });
if (scope.customerId)
params.set('customerId', scope.customerId);
if (scope.accountId)
params.set('accountId', scope.accountId);
if (scope.zoneId)
params.set('zoneId', scope.zoneId);
return this.one.requestJson(this.path('/api/services/cloudflare/analytics', params));
}
checkup(scope, isStart = false) {
if (isStart) {
return this.one.requestJson('/api/services/cloudflare/checkups/start', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ customerId: scope.customerId, accountId: scope.accountId }),
}, { hasCustomerScope: Boolean(scope.customerId) });
}
const params = new URLSearchParams();
if (scope.customerId)
params.set('customerId', scope.customerId);
if (scope.accountId)
params.set('accountId', scope.accountId);
return this.one.requestJson(this.path('/api/services/cloudflare/checkups', params));
}
checkupProgress(toolRunId) {
return this.one.requestJson(this.path('/api/services/cloudflare/checkups/progress', new URLSearchParams({ toolRunId })));
}
path(path, params) {
const query = params.toString();
return `${path}${query ? `?${query}` : ''}`;
}
}