@oneuptime/cli 1.0.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.
package/README.md ADDED
@@ -0,0 +1,220 @@
1
+ # @oneuptime/cli
2
+
3
+ Command-line interface for managing OneUptime resources. Supports all MCP-enabled resources with full CRUD operations, named contexts for multiple environments, and flexible output formats.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @oneuptime/cli
9
+ ```
10
+
11
+ Or run directly within the monorepo:
12
+
13
+ ```bash
14
+ cd CLI
15
+ npm install
16
+ npm start -- --help
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```bash
22
+ # Authenticate with your OneUptime instance
23
+ oneuptime login <api-key> <instance-url>
24
+ oneuptime login sk-your-api-key https://oneuptime.com
25
+
26
+ # List incidents
27
+ oneuptime incident list --limit 10
28
+
29
+ # Get a single resource by ID
30
+ oneuptime monitor get 550e8400-e29b-41d4-a716-446655440000
31
+
32
+ # Create a resource
33
+ oneuptime monitor create --data '{"name":"API Health","projectId":"..."}'
34
+
35
+ # See all available resources
36
+ oneuptime resources
37
+ ```
38
+
39
+ ## Authentication & Contexts
40
+
41
+ The CLI supports multiple authentication contexts, making it easy to switch between environments.
42
+
43
+ ### Setting Up
44
+
45
+ ```bash
46
+ # Create a production context
47
+ oneuptime login sk-prod-key https://oneuptime.com --context-name production
48
+
49
+ # Create a staging context
50
+ oneuptime login sk-staging-key https://staging.oneuptime.com --context-name staging
51
+ ```
52
+
53
+ ### Switching Contexts
54
+
55
+ ```bash
56
+ # List all contexts
57
+ oneuptime context list
58
+
59
+ # Switch active context
60
+ oneuptime context use staging
61
+
62
+ # Show current context
63
+ oneuptime context current
64
+
65
+ # Delete a context
66
+ oneuptime context delete old-context
67
+ ```
68
+
69
+ ### Credential Resolution Order
70
+
71
+ 1. CLI flags: `--api-key` and `--url`
72
+ 2. Environment variables: `ONEUPTIME_API_KEY` and `ONEUPTIME_URL`
73
+ 3. Current context from config file (`~/.oneuptime/config.json`)
74
+
75
+ ## Command Reference
76
+
77
+ ### Authentication
78
+
79
+ | Command | Description |
80
+ |---|---|
81
+ | `oneuptime login <api-key> <url>` | Authenticate and create a context |
82
+ | `oneuptime context list` | List all contexts |
83
+ | `oneuptime context use <name>` | Switch active context |
84
+ | `oneuptime context current` | Show current context |
85
+ | `oneuptime context delete <name>` | Remove a context |
86
+ | `oneuptime whoami` | Show current auth info |
87
+
88
+ ### Resource Operations
89
+
90
+ Every discovered resource supports these subcommands:
91
+
92
+ | Subcommand | Description |
93
+ |---|---|
94
+ | `<resource> list [options]` | List resources with filtering and pagination |
95
+ | `<resource> get <id>` | Get a single resource by ID |
96
+ | `<resource> create --data <json>` | Create a new resource |
97
+ | `<resource> update <id> --data <json>` | Update an existing resource |
98
+ | `<resource> delete <id>` | Delete a resource |
99
+ | `<resource> count [--query <json>]` | Count resources |
100
+
101
+ ### List Options
102
+
103
+ ```
104
+ --query <json> Filter criteria as JSON
105
+ --limit <n> Maximum number of results (default: 10)
106
+ --skip <n> Number of results to skip (default: 0)
107
+ --sort <json> Sort order as JSON (e.g. '{"createdAt": -1}')
108
+ -o, --output Output format: json, table, wide
109
+ ```
110
+
111
+ ### Utility Commands
112
+
113
+ | Command | Description |
114
+ |---|---|
115
+ | `oneuptime version` | Print CLI version |
116
+ | `oneuptime whoami` | Show current authentication info |
117
+ | `oneuptime resources` | List all available resource types |
118
+
119
+ ## Output Formats
120
+
121
+ | Format | Description |
122
+ |---|---|
123
+ | `table` | Formatted ASCII table (default for TTY) |
124
+ | `json` | Raw JSON (default when piped) |
125
+ | `wide` | Table with all columns shown |
126
+
127
+ ```bash
128
+ # Explicit format
129
+ oneuptime incident list -o json
130
+ oneuptime incident list -o table
131
+ oneuptime incident list -o wide
132
+
133
+ # Pipe to jq (auto-detects JSON)
134
+ oneuptime incident list | jq '.[].title'
135
+ ```
136
+
137
+ ## Scripting Examples
138
+
139
+ ```bash
140
+ # List incidents as JSON for scripting
141
+ oneuptime incident list -o json --limit 100
142
+
143
+ # Count resources with filter
144
+ oneuptime incident count --query '{"currentIncidentStateId":"..."}'
145
+
146
+ # Create from a JSON file
147
+ oneuptime monitor create --file monitor.json
148
+
149
+ # Use environment variables in CI/CD
150
+ ONEUPTIME_API_KEY=sk-xxx ONEUPTIME_URL=https://oneuptime.com oneuptime incident list
151
+ ```
152
+
153
+ ## Environment Variables
154
+
155
+ | Variable | Description |
156
+ |---|---|
157
+ | `ONEUPTIME_API_KEY` | API key for authentication |
158
+ | `ONEUPTIME_URL` | OneUptime instance URL |
159
+ | `NO_COLOR` | Disable colored output |
160
+
161
+ ## Configuration File
162
+
163
+ The CLI stores configuration at `~/.oneuptime/config.json` with `0600` permissions. The file contains:
164
+
165
+ ```json
166
+ {
167
+ "currentContext": "production",
168
+ "contexts": {
169
+ "production": {
170
+ "name": "production",
171
+ "apiUrl": "https://oneuptime.com",
172
+ "apiKey": "sk-..."
173
+ }
174
+ },
175
+ "defaults": {
176
+ "output": "table",
177
+ "limit": 10
178
+ }
179
+ }
180
+ ```
181
+
182
+ ## Global Options
183
+
184
+ | Option | Description |
185
+ |---|---|
186
+ | `--api-key <key>` | Override API key for this command |
187
+ | `--url <url>` | Override instance URL for this command |
188
+ | `--context <name>` | Use a specific context for this command |
189
+ | `-o, --output <format>` | Output format: json, table, wide |
190
+ | `--no-color` | Disable colored output |
191
+
192
+ ## Supported Resources
193
+
194
+ Run `oneuptime resources` to see all available resource types. Resources are auto-discovered from OneUptime models that have MCP enabled. Currently supported:
195
+
196
+ - **Incident** - Manage incidents
197
+ - **Alert** - Manage alerts
198
+ - **Monitor** - Manage monitors
199
+ - **Monitor Status** - Manage monitor statuses
200
+ - **Incident State** - Manage incident states
201
+ - **Status Page** - Manage status pages
202
+ - **On-Call Policy** - Manage on-call duty policies
203
+ - **Team** - Manage teams
204
+ - **Scheduled Maintenance Event** - Manage scheduled maintenance
205
+
206
+ As more models are MCP-enabled in OneUptime, they automatically become available in the CLI.
207
+
208
+ ## Development
209
+
210
+ ```bash
211
+ cd CLI
212
+ npm install
213
+ npm start -- --help # Run via ts-node
214
+ npm test # Run tests
215
+ npm run compile # Type-check
216
+ ```
217
+
218
+ ## License
219
+
220
+ Apache-2.0
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.registerConfigCommands = registerConfigCommands;
40
+ const ConfigManager = __importStar(require("../Core/ConfigManager"));
41
+ const OutputFormatter_1 = require("../Core/OutputFormatter");
42
+ const cli_table3_1 = __importDefault(require("cli-table3"));
43
+ const chalk_1 = __importDefault(require("chalk"));
44
+ function registerConfigCommands(program) {
45
+ // Login command
46
+ const loginCmd = program
47
+ .command("login")
48
+ .description("Authenticate with a OneUptime instance")
49
+ .argument("<api-key>", "API key for authentication")
50
+ .argument("<instance-url>", "OneUptime instance URL (e.g. https://oneuptime.com)")
51
+ .option("--context-name <name>", "Name for this context", "default")
52
+ .action((apiKey, instanceUrl, options) => {
53
+ try {
54
+ const context = {
55
+ name: options.contextName,
56
+ apiUrl: instanceUrl.replace(/\/+$/, ""),
57
+ apiKey: apiKey,
58
+ };
59
+ ConfigManager.addContext(context);
60
+ ConfigManager.setCurrentContext(context.name);
61
+ (0, OutputFormatter_1.printSuccess)(`Logged in successfully. Context "${context.name}" is now active.`);
62
+ }
63
+ catch (error) {
64
+ (0, OutputFormatter_1.printError)(`Login failed: ${error instanceof Error ? error.message : String(error)}`);
65
+ process.exit(1);
66
+ }
67
+ });
68
+ // Suppress unused variable warning - loginCmd is used for registration
69
+ void loginCmd;
70
+ // Context commands
71
+ const contextCmd = program
72
+ .command("context")
73
+ .description("Manage CLI contexts (environments/projects)");
74
+ contextCmd
75
+ .command("list")
76
+ .description("List all configured contexts")
77
+ .action(() => {
78
+ const contexts = ConfigManager.listContexts();
79
+ if (contexts.length === 0) {
80
+ (0, OutputFormatter_1.printInfo)("No contexts configured. Run `oneuptime login` to create one.");
81
+ return;
82
+ }
83
+ const noColor = process.env["NO_COLOR"] !== undefined ||
84
+ process.argv.includes("--no-color");
85
+ const table = new cli_table3_1.default({
86
+ head: ["", "Name", "URL"].map((h) => {
87
+ return noColor ? h : chalk_1.default.cyan(h);
88
+ }),
89
+ style: { head: [], border: [] },
90
+ });
91
+ for (const ctx of contexts) {
92
+ table.push([ctx.isCurrent ? "*" : "", ctx.name, ctx.apiUrl]);
93
+ }
94
+ // eslint-disable-next-line no-console
95
+ console.log(table.toString());
96
+ });
97
+ contextCmd
98
+ .command("use <name>")
99
+ .description("Switch to a different context")
100
+ .action((name) => {
101
+ try {
102
+ ConfigManager.setCurrentContext(name);
103
+ (0, OutputFormatter_1.printSuccess)(`Switched to context "${name}".`);
104
+ }
105
+ catch (error) {
106
+ (0, OutputFormatter_1.printError)(error instanceof Error ? error.message : String(error));
107
+ process.exit(1);
108
+ }
109
+ });
110
+ contextCmd
111
+ .command("current")
112
+ .description("Show the current active context")
113
+ .action(() => {
114
+ const ctx = ConfigManager.getCurrentContext();
115
+ if (!ctx) {
116
+ (0, OutputFormatter_1.printInfo)("No current context set. Run `oneuptime login` to create one.");
117
+ return;
118
+ }
119
+ const maskedKey = ctx.apiKey.length > 8
120
+ ? ctx.apiKey.substring(0, 4) +
121
+ "****" +
122
+ ctx.apiKey.substring(ctx.apiKey.length - 4)
123
+ : "****";
124
+ // eslint-disable-next-line no-console
125
+ console.log(`Context: ${ctx.name}`);
126
+ // eslint-disable-next-line no-console
127
+ console.log(`URL: ${ctx.apiUrl}`);
128
+ // eslint-disable-next-line no-console
129
+ console.log(`API Key: ${maskedKey}`);
130
+ });
131
+ contextCmd
132
+ .command("delete <name>")
133
+ .description("Delete a context")
134
+ .action((name) => {
135
+ try {
136
+ ConfigManager.removeContext(name);
137
+ (0, OutputFormatter_1.printSuccess)(`Context "${name}" deleted.`);
138
+ }
139
+ catch (error) {
140
+ (0, OutputFormatter_1.printError)(error instanceof Error ? error.message : String(error));
141
+ process.exit(1);
142
+ }
143
+ });
144
+ }
145
+ //# sourceMappingURL=ConfigCommands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigCommands.js","sourceRoot":"","sources":["../../../Commands/ConfigCommands.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,wDAoIC;AA1ID,qEAAuD;AAEvD,6DAA8E;AAC9E,4DAA+B;AAC/B,kDAA0B;AAE1B,SAAgB,sBAAsB,CAAC,OAAgB;IACrD,gBAAgB;IAChB,MAAM,QAAQ,GAAY,OAAO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