@knowttl/tenable-axi 0.0.0-stage → 0.1.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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +341 -2
  3. package/axi-credential.schema.json +28 -0
  4. package/bin/tenable-axi-hook.js +13 -0
  5. package/bin/tenable-axi.js +8 -0
  6. package/bin/version.js +3 -0
  7. package/dist/src/attack-catalogue.d.ts +176 -0
  8. package/dist/src/attack-catalogue.js +71 -0
  9. package/dist/src/attack-export-catalogue.d.ts +29 -0
  10. package/dist/src/attack-export-catalogue.js +58 -0
  11. package/dist/src/attack-export.d.ts +5 -0
  12. package/dist/src/attack-export.js +151 -0
  13. package/dist/src/attack.d.ts +3 -0
  14. package/dist/src/attack.js +287 -0
  15. package/dist/src/catalogue.d.ts +150 -0
  16. package/dist/src/catalogue.js +68 -0
  17. package/dist/src/cli.d.ts +11 -0
  18. package/dist/src/cli.js +61 -0
  19. package/dist/src/export-file.d.ts +8 -0
  20. package/dist/src/export-file.js +157 -0
  21. package/dist/src/exposure-contracts.d.ts +31 -0
  22. package/dist/src/exposure-contracts.js +31 -0
  23. package/dist/src/exposure.d.ts +4 -0
  24. package/dist/src/exposure.js +305 -0
  25. package/dist/src/hook-install.d.ts +1 -0
  26. package/dist/src/hook-install.js +132 -0
  27. package/dist/src/inventory/schema.d.ts +34 -0
  28. package/dist/src/inventory/schema.js +18 -0
  29. package/dist/src/inventory-catalogue.d.ts +55 -0
  30. package/dist/src/inventory-catalogue.js +61 -0
  31. package/dist/src/inventory-export-catalogue.d.ts +96 -0
  32. package/dist/src/inventory-export-catalogue.js +47 -0
  33. package/dist/src/inventory-export.d.ts +5 -0
  34. package/dist/src/inventory-export.js +162 -0
  35. package/dist/src/inventory.d.ts +3 -0
  36. package/dist/src/inventory.js +285 -0
  37. package/dist/src/local-commands.d.ts +2 -0
  38. package/dist/src/local-commands.js +44 -0
  39. package/dist/src/platform-tag-catalogue.d.ts +101 -0
  40. package/dist/src/platform-tag-catalogue.js +180 -0
  41. package/dist/src/platform-tag.d.ts +4 -0
  42. package/dist/src/platform-tag.js +312 -0
  43. package/dist/src/private-file.d.ts +18 -0
  44. package/dist/src/private-file.js +156 -0
  45. package/dist/src/profiles.d.ts +116 -0
  46. package/dist/src/profiles.js +147 -0
  47. package/dist/src/redact.d.ts +7 -0
  48. package/dist/src/redact.js +41 -0
  49. package/dist/src/response-catalogue.d.ts +41 -0
  50. package/dist/src/response-catalogue.js +134 -0
  51. package/dist/src/response.d.ts +4 -0
  52. package/dist/src/response.js +227 -0
  53. package/dist/src/setup.d.ts +1 -0
  54. package/dist/src/setup.js +39 -0
  55. package/dist/src/transport-core.d.ts +85 -0
  56. package/dist/src/transport-core.js +274 -0
  57. package/dist/src/transport.d.ts +4 -0
  58. package/dist/src/transport.js +6 -0
  59. package/dist/src/writes-core.d.ts +112 -0
  60. package/dist/src/writes-core.js +215 -0
  61. package/dist/src/writes.d.ts +57 -0
  62. package/dist/src/writes.js +5 -0
  63. package/docs/commands.md +1377 -0
  64. package/inventory/capabilities.json +3728 -0
  65. package/package.json +24 -4
  66. package/skills/tenable-axi/SKILL.md +101 -0
