@uptimerobot/cli 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 (108) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +179 -0
  3. package/bin/run.js +43 -0
  4. package/dist/api/client.js +95 -0
  5. package/dist/api/errors.js +26 -0
  6. package/dist/commands/alert-contacts/create.js +10 -0
  7. package/dist/commands/alert-contacts/delete.js +10 -0
  8. package/dist/commands/alert-contacts/get.js +10 -0
  9. package/dist/commands/alert-contacts/list.js +10 -0
  10. package/dist/commands/alert-contacts/update.js +10 -0
  11. package/dist/commands/auth/login.js +51 -0
  12. package/dist/commands/auth/logout.js +33 -0
  13. package/dist/commands/auth/status.js +38 -0
  14. package/dist/commands/auth/whoami.js +6 -0
  15. package/dist/commands/incidents/activity-log.js +10 -0
  16. package/dist/commands/incidents/alerts.js +10 -0
  17. package/dist/commands/incidents/comments/create.js +10 -0
  18. package/dist/commands/incidents/comments/delete.js +10 -0
  19. package/dist/commands/incidents/comments/list.js +10 -0
  20. package/dist/commands/incidents/comments/update.js +10 -0
  21. package/dist/commands/incidents/get.js +10 -0
  22. package/dist/commands/incidents/list.js +10 -0
  23. package/dist/commands/integrations/create.js +10 -0
  24. package/dist/commands/integrations/delete.js +10 -0
  25. package/dist/commands/integrations/get.js +10 -0
  26. package/dist/commands/integrations/list.js +10 -0
  27. package/dist/commands/integrations/update.js +10 -0
  28. package/dist/commands/maintenance-windows/create.js +10 -0
  29. package/dist/commands/maintenance-windows/delete.js +10 -0
  30. package/dist/commands/maintenance-windows/get.js +10 -0
  31. package/dist/commands/maintenance-windows/list.js +10 -0
  32. package/dist/commands/maintenance-windows/update.js +10 -0
  33. package/dist/commands/monitor-groups/create.js +10 -0
  34. package/dist/commands/monitor-groups/delete.js +10 -0
  35. package/dist/commands/monitor-groups/get.js +10 -0
  36. package/dist/commands/monitor-groups/list.js +10 -0
  37. package/dist/commands/monitor-groups/update.js +10 -0
  38. package/dist/commands/monitors/bulk/pause.js +10 -0
  39. package/dist/commands/monitors/bulk/start.js +10 -0
  40. package/dist/commands/monitors/bulk/update.js +10 -0
  41. package/dist/commands/monitors/create/api.js +10 -0
  42. package/dist/commands/monitors/create/dns.js +10 -0
  43. package/dist/commands/monitors/create/heartbeat.js +10 -0
  44. package/dist/commands/monitors/create/http.js +10 -0
  45. package/dist/commands/monitors/create/keyword.js +10 -0
  46. package/dist/commands/monitors/create/ping.js +10 -0
  47. package/dist/commands/monitors/create/port.js +10 -0
  48. package/dist/commands/monitors/create/udp.js +10 -0
  49. package/dist/commands/monitors/create/visual-comparison.js +10 -0
  50. package/dist/commands/monitors/delete.js +10 -0
  51. package/dist/commands/monitors/get.js +10 -0
  52. package/dist/commands/monitors/list.js +10 -0
  53. package/dist/commands/monitors/pause.js +10 -0
  54. package/dist/commands/monitors/reset.js +10 -0
  55. package/dist/commands/monitors/schema.js +57 -0
  56. package/dist/commands/monitors/start.js +10 -0
  57. package/dist/commands/monitors/stats/response-time/all.js +10 -0
  58. package/dist/commands/monitors/stats/response-time.js +10 -0
  59. package/dist/commands/monitors/stats/uptime.js +10 -0
  60. package/dist/commands/monitors/update.js +10 -0
  61. package/dist/commands/monitors/uptime-stats.js +10 -0
  62. package/dist/commands/status-pages/announcements/create.js +10 -0
  63. package/dist/commands/status-pages/announcements/get.js +10 -0
  64. package/dist/commands/status-pages/announcements/list.js +10 -0
  65. package/dist/commands/status-pages/announcements/pin.js +10 -0
  66. package/dist/commands/status-pages/announcements/unpin.js +10 -0
  67. package/dist/commands/status-pages/announcements/update.js +10 -0
  68. package/dist/commands/status-pages/create.js +10 -0
  69. package/dist/commands/status-pages/delete.js +10 -0
  70. package/dist/commands/status-pages/get.js +10 -0
  71. package/dist/commands/status-pages/list.js +10 -0
  72. package/dist/commands/status-pages/update.js +10 -0
  73. package/dist/commands/tags/delete.js +10 -0
  74. package/dist/commands/tags/list.js +10 -0
  75. package/dist/commands/user/alert-contacts.js +10 -0
  76. package/dist/commands/user/all-alert-contacts.js +10 -0
  77. package/dist/commands/user/get.js +5 -0
  78. package/dist/commands/user/me.js +10 -0
  79. package/dist/generated/operations.js +7631 -0
  80. package/dist/lib/auth.js +60 -0
  81. package/dist/lib/base-command.js +21 -0
  82. package/dist/lib/cli-errors.js +80 -0
  83. package/dist/lib/command-suggestions.js +44 -0
  84. package/dist/lib/credential-store.js +152 -0
  85. package/dist/lib/flag-name.js +11 -0
  86. package/dist/lib/invocation.js +74 -0
  87. package/dist/lib/objects.js +34 -0
  88. package/dist/lib/operation-command.js +486 -0
  89. package/dist/lib/operation-parser-error.js +28 -0
  90. package/dist/lib/request-curation.js +76 -0
  91. package/dist/lib/request-example.js +82 -0
  92. package/dist/lib/request-preview.js +25 -0
  93. package/dist/lib/request.js +301 -0
  94. package/dist/lib/sensitive-fields.js +19 -0
  95. package/dist/lib/types.js +1 -0
  96. package/dist/output/columns.js +221 -0
  97. package/dist/output/display-width.js +34 -0
  98. package/dist/output/normalize-result.js +28 -0
  99. package/dist/output/pagination-notice.js +27 -0
  100. package/dist/output/renderer.js +145 -0
  101. package/dist/output/request-progress.js +15 -0
  102. package/dist/output/resolve-format.js +32 -0
  103. package/dist/output/style.js +57 -0
  104. package/dist/runtime/parse-input.js +35 -0
  105. package/dist/runtime/types.js +1 -0
  106. package/dist/runtime/validate-input.js +63 -0
  107. package/openapi/openapi.yaml +9034 -0
  108. package/package.json +135 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 UptimeRobot
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # UptimeRobot CLI
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@uptimerobot/cli)](https://www.npmjs.com/package/@uptimerobot/cli)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@uptimerobot/cli)](https://www.npmjs.com/package/@uptimerobot/cli)
5
+ [![CI](https://github.com/uptimerobot/uptimerobot-cli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/uptimerobot/uptimerobot-cli/actions/workflows/ci.yml)
6
+ [![Node.js](https://img.shields.io/node/v/@uptimerobot/cli)](https://nodejs.org)
7
+ [![License: Apache-2.0](https://img.shields.io/npm/l/@uptimerobot/cli)](./LICENSE)
8
+
9
+ The official command-line interface for UptimeRobot. Manage uptime monitors, incidents, status pages, maintenance windows, and alert contacts from your terminal, scripts, CI pipelines, or coding agents — readable tables when you're interactive, stable JSON when you're automating.
10
+
11
+ Built on the UptimeRobot API v3. The CLI combines human-friendly commands with structured output, local validation, and safe automation defaults.
12
+
13
+ - Manage monitors, incidents, status pages, maintenance windows, alert contacts, integrations, tags, and more.
14
+ - Create each monitor type through a dedicated command such as `monitors create http` or `monitors create keyword`.
15
+ - Use readable tables interactively and stable JSON or JSONL for automation.
16
+ - Inspect and validate monitor requests locally before sending them.
17
+
18
+ ## Installation
19
+
20
+ UptimeRobot CLI requires Node.js 22.12 or newer.
21
+
22
+ ```sh
23
+ npm install --global @uptimerobot/cli
24
+ ```
25
+
26
+ With pnpm:
27
+
28
+ ```sh
29
+ pnpm add --global @uptimerobot/cli
30
+ ```
31
+
32
+ Verify the installation:
33
+
34
+ ```sh
35
+ uptimerobot --version
36
+ uptimerobot --help
37
+ ```
38
+
39
+ ## Authentication
40
+
41
+ [Create an API key](https://help.uptimerobot.com/en/articles/11620152-how-to-use-uptimerobot-s-api), then save it in your operating system's secure credential store:
42
+
43
+ ```sh
44
+ uptimerobot auth login
45
+ ```
46
+
47
+ The CLI prompts for the key with masked input and validates it before saving, so the key never appears in shell history. For scripts, provide it through the environment instead:
48
+
49
+ ```sh
50
+ UPTIMEROBOT_API_KEY='your-api-key' uptimerobot auth login
51
+ ```
52
+
53
+ The key is stored in macOS Keychain, Windows Credential Manager, or an available Linux keyring. When no OS keyring is available — common on minimal or headless Linux — the key is saved in plaintext at `~/.config/uptimerobot/credentials.json` with owner-only `0600` permissions. Set `UPTIMEROBOT_CONFIG_DIR` to change that location. Prefer a preconfigured environment or secret manager instead of typing secrets directly into shell history.
54
+
55
+ For CI, containers, and other temporary environments, provide the key without storing it:
56
+
57
+ ```sh
58
+ export UPTIMEROBOT_API_KEY='your-api-key'
59
+ uptimerobot monitors list
60
+ ```
61
+
62
+ Credentials are resolved from `--api-key`, then `UPTIMEROBOT_API_KEY`, then the stored key. Run `uptimerobot auth logout` to remove the stored credential.
63
+
64
+ ## Quick start
65
+
66
+ List monitors:
67
+
68
+ ```sh
69
+ uptimerobot monitors list
70
+ ```
71
+
72
+ Create an HTTP monitor:
73
+
74
+ ```sh
75
+ uptimerobot monitors create http \
76
+ --name checkout-api \
77
+ --url https://checkout.example.com \
78
+ --interval 60 \
79
+ --timeout 30 \
80
+ --method GET \
81
+ --check-ssl \
82
+ --follow-redirects
83
+ ```
84
+
85
+ Inspect or delete it:
86
+
87
+ ```sh
88
+ uptimerobot monitors get 797054213
89
+ uptimerobot monitors delete 797054213 --confirm
90
+ ```
91
+
92
+ ## Find the right command
93
+
94
+ Help is available at every level of the command tree:
95
+
96
+ ```sh
97
+ uptimerobot monitors --help
98
+ uptimerobot monitors create --help
99
+ uptimerobot monitors create keyword --help
100
+ uptimerobot incidents comments create --help
101
+ ```
102
+
103
+ Monitor creation commands expose only the fields relevant to their type and supply the API monitor type automatically. Command help includes accepted values, required fields, defaults, constraints, and examples from the packaged API contract.
104
+
105
+ Typed flags cover normal use. Full API request bodies remain available when needed:
106
+
107
+ ```sh
108
+ uptimerobot monitors create http --body @monitor.json
109
+ uptimerobot monitors update 797054213 --set interval=120
110
+ uptimerobot monitors create http --body - < monitor.json
111
+ ```
112
+
113
+ ## Validate before sending
114
+
115
+ Inspect a monitor request contract or print a validated example without credentials or network access:
116
+
117
+ ```sh
118
+ uptimerobot monitors schema keyword
119
+ uptimerobot monitors schema keyword --example
120
+ ```
121
+
122
+ Add `--dry-run` to compile and validate a JSON request without authenticating or sending it:
123
+
124
+ ```sh
125
+ uptimerobot monitors create http --body @monitor.json --dry-run
126
+ ```
127
+
128
+ Dry-run output contains the final method, path, content type, and body. Recognizable credential fields are redacted. Local validation cannot verify account entitlements, referenced resource IDs, or other server-owned rules.
129
+
130
+ ## Output and automation
131
+
132
+ Interactive terminals use tables by default. Piped, redirected, and agent-driven commands use normalized JSON by default.
133
+
134
+ | Option | Output |
135
+ | ---------------- | -------------------------------- |
136
+ | `--json` | Normalized JSON |
137
+ | `--format jsonl` | One normalized resource per line |
138
+ | `--format table` | Human-readable table |
139
+ | `--format plain` | Headerless, tab-separated rows |
140
+ | `--raw` | Untouched API response as JSON |
141
+
142
+ Set `UPTIMEROBOT_OUTPUT` to `json`, `jsonl`, `table`, or `plain` to choose a default. Use `--agent` or `UPTIMEROBOT_AGENT=1` to identify agent execution explicitly. A truthy `CI` environment variable identifies CI execution independently.
143
+
144
+ Normalized collection JSON contains `items` and `nextCursor`. The CLI does not follow pagination automatically; pass a returned cursor through `--cursor` for the next page. Collection commands also support `--columns` and `--all`. Column selection never changes JSON, JSONL, or raw output, and `--all` may expose sensitive API fields.
145
+
146
+ Machine-readable failures are emitted as JSON on stderr while stdout remains empty.
147
+
148
+ ## Safety
149
+
150
+ Destructive commands prompt in an interactive terminal. Agents and non-interactive processes must pass `--confirm` explicitly:
151
+
152
+ ```sh
153
+ uptimerobot monitors delete 797054213 --confirm --json
154
+ ```
155
+
156
+ The CLI retries only safe `GET` and `HEAD` requests. It does not retry `POST`, `PATCH`, or `DELETE`; retain returned resource IDs before deciding to repeat a mutation.
157
+
158
+ ## Development
159
+
160
+ This project uses pnpm and oclif.
161
+
162
+ ```sh
163
+ pnpm install
164
+ pnpm build
165
+ pnpm format:check
166
+ pnpm lint
167
+ pnpm typecheck
168
+ pnpm test
169
+ ```
170
+
171
+ The command tree is generated from [`openapi/openapi.yaml`](openapi/openapi.yaml), which tracks the [published UptimeRobot OpenAPI contract](https://cdn.uptimerobot.com/api/openapi.yaml). Run `pnpm openapi:generate` after updating the snapshot. Generated command files and operation metadata should not be edited directly.
172
+
173
+ ## Support
174
+
175
+ For bugs and feature requests, [open a GitHub issue](https://github.com/uptimerobot/uptimerobot-cli/issues). Include the CLI version, command, output mode, and a sanitized error response when possible. Never include an API key.
176
+
177
+ ## License
178
+
179
+ Licensed under the [Apache License 2.0](LICENSE).
package/bin/run.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+
3
+ const [major, minor, patch] = process.version.replace(/^v/, '').split('.').map(Number);
4
+
5
+ const nodeVersionSupported =
6
+ major > 22 || (major === 22 && minor > 12) || (major === 22 && minor === 12 && patch >= 0);
7
+
8
+ if (!nodeVersionSupported) {
9
+ process.stderr.write(
10
+ `uptimerobot requires Node.js 22.12.0 or newer; you are running ${process.version}.\n` +
11
+ 'Install a current release from https://nodejs.org/.\n',
12
+ );
13
+ process.exit(1);
14
+ }
15
+
16
+ const { flush, handle, run } = await import('@oclif/core');
17
+ const { commandSuggestion } = await import('../dist/lib/command-suggestions.js');
18
+ const { errorEnvelope, exitCodeForError, machineOutputRequested, wasErrorHandled } =
19
+ await import('../dist/lib/cli-errors.js');
20
+
21
+ try {
22
+ await run(process.argv.slice(2), import.meta.url);
23
+ await flush();
24
+ } catch (error) {
25
+ await flush();
26
+ const suggestion = commandSuggestion(process.argv.slice(2));
27
+ if (
28
+ suggestion &&
29
+ typeof error === 'object' &&
30
+ error !== null &&
31
+ /^command .+ not found$/.test(error.message ?? '')
32
+ ) {
33
+ error.suggestions = [`uptimerobot ${suggestion}`];
34
+ }
35
+ if (wasErrorHandled(error)) {
36
+ process.exitCode = exitCodeForError(error);
37
+ } else if (machineOutputRequested()) {
38
+ process.stderr.write(`${JSON.stringify(errorEnvelope(error))}\n`);
39
+ process.exitCode = exitCodeForError(error);
40
+ } else {
41
+ await handle(error);
42
+ }
43
+ }
@@ -0,0 +1,95 @@
1
+ import ky, { isHTTPError } from 'ky';
2
+ const RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
3
+ const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
4
+ const MAX_REDIRECTS = 5;
5
+ const MAX_RETRY_DELAY_MS = 5000;
6
+ const REQUEST_TIMEOUT_MS = 30_000;
7
+ export function createApiClient(options) {
8
+ const baseUrl = options.apiUrl;
9
+ const http = ky.create({
10
+ fetch: options.fetchImplementation ?? fetch,
11
+ // Redirects are followed manually below so the origin check can be
12
+ // re-applied to every hop before credentials are attached again.
13
+ redirect: 'manual',
14
+ retry: {
15
+ afterStatusCodes: RETRYABLE_STATUSES,
16
+ delay: (attempt) => 100 * 2 ** (attempt - 1),
17
+ limit: 2,
18
+ maxRetryAfter: MAX_RETRY_DELAY_MS,
19
+ methods: ['get', 'head'],
20
+ shouldRetry: ({ error }) => (hasLongRetryAfter(error) ? false : undefined),
21
+ statusCodes: RETRYABLE_STATUSES,
22
+ },
23
+ timeout: REQUEST_TIMEOUT_MS,
24
+ });
25
+ return {
26
+ async request(input, init) {
27
+ if (input.origin !== baseUrl.origin) {
28
+ throw new Error('Refusing to send credentials to a different origin.');
29
+ }
30
+ const headers = new Headers(init.headers);
31
+ headers.set('authorization', `Bearer ${options.apiKey}`);
32
+ headers.set('user-agent', `uptimerobot-cli/${options.version} mode/${options.mode} environment/${options.environment}`);
33
+ headers.set('x-uptimerobot-client', 'cli');
34
+ headers.set('x-uptimerobot-execution-environment', options.environment);
35
+ headers.set('x-uptimerobot-invocation-mode', options.mode);
36
+ let url = input;
37
+ let method = init.method ?? 'GET';
38
+ let body = init.body;
39
+ for (let redirects = 0;; redirects += 1) {
40
+ let response;
41
+ try {
42
+ response = await http(new Request(url, { body, headers, method }));
43
+ }
44
+ catch (error) {
45
+ if (!isHTTPError(error))
46
+ throw error;
47
+ const location = error.response.headers.get('location');
48
+ if (!REDIRECT_STATUSES.has(error.response.status) ||
49
+ !location ||
50
+ redirects === MAX_REDIRECTS) {
51
+ return { payload: error.data, response: error.response };
52
+ }
53
+ const next = new URL(location, url);
54
+ if (next.origin !== baseUrl.origin) {
55
+ throw new Error('Refusing to follow a redirect to a different origin.');
56
+ }
57
+ url = next;
58
+ if (error.response.status === 303 ||
59
+ ((error.response.status === 301 || error.response.status === 302) &&
60
+ method !== 'GET' &&
61
+ method !== 'HEAD')) {
62
+ method = 'GET';
63
+ body = undefined;
64
+ headers.delete('content-type');
65
+ }
66
+ continue;
67
+ }
68
+ return { payload: await readSuccessPayload(response), response };
69
+ }
70
+ },
71
+ };
72
+ }
73
+ async function readSuccessPayload(response) {
74
+ if (response.status === 204)
75
+ return { success: true };
76
+ const text = await response.text();
77
+ if (text.length === 0)
78
+ return { success: true };
79
+ try {
80
+ return JSON.parse(text);
81
+ }
82
+ catch {
83
+ return text;
84
+ }
85
+ }
86
+ function hasLongRetryAfter(error) {
87
+ if (!isHTTPError(error))
88
+ return undefined;
89
+ const retryAfter = error.response.headers.get('retry-after');
90
+ if (!retryAfter)
91
+ return undefined;
92
+ const seconds = Number(retryAfter);
93
+ const delay = Number.isFinite(seconds) ? seconds * 1000 : Date.parse(retryAfter) - Date.now();
94
+ return Number.isFinite(delay) && Math.max(0, delay) > MAX_RETRY_DELAY_MS ? true : undefined;
95
+ }
@@ -0,0 +1,26 @@
1
+ export function normalizeApiError(status, payload) {
2
+ const object = typeof payload === 'object' && payload !== null ? payload : {};
3
+ const rawMessage = typeof payload === 'string' ? payload : (object.message ?? object.error);
4
+ const message = Array.isArray(rawMessage)
5
+ ? rawMessage.map(String).join('; ')
6
+ : typeof rawMessage === 'string'
7
+ ? rawMessage
8
+ : `UptimeRobot API request failed with HTTP ${status}.`;
9
+ return {
10
+ code: typeof object.code === 'string' ? object.code : `HTTP_${status}`,
11
+ ...(object.details !== undefined ? { details: object.details } : {}),
12
+ message,
13
+ status,
14
+ };
15
+ }
16
+ export function exitCodeFor(status) {
17
+ if (status === 401)
18
+ return 4;
19
+ if (status === 403)
20
+ return 5;
21
+ if (status === 404)
22
+ return 6;
23
+ if (status === 429)
24
+ return 7;
25
+ return 1;
26
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Code generated by scripts/generate-openapi.ts
3
+ * from openapi/openapi.yaml.
4
+ *
5
+ * DO NOT EDIT — changes will be overwritten.
6
+ * Run `pnpm openapi:generate` to regenerate.
7
+ */
8
+ import { createOperationCommand } from '../../lib/operation-command.js';
9
+ import { operations } from '../../generated/operations.js';
10
+ export default createOperationCommand(operations['alert-contacts:create']);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Code generated by scripts/generate-openapi.ts
3
+ * from openapi/openapi.yaml.
4
+ *
5
+ * DO NOT EDIT — changes will be overwritten.
6
+ * Run `pnpm openapi:generate` to regenerate.
7
+ */
8
+ import { createOperationCommand } from '../../lib/operation-command.js';
9
+ import { operations } from '../../generated/operations.js';
10
+ export default createOperationCommand(operations['alert-contacts:delete']);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Code generated by scripts/generate-openapi.ts
3
+ * from openapi/openapi.yaml.
4
+ *
5
+ * DO NOT EDIT — changes will be overwritten.
6
+ * Run `pnpm openapi:generate` to regenerate.
7
+ */
8
+ import { createOperationCommand } from '../../lib/operation-command.js';
9
+ import { operations } from '../../generated/operations.js';
10
+ export default createOperationCommand(operations['alert-contacts:get']);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Code generated by scripts/generate-openapi.ts
3
+ * from openapi/openapi.yaml.
4
+ *
5
+ * DO NOT EDIT — changes will be overwritten.
6
+ * Run `pnpm openapi:generate` to regenerate.
7
+ */
8
+ import { createOperationCommand } from '../../lib/operation-command.js';
9
+ import { operations } from '../../generated/operations.js';
10
+ export default createOperationCommand(operations['alert-contacts:list']);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Code generated by scripts/generate-openapi.ts
3
+ * from openapi/openapi.yaml.
4
+ *
5
+ * DO NOT EDIT — changes will be overwritten.
6
+ * Run `pnpm openapi:generate` to regenerate.
7
+ */
8
+ import { createOperationCommand } from '../../lib/operation-command.js';
9
+ import { operations } from '../../generated/operations.js';
10
+ export default createOperationCommand(operations['alert-contacts:update']);
@@ -0,0 +1,51 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { AuthenticationError, PRODUCTION_API_URL, saveValidatedApiKey } from '../../lib/auth.js';
3
+ import { BaseCommand } from '../../lib/base-command.js';
4
+ import { detectInvocationMode, isCI, promptSecret } from '../../lib/invocation.js';
5
+ import { resolveFormat } from '../../output/resolve-format.js';
6
+ export default class AuthLogin extends BaseCommand {
7
+ static description = 'Validate and securely store a UptimeRobot API key. Run without flags to paste the key at a masked prompt.';
8
+ static flags = {
9
+ 'api-key': Flags.string({
10
+ description: 'UptimeRobot API key to validate and save (prompted securely when omitted)',
11
+ env: 'UPTIMEROBOT_API_KEY',
12
+ helpValue: '<key>',
13
+ }),
14
+ json: Flags.boolean({ description: 'Emit structured JSON output' }),
15
+ };
16
+ static summary = 'Log in with an API key';
17
+ async run() {
18
+ const { flags } = await this.parse(AuthLogin);
19
+ const mode = detectInvocationMode(false);
20
+ let apiKey = flags['api-key'];
21
+ if (!apiKey && mode === 'human') {
22
+ apiKey = await promptSecret('Paste your UptimeRobot API key: ');
23
+ }
24
+ if (!apiKey) {
25
+ this.error('No API key provided. Pass --api-key, set UPTIMEROBOT_API_KEY, or run in an interactive terminal.', { code: 'AUTH_REQUIRED', exit: 2 });
26
+ }
27
+ let backend;
28
+ try {
29
+ backend = await saveValidatedApiKey(apiKey, PRODUCTION_API_URL, {
30
+ environment: isCI() ? 'ci' : 'local',
31
+ mode,
32
+ version: this.config.pjson.version,
33
+ });
34
+ }
35
+ catch (error) {
36
+ if (error instanceof AuthenticationError)
37
+ this.error(error.message, { code: error.code, exit: error.exitCode });
38
+ throw error;
39
+ }
40
+ const format = resolveFormat(flags, mode);
41
+ if (format === 'json' || format === 'jsonl') {
42
+ this.log(JSON.stringify({ authenticated: true, storage: backend, stored: true, type: 'api-key' }));
43
+ }
44
+ else if (backend === 'keyring') {
45
+ this.log('API key validated and saved in the OS credential store.');
46
+ }
47
+ else {
48
+ this.log('API key validated and saved in the config file.');
49
+ }
50
+ }
51
+ }