@@ -0,0 +1,150 @@
1
+ import type { OperationBinding } from "./transport-core.js";
2
+ import type { MutationOperation } from "./writes-core.js";
3
+ export declare const DESCRIPTION = "Investigate Tenable One exposure and run explicitly guarded writes";
4
+ export declare const SETUP_GUIDANCE = "Run tenable-axi config path; configure a profile with accessKey and secretKey SecretRefs";
5
+ export declare const transportBindings: Readonly<Record<string, OperationBinding>>;
6
+ export declare const mutationOperations: Readonly<Record<string, MutationOperation>>;
7
+ export declare const catalogue: {
8
+ readonly "card list": {
9
+ description: string;
10
+ flags: {
11
+ global: string;
12
+ query: string;
13
+ "sorting-order": string;
14
+ limit: string;
15
+ offset: string;
16
+ cursor: string;
17
+ all: string;
18
+ config: string;
19
+ profile: string;
20
+ fields: string;
21
+ full: string;
22
+ help: string;
23
+ };
24
+ examples: string[];
25
+ };
26
+ readonly "card show": {
27
+ description: string;
28
+ flags: {
29
+ id: string;
30
+ "trend-start-date": string;
31
+ "trend-end-date": string;
32
+ "sla-efficiency-start-date": string;
33
+ "sla-efficiency-end-date": string;
34
+ "sla-breakdown-filter": string;
35
+ "include-trend-events": string;
36
+ config: string;
37
+ profile: string;
38
+ fields: string;
39
+ full: string;
40
+ help: string;
41
+ };
42
+ examples: string[];
43
+ };
44
+ readonly "tag list": {
45
+ description: string;
46
+ flags: {
47
+ query: string;
48
+ filter: string;
49
+ "filter-file": string;
50
+ sort: string;
51
+ "extra-properties": string;
52
+ limit: string;
53
+ offset: string;
54
+ cursor: string;
55
+ all: string;
56
+ config: string;
57
+ profile: string;
58
+ fields: string;
59
+ full: string;
60
+ help: string;
61
+ };
62
+ examples: string[];
63
+ };
64
+ readonly "tag properties": {
65
+ description: string;
66
+ flags: {
67
+ config: string;
68
+ profile: string;
69
+ fields: string;
70
+ full: string;
71
+ help: string;
72
+ };
73
+ examples: string[];
74
+ };
75
+ readonly doctor: {
76
+ description: string;
77
+ flags: {
78
+ config: string;
79
+ profile: string;
80
+ fields: string;
81
+ full: string;
82
+ help: string;
83
+ };
84
+ examples: string[];
85
+ };
86
+ readonly hook: {
87
+ description: string;
88
+ flags: {
89
+ config: string;
90
+ profile: string;
91
+ fields: string;
92
+ full: string;
93
+ help: string;
94
+ };
95
+ examples: string[];
96
+ };
97
+ readonly "setup hooks": {
98
+ readonly description: "Explicitly install or repair local agent session integrations";
99
+ readonly flags: {
100
+ readonly scope: "user or project; default user; project targets the current directory";
101
+ readonly help: "Show help; default false";
102
+ };
103
+ readonly examples: readonly ["tenable-axi setup hooks", "tenable-axi setup hooks --scope project"];
104
+ };
105
+ readonly home: {
106
+ readonly description: "Show profile state and up to five live exposure cards";
107
+ readonly flags: {
108
+ readonly config: "Config path; default platform path";
109
+ readonly profile: "Profile name; default credential precedence";
110
+ readonly fields: "Card fields; default id,name,score";
111
+ readonly full: "Full text; default false";
112
+ readonly help: "Show help; default false";
113
+ };
114
+ readonly examples: readonly ["tenable-axi", "tenable-axi home --help"];
115
+ };
116
+ readonly "auth status": {
117
+ readonly description: "Check local credentials and file security without contacting Tenable";
118
+ readonly flags: {
119
+ readonly config: "Config path; default TENABLE_AXI_CONFIG or platform path";
120
+ readonly profile: "Profile name; default credential precedence";
121
+ readonly fields: "Comma-separated output fields; default all";
122
+ readonly full: "Show full text; default false";
123
+ readonly help: "Show help; default false";
124
+ };
125
+ readonly examples: readonly ["tenable-axi auth status", "tenable-axi auth status --profile example"];
126
+ };
127
+ readonly "profile list": {
128
+ readonly description: "List configured profiles without resolving secrets or contacting Tenable";
129
+ readonly flags: {
130
+ readonly config: "Config path; default TENABLE_AXI_CONFIG or platform path";
131
+ readonly profile: "Common selector; list still shows all profiles";
132
+ readonly fields: "Comma-separated output fields; default all";
133
+ readonly full: "Show full text; default false";
134
+ readonly help: "Show help; default false";
135
+ };
136
+ readonly examples: readonly ["tenable-axi profile list", "tenable-axi profile list --config /example/config.json"];
137
+ };
138
+ readonly "config path": {
139
+ readonly description: "Show selected config and state paths without reading files";
140
+ readonly flags: {
141
+ readonly config: "Config path; default TENABLE_AXI_CONFIG or platform path";
142
+ readonly profile: "Common selector; paths are independent of profile";
143
+ readonly fields: "Comma-separated output fields; default all";
144
+ readonly full: "Show full text; default false";
145
+ readonly help: "Show help; default false";
146
+ };
147
+ readonly examples: readonly ["tenable-axi config path", "tenable-axi config path --fields config"];
148
+ };
149
+ };
150
+ export declare function help(): Record<string, unknown>;
@@ -0,0 +1,68 @@
1
+ import { inventoryBindings, inventoryCatalogue } from "./inventory-catalogue.js";
2
+ import { exposureBindings } from "./exposure-contracts.js";
3
+ import { attackBindings, attackCatalogue } from "./attack-catalogue.js";
4
+ import { attackExportBindings, attackExportCatalogue, attackExportMutations } from "./attack-export-catalogue.js";
5
+ import { inventoryExportBindings, inventoryExportCatalogue, inventoryExportMutations } from "./inventory-export-catalogue.js";
6
+ import { platformTagBindings, platformTagCatalogue, platformTagMutations } from "./platform-tag-catalogue.js";
7
+ import { responseBindings, responseCatalogue, responseMutations } from "./response-catalogue.js";
8
+ export const DESCRIPTION = "Investigate Tenable One exposure and run explicitly guarded writes";
9
+ export const SETUP_GUIDANCE = "Run tenable-axi config path; configure a profile with accessKey and secretKey SecretRefs";
10
+ // Endpoint slices add reviewed executable bindings alongside their commands.
11
+ export const transportBindings = Object.freeze({ ...inventoryBindings, ...exposureBindings, ...attackBindings, ...inventoryExportBindings, ...attackExportBindings, ...platformTagBindings, ...responseBindings });
12
+ export const mutationOperations = Object.freeze({ ...inventoryExportMutations, ...attackExportMutations, ...platformTagMutations, ...responseMutations });
13
+ // Evidence and planned commands never enable execution. Endpoint slices add explicit bindings here.
14
+ export const catalogue = {
15
+ ...inventoryCatalogue,
16
+ ...attackCatalogue,
17
+ ...inventoryExportCatalogue,
18
+ ...attackExportCatalogue,
19
+ ...platformTagCatalogue,
20
+ ...responseCatalogue,
21
+ "setup hooks": {
22
+ description: "Explicitly install or repair local agent session integrations",
23
+ flags: { scope: "user or project; default user; project targets the current directory", help: "Show help; default false" },
24
+ examples: ["tenable-axi setup hooks", "tenable-axi setup hooks --scope project"],
25
+ },
26
+ home: {
27
+ description: "Show profile state and up to five live exposure cards",
28
+ flags: { config: "Config path; default platform path", profile: "Profile name; default credential precedence", fields: "Card fields; default id,name,score", full: "Full text; default false", help: "Show help; default false" },
29
+ examples: ["tenable-axi", "tenable-axi home --help"],
30
+ },
31
+ "auth status": {
32
+ description: "Check local credentials and file security without contacting Tenable",
33
+ flags: { config: "Config path; default TENABLE_AXI_CONFIG or platform path", profile: "Profile name; default credential precedence", fields: "Comma-separated output fields; default all", full: "Show full text; default false", help: "Show help; default false" },
34
+ examples: ["tenable-axi auth status", "tenable-axi auth status --profile example"],
35
+ },
36
+ "profile list": {
37
+ description: "List configured profiles without resolving secrets or contacting Tenable",
38
+ flags: { config: "Config path; default TENABLE_AXI_CONFIG or platform path", profile: "Common selector; list still shows all profiles", fields: "Comma-separated output fields; default all", full: "Show full text; default false", help: "Show help; default false" },
39
+ examples: ["tenable-axi profile list", "tenable-axi profile list --config /example/config.json"],
40
+ },
41
+ "config path": {
42
+ description: "Show selected config and state paths without reading files",
43
+ flags: { config: "Config path; default TENABLE_AXI_CONFIG or platform path", profile: "Common selector; paths are independent of profile", fields: "Comma-separated output fields; default all", full: "Show full text; default false", help: "Show help; default false" },
44
+ examples: ["tenable-axi config path", "tenable-axi config path --fields config"],
45
+ },
46
+ ...exposureCatalogue(),
47
+ };
48
+ function exposureCatalogue() {
49
+ const common = { config: "Config path; default platform path", profile: "Profile name; default credential precedence", fields: "Comma-separated output fields; default compact projection", full: "Full text; default false", help: "Show help; default false" };
50
+ const paging = { limit: "Output rows; default 100", offset: "Starting record; default 0", cursor: "Resume the same scoped collection", all: "Read up to 10000 rows; incompatible with --limit" };
51
+ return {
52
+ "card list": { description: "List exposure view cards", flags: { ...common, ...paging, global: "true or false; default all cards", query: "Card name search", "sorting-order": "asc or desc; default API order" }, examples: ["tenable-axi card list", "tenable-axi card list --global true --limit 5"] },
53
+ "card show": { description: "Show an exposure card and its scores, trends and SLA details", flags: { ...common, id: "Required card ID", "trend-start-date": "UTC ISO timestamp", "trend-end-date": "UTC ISO timestamp", "sla-efficiency-start-date": "UTC ISO timestamp", "sla-efficiency-end-date": "UTC ISO timestamp", "sla-breakdown-filter": "ANY, REMEDIATED or NON_REMEDIATED; default ANY", "include-trend-events": "true or false; default false" }, examples: ["tenable-axi card show --id <id>", "tenable-axi card show --id <id> --include-trend-events true"] },
54
+ "tag list": { description: "Search Exposure Management tags", flags: { ...common, ...paging, query: "Simple text search", filter: "Repeatable: property operator JSON-array-of-strings", "filter-file": "Strict documented tag filter array; incompatible with --filter", sort: "property:asc or property:desc", "extra-properties": "Comma-separated property names" }, examples: ["tenable-axi tag list", "tenable-axi tag list --query production --limit 10"] },
55
+ "tag properties": { description: "List available tag properties and operators", flags: common, examples: ["tenable-axi tag properties", "tenable-axi tag properties --fields property,operators"] },
56
+ doctor: { description: "Check local security and one tag-properties read without retries", flags: common, examples: ["tenable-axi doctor", "tenable-axi doctor --profile example"] },
57
+ hook: { description: "Show compact local profile context without resolving secrets or HTTP", flags: common, examples: ["tenable-axi hook", "tenable-axi hook --profile example"] },
58
+ };
59
+ }
60
+ export function help() {
61
+ return {
62
+ description: DESCRIPTION,
63
+ commands: Object.fromEntries(Object.entries(catalogue).map(([name, entry]) => [name, entry.description])),
64
+ flags: Object.fromEntries(Object.entries(catalogue.home.flags).map(([name, description]) => [`--${name}`, description])),
65
+ version: "-v, -V, --version: print the bare version",
66
+ examples: catalogue.home.examples,
67
+ };
68
+ }
@@ -0,0 +1,11 @@
1
+ import { type CredentialContext } from "./profiles.js";
2
+ import { type TransportFactory } from "./exposure.js";
3
+ import { type WriteCoordinatorFactory } from "./inventory-export.js";
4
+ export declare function main(argv?: string[], options?: {
5
+ credentials?: CredentialContext;
6
+ stdout?: {
7
+ write: (chunk: string) => unknown;
8
+ };
9
+ transportFactory?: TransportFactory;
10
+ writeCoordinatorFactory?: WriteCoordinatorFactory;
11
+ }): Promise<void>;
@@ -0,0 +1,61 @@
1
+ import { AxiError, runAxiCli } from "axi-sdk-js";
2
+ import { DESCRIPTION, help } from "./catalogue.js";
3
+ import { encode } from "@toon-format/toon";
4
+ import { credentialStore } from "./profiles.js";
5
+ import { localCommand } from "./local-commands.js";
6
+ import { inventoryCommand } from "./inventory.js";
7
+ import { exposureCommand } from "./exposure.js";
8
+ import { TransportError } from "./transport.js";
9
+ import { attackCommand } from "./attack.js";
10
+ import { attackExportCommand } from "./attack-export.js";
11
+ import { inventoryExportCommand } from "./inventory-export.js";
12
+ import { createWriteCoordinator } from "./writes.js";
13
+ import { platformTagCommand } from "./platform-tag.js";
14
+ import { responseCommand } from "./response.js";
15
+ import { setupHooks } from "./setup.js";
16
+ export async function main(argv = process.argv.slice(2), options = {}) {
17
+ const store = credentialStore(options.credentials);
18
+ await runAxiCli({
19
+ description: DESCRIPTION,
20
+ argv: ["scaffold"],
21
+ topLevelHelp: "",
22
+ home: async () => store.redactor.payload(await exposureCommand([], store, options.transportFactory)),
23
+ stdout: { write: (chunk) => (options.stdout ?? process.stdout).write(store.redactor.text(chunk)) },
24
+ formatError: (error) => ({
25
+ output: `${encode(store.redactor.value(error instanceof TransportError ? error.toJSON() : error instanceof AxiError ? { error: { code: error.code, message: error.message }, help: error.suggestions }
26
+ : { error: { code: "CONFIG_INVALID", message: "Command could not complete" } }))}\n`,
27
+ exitCode: error instanceof AxiError && error.code === "VALIDATION_ERROR" ? 2 : 1,
28
+ }),
29
+ commands: {
30
+ scaffold: async () => {
31
+ if (argv[0] === "setup")
32
+ return setupHooks(argv);
33
+ if (argv[0] === "tag" && !["list", "properties"].includes(argv[1] ?? ""))
34
+ return store.redactor.payload(await platformTagCommand(argv, store, options.transportFactory, options.writeCoordinatorFactory ?? ((flags) => createWriteCoordinator(flags, options.credentials))));
35
+ if (["initiative", "combination"].includes(argv[0] ?? "")) {
36
+ const result = await responseCommand(argv, store, options.transportFactory, options.writeCoordinatorFactory ?? ((flags) => createWriteCoordinator(flags, options.credentials)));
37
+ if (result.error)
38
+ process.exitCode = 1;
39
+ return store.redactor.payload(result);
40
+ }
41
+ if (argv[0] === "export")
42
+ return store.redactor.payload(await (["attack-path", "attack-technique", "mitre-heatmap", "attack"].includes(argv[1] ?? "") ? attackExportCommand : inventoryExportCommand)(argv, store, options.transportFactory, options.writeCoordinatorFactory ?? ((flags) => createWriteCoordinator(flags, options.credentials))));
43
+ if (["attack-path", "attack-technique", "connector"].includes(argv[0] ?? "")) {
44
+ const result = await attackCommand(argv, store, options.transportFactory);
45
+ if (result.error)
46
+ process.exitCode = 1;
47
+ return store.redactor.value(result);
48
+ }
49
+ if (["asset", "finding", "software"].includes(argv[0] ?? "")) {
50
+ const result = await inventoryCommand(argv, store, options.transportFactory);
51
+ if (result.error)
52
+ process.exitCode = 1;
53
+ return store.redactor.value(result);
54
+ }
55
+ if (["auth", "profile", "config"].includes(argv[0] ?? ""))
56
+ return store.redactor.value(localCommand(argv, store));
57
+ return argv.length === 1 && argv[0] === "--help" ? help() : store.redactor.payload(await exposureCommand(argv, store, options.transportFactory));
58
+ },
59
+ },
60
+ });
61
+ }
@@ -0,0 +1,8 @@
1
+ import type { SecretRedactor } from "./redact.js";
2
+ export declare function exportOutputPath(path: string, operation: string): string;
3
+ export declare function saveExport(contents: unknown, output: string, redactor: SecretRedactor, operation: string): {
4
+ output: string;
5
+ bytes: number;
6
+ format: string;
7
+ compressed: boolean;
8
+ };
@@ -0,0 +1,157 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { closeSync, fsyncSync, linkSync, lstatSync, openSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { gunzipSync, gzipSync } from "node:zlib";
5
+ import { TransportError } from "./transport-core.js";
6
+ const ceiling = 128 * 1024 * 1024;
7
+ // Parse CSV before scanning so quoted delimiters, newlines and sensitive columns
8
+ // have the same redaction semantics as JSON properties.
9
+ function csv(text) {
10
+ const rows = [];
11
+ let row = [];
12
+ let cell = "";
13
+ let quoted = false;
14
+ let closed = false;
15
+ for (let index = 0; index < text.length; index++) {
16
+ const char = text[index];
17
+ if (quoted) {
18
+ if (char === '"') {
19
+ if (text[index + 1] === '"') {
20
+ cell += '"';
21
+ index++;
22
+ }
23
+ else {
24
+ quoted = false;
25
+ closed = true;
26
+ }
27
+ }
28
+ else
29
+ cell += char;
30
+ }
31
+ else if (char === '"' && !cell && !closed)
32
+ quoted = true;
33
+ else if (char === ",") {
34
+ row.push(cell);
35
+ cell = "";
36
+ closed = false;
37
+ }
38
+ else if (char === "\n" || char === "\r") {
39
+ if (char === "\r" && text[index + 1] === "\n")
40
+ index++;
41
+ row.push(cell);
42
+ rows.push(row);
43
+ row = [];
44
+ cell = "";
45
+ closed = false;
46
+ }
47
+ else {
48
+ if (closed || char === '"')
49
+ throw new Error("Invalid CSV quoting");
50
+ cell += char;
51
+ }
52
+ }
53
+ if (quoted)
54
+ throw new Error("Unclosed CSV quote");
55
+ if (cell || row.length || closed) {
56
+ row.push(cell);
57
+ rows.push(row);
58
+ }
59
+ if (!rows.length || rows[0].some((name) => !name) || rows.some((row) => row.length !== rows[0].length))
60
+ throw new Error("Invalid CSV rows");
61
+ return rows;
62
+ }
63
+ export function exportOutputPath(path, operation) {
64
+ const output = resolve(path);
65
+ try {
66
+ lstatSync(output);
67
+ }
68
+ catch (error) {
69
+ if (error.code === "ENOENT")
70
+ return output;
71
+ throw new TransportError({ code: "OUTPUT_FAILED", message: "Cannot inspect output destination", operation });
72
+ }
73
+ throw new TransportError({ code: "OUTPUT_EXISTS", message: "Output must be a new file; choose another path", operation });
74
+ }
75
+ export function saveExport(contents, output, redactor, operation) {
76
+ const invalid = () => { throw new TransportError({ code: "RESPONSE_INVALID", message: "Export must be valid bounded JSON or CSV, optionally gzip compressed", operation }); };
77
+ if (!Buffer.isBuffer(contents) || contents.length > ceiling)
78
+ invalid();
79
+ const source = contents;
80
+ const compressed = source[0] === 0x1f && source[1] === 0x8b;
81
+ let bytes;
82
+ let format;
83
+ try {
84
+ const decoded = compressed ? gunzipSync(source, { maxOutputLength: ceiling }) : source;
85
+ const text = new TextDecoder("utf-8", { fatal: true }).decode(decoded).replace(/^\uFEFF/, "");
86
+ if (!text.trim())
87
+ invalid();
88
+ const normalize = (key) => key.toLowerCase().replace(/[ -]/g, "_");
89
+ const scan = (value) => {
90
+ if (Array.isArray(value))
91
+ return value.map(scan);
92
+ if (value && typeof value === "object")
93
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => {
94
+ const name = normalize(key);
95
+ return [redactor.text(key), redactor.payload({ [name]: scan(child) })[name]];
96
+ }));
97
+ return redactor.payload(value);
98
+ };
99
+ let safe;
100
+ if (/^\s*[\[{]/.test(text)) {
101
+ const value = JSON.parse(text);
102
+ if (Array.isArray(value)
103
+ ? value.some((row) => !row || typeof row !== "object" || Array.isArray(row))
104
+ : operation !== "apa-export-download" || !value || typeof value !== "object")
105
+ invalid();
106
+ format = "JSON";
107
+ safe = JSON.stringify(scan(value));
108
+ }
109
+ else {
110
+ const rows = csv(text);
111
+ const headers = rows[0];
112
+ if (headers.some((header) => /[<>\r\n]/.test(header)))
113
+ invalid();
114
+ format = "CSV";
115
+ const quote = (value) => `"${value.replace(/"/g, '""')}"`;
116
+ safe = rows.map((row, index) => row.map((cell, column) => {
117
+ const key = normalize(headers[column]);
118
+ const value = index === 0 ? redactor.payload(cell) : redactor.payload({ [key]: cell })[key];
119
+ return quote(String(value));
120
+ }).join(",")).join("\n");
121
+ }
122
+ const encoded = Buffer.from(safe);
123
+ if (encoded.length > ceiling)
124
+ invalid();
125
+ bytes = compressed ? gzipSync(encoded) : encoded;
126
+ if (bytes.length > ceiling)
127
+ invalid();
128
+ }
129
+ catch {
130
+ return invalid();
131
+ }
132
+ const temporary = join(dirname(output), `.tenable-export-${randomUUID()}.tmp`);
133
+ let fd;
134
+ let created = false;
135
+ try {
136
+ fd = openSync(temporary, "wx", 0o600);
137
+ created = true;
138
+ writeFileSync(fd, bytes);
139
+ fsyncSync(fd);
140
+ closeSync(fd);
141
+ fd = undefined;
142
+ // A hard link publishes the completed file atomically and refuses even a
143
+ // destination created after the initial existence check.
144
+ linkSync(temporary, output);
145
+ return { output, bytes: bytes.length, format, compressed };
146
+ }
147
+ catch (error) {
148
+ throw new TransportError({ code: error.code === "EEXIST" ? "OUTPUT_EXISTS" : "OUTPUT_FAILED",
149
+ message: "Export file could not be published; choose a new writable output path", operation });
150
+ }
151
+ finally {
152
+ if (fd !== undefined)
153
+ closeSync(fd);
154
+ if (created)
155
+ unlinkSync(temporary);
156
+ }
157
+ }
@@ -0,0 +1,31 @@
1
+ import { z } from "zod";
2
+ import type { OperationBinding } from "./transport-core.js";
3
+ export declare const TAG_PRIVILEGE = "EXPOSURE_MANAGEMENT.TAG.TAG.READ";
4
+ export declare const cardRecord: z.ZodObject<{
5
+ id: z.ZodString;
6
+ name: z.ZodString;
7
+ ces_score: z.ZodOptional<z.ZodObject<{
8
+ score: z.ZodNumber;
9
+ }, z.core.$loose>>;
10
+ }, z.core.$loose>;
11
+ export declare const cardDetails: z.ZodObject<{
12
+ id: z.ZodString;
13
+ name: z.ZodString;
14
+ ces_scores: z.ZodOptional<z.ZodObject<{
15
+ total: z.ZodObject<{
16
+ score: z.ZodNumber;
17
+ }, z.core.$loose>;
18
+ }, z.core.$loose>>;
19
+ }, z.core.$loose>;
20
+ export declare const tagRecord: z.ZodObject<{
21
+ id: z.ZodString;
22
+ name: z.ZodString;
23
+ extra_properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
24
+ }, z.core.$loose>;
25
+ export declare const properties: z.ZodObject<{
26
+ data: z.ZodArray<z.ZodObject<{
27
+ key: z.ZodString;
28
+ operators: z.ZodArray<z.ZodString>;
29
+ }, z.core.$loose>>;
30
+ }, z.core.$strip>;
31
+ export declare const exposureBindings: Readonly<Record<string, OperationBinding>>;
@@ -0,0 +1,31 @@
1
+ import { z } from "zod";
2
+ export const TAG_PRIVILEGE = "EXPOSURE_MANAGEMENT.TAG.TAG.READ";
3
+ const score = z.object({ score: z.number() }).passthrough();
4
+ export const cardRecord = z.object({ id: z.string(), name: z.string(), ces_score: score.optional() }).passthrough();
5
+ export const cardDetails = z.object({ id: z.string(), name: z.string(), ces_scores: z.object({ total: score }).passthrough().optional() }).passthrough();
6
+ export const tagRecord = z.object({ id: z.string(), name: z.string(), extra_properties: z.record(z.string(), z.unknown()).optional() }).passthrough();
7
+ const pagination = z.object({ total: z.number().int().nonnegative().optional(), total_record_count: z.number().int().nonnegative().optional() }).passthrough();
8
+ export const properties = z.object({ data: z.array(z.object({ key: z.string(), operators: z.array(z.string()) }).passthrough()) });
9
+ export const exposureBindings = {
10
+ "exposure-view-cards-search": {
11
+ method: "GET", path: "/api/v1/t1/exposure-view/cards", effect: "read",
12
+ query: ["is_global_card", "text_query", "sorting_order", "limit", "offset"], paging: ["limit", "offset"],
13
+ decoder: z.object({ data: z.array(cardRecord), pagination: pagination.optional() }),
14
+ permissionHelp: "Requires EXPOSURE_MANAGEMENT.ANALYTICS.EXPOSURE_VIEW.READ", validationHelp: "Check card list --help",
15
+ },
16
+ "exposure-view-card-details": {
17
+ method: "GET", path: "/api/v1/t1/exposure-view/cards/{card_id}", effect: "read",
18
+ query: ["trend_start_date", "trend_end_date", "sla_efficiency_start_date", "sla_efficiency_end_date", "sla_breakdown_filter", "include_trend_events"],
19
+ decoder: cardDetails, permissionHelp: "Requires EXPOSURE_MANAGEMENT.ANALYTICS.EXPOSURE_VIEW.READ", validationHelp: "Check card show --help",
20
+ },
21
+ "inventory-tag-search": {
22
+ method: "POST", path: "/api/v1/t1/tags/search", effect: "read",
23
+ query: ["extra_properties", "offset", "limit", "sort"], paging: ["limit", "offset"],
24
+ decoder: z.object({ data: z.array(tagRecord), pagination: pagination.optional() }),
25
+ permissionHelp: `Requires ${TAG_PRIVILEGE}`, validationHelp: "Run tenable-axi tag properties to discover filter properties and operators",
26
+ },
27
+ "inventory-tag-properties-list": {
28
+ method: "GET", path: "/api/v1/t1/tags/properties", effect: "read", query: [], decoder: properties,
29
+ permissionHelp: `Requires ${TAG_PRIVILEGE}`, validationHelp: "Check tag properties --help",
30
+ },
31
+ };
@@ -0,0 +1,4 @@
1
+ import { credentialStore } from "./profiles.js";
2
+ import { type Transport, type TransportOptions } from "./transport.js";
3
+ export type TransportFactory = (options: TransportOptions) => Transport;
4
+ export declare function exposureCommand(argv: string[], store: ReturnType<typeof credentialStore>, factory?: TransportFactory): Promise<Record<string, unknown>>;