@oneuptime/common 14.0.102 → 14.0.103
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/Models/DatabaseModels/Index.js +6 -0
- package/Models/DatabaseModels/LogSavedView.d.mts +1 -0
- package/Models/DatabaseModels/LogSavedView.d.ts +1 -0
- package/Models/DatabaseModels/LogSavedView.js +43 -1
- package/Models/DatabaseModels/NetworkControllerConnection.d.mts +1 -0
- package/Models/DatabaseModels/NetworkControllerConnection.d.ts +1 -0
- package/Models/DatabaseModels/NetworkControllerConnection.js +21 -0
- package/Models/DatabaseModels/Project.d.mts +3 -0
- package/Models/DatabaseModels/Project.d.ts +3 -0
- package/Models/DatabaseModels/Project.js +124 -0
- package/Models/DatabaseModels/Runner.d.mts +1 -0
- package/Models/DatabaseModels/Runner.d.ts +1 -0
- package/Models/DatabaseModels/Runner.js +40 -0
- package/Models/DatabaseModels/SecurityCase.d.mts +2 -1
- package/Models/DatabaseModels/SecurityCase.d.ts +2 -1
- package/Models/DatabaseModels/SecurityCase.js +27 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.d.mts +20 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.d.ts +20 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.js +387 -0
- package/Models/DatabaseModels/SecurityCaseCustomField.mjs +2 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.d.mts +15 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.d.ts +15 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.js +309 -0
- package/Models/DatabaseModels/SecurityCaseNoteTemplate.mjs +2 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.d.mts +11 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.d.ts +11 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.js +186 -0
- package/Models/DatabaseModels/WorkspaceHomeChoice.mjs +2 -0
- package/Types/AI/AIFixReadiness.d.mts +2 -0
- package/Types/AI/AIFixReadiness.d.ts +2 -0
- package/Types/AI/AIFixReadiness.js +0 -6
- package/Types/AI/CodeTask.d.mts +3 -1
- package/Types/AI/CodeTask.d.ts +3 -1
- package/Types/AI/CodeTask.js +12 -0
- package/Types/CustomField/CustomFieldRecordKinds.js +5 -0
- package/Types/CustomField/CustomFieldSavedViews.js +2 -0
- package/Types/DateLanguage.js +3 -2
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.d.mts +1 -0
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.d.ts +1 -0
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.js +84 -6
- package/Types/DockerSwarm/DockerSwarmInventoryExtractor.mjs +1 -0
- package/Types/InstallScripts/InstallScripts.d.mts +1 -0
- package/Types/InstallScripts/InstallScripts.d.ts +1 -0
- package/Types/InstallScripts/InstallScripts.js +14 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.d.mts +15 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.d.ts +15 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.js +168 -0
- package/Types/Monitor/DockerSwarmAlertTemplates.mjs +1 -0
- package/Types/Monitor/DockerSwarmMetricCatalog.d.mts +1 -1
- package/Types/Monitor/DockerSwarmMetricCatalog.d.ts +1 -1
- package/Types/Monitor/DockerSwarmMetricCatalog.js +43 -11
- package/Types/Monitor/SeriesContext/SeriesDebugHints.js +19 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.d.mts +70 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.d.ts +70 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.js +389 -0
- package/Types/NetworkController/NetworkControllerDeviceAdd.mjs +26 -0
- package/Types/NetworkController/NetworkControllerReadSummary.d.mts +2 -0
- package/Types/NetworkController/NetworkControllerReadSummary.d.ts +2 -0
- package/Types/NetworkController/NetworkControllerReadSummary.js +6 -1
- package/Types/NetworkDevice/NetworkTopologyLayout.d.mts +8 -0
- package/Types/NetworkDevice/NetworkTopologyLayout.d.ts +8 -0
- package/Types/NetworkDevice/NetworkTopologyLayout.js +49 -0
- package/Types/NetworkDevice/NetworkTopologyLayout.mjs +3 -0
- package/Types/Permission.d.mts +8 -0
- package/Types/Permission.d.ts +8 -0
- package/Types/Permission.js +87 -3
- package/Types/PushNotification/PushNotificationCategory.d.mts +3 -0
- package/Types/PushNotification/PushNotificationCategory.d.ts +3 -0
- package/Types/PushNotification/PushNotificationCategory.js +38 -0
- package/Types/PushNotification/PushNotificationCategory.mjs +4 -0
- package/Types/PushNotification/PushNotificationMessage.d.mts +1 -0
- package/Types/PushNotification/PushNotificationMessage.d.ts +1 -0
- package/Types/Runner/RunnerCodeFixes.d.mts +22 -0
- package/Types/Runner/RunnerCodeFixes.d.ts +22 -0
- package/Types/Runner/RunnerCodeFixes.js +129 -0
- package/Types/Runner/RunnerCodeFixes.mjs +9 -0
- package/Types/SecurityCase/SecurityCaseNumber.js +8 -4
- package/Types/SecurityEvent/MitreAttack.d.mts +2 -0
- package/Types/SecurityEvent/MitreAttack.d.ts +2 -0
- package/Types/SecurityEvent/MitreAttack.js +26 -0
- package/Types/SecurityEvent/MitreAttack.mjs +2 -0
- package/Types/SecurityEvent/OcsfSeverity.js +10 -1
- package/Types/Telemetry/TelemetrySearchQuery.js +14 -2
- package/Types/Workspace/WorkspaceMessagePayload.d.mts +7 -0
- package/Types/Workspace/WorkspaceMessagePayload.d.ts +7 -0
- package/Utils/CronScheduleText.d.mts +3 -0
- package/Utils/CronScheduleText.d.ts +3 -0
- package/Utils/CronScheduleText.js +307 -0
- package/Utils/CronScheduleText.mjs +3 -0
- package/Utils/Dashboard/DashboardBoardLayout.d.mts +2 -0
- package/Utils/Dashboard/DashboardBoardLayout.d.ts +2 -0
- package/Utils/Dashboard/DashboardBoardLayout.js +17 -4
- package/Utils/Dashboard/DashboardBoardLayout.mjs +1 -0
- package/Utils/DeveloperDocs/CliCommands.d.mts +114 -0
- package/Utils/DeveloperDocs/CliCommands.d.ts +114 -0
- package/Utils/DeveloperDocs/CliCommands.js +750 -0
- package/Utils/DeveloperDocs/CliCommands.mjs +37 -0
- package/Utils/DeveloperDocs/CliExamples.d.mts +59 -0
- package/Utils/DeveloperDocs/CliExamples.d.ts +59 -0
- package/Utils/DeveloperDocs/CliExamples.js +348 -0
- package/Utils/DeveloperDocs/CliExamples.mjs +17 -0
- package/Utils/DeveloperDocs/CliResources.d.mts +18 -0
- package/Utils/DeveloperDocs/CliResources.d.ts +18 -0
- package/Utils/DeveloperDocs/CliResources.js +129 -0
- package/Utils/DeveloperDocs/CliResources.mjs +6 -0
- package/Utils/DeveloperDocs/ExampleBuilder.d.mts +6 -0
- package/Utils/DeveloperDocs/ExampleBuilder.d.ts +6 -0
- package/Utils/DeveloperDocs/ExampleBuilder.js +27 -2
- package/Utils/DeveloperDocs/ExampleBuilder.mjs +1 -0
- package/Utils/DeveloperDocs/PageLookups.d.mts +1 -1
- package/Utils/DeveloperDocs/PageLookups.d.ts +1 -1
- package/Utils/DeveloperDocs/PageLookups.js +9 -2
- package/Utils/DeveloperDocs/TerraformSchema.d.mts +1 -0
- package/Utils/DeveloperDocs/TerraformSchema.d.ts +1 -0
- package/Utils/DeveloperDocs/TerraformSchema.js +3 -1
- package/Utils/DeveloperDocs/TerraformSchema.mjs +1 -0
- package/Utils/LookupTable.d.mts +3 -0
- package/Utils/LookupTable.d.ts +3 -0
- package/Utils/LookupTable.js +44 -0
- package/Utils/LookupTable.mjs +4 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.d.mts +62 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.d.ts +62 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.js +484 -0
- package/Utils/Monitor/MonitorCheckScheduleUtil.mjs +3 -0
- package/Utils/Monitor/MonitorOverviewFamily.d.mts +39 -0
- package/Utils/Monitor/MonitorOverviewFamily.d.ts +39 -0
- package/Utils/Monitor/MonitorOverviewFamily.js +207 -0
- package/Utils/Monitor/MonitorOverviewFamily.mjs +4 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.d.mts +192 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.d.ts +192 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.js +1659 -0
- package/Utils/Monitor/MonitorOverviewPresentationUtil.mjs +5 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.d.mts +112 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.d.ts +112 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.js +640 -0
- package/Utils/Monitor/MonitorOverviewProbeUtil.mjs +3 -0
- package/Utils/Monitor/MonitorOverviewTargetUtil.d.mts +1 -1
- package/Utils/Monitor/MonitorOverviewTargetUtil.d.ts +1 -1
- package/Utils/Monitor/MonitorStatusHistoryUtil.d.mts +27 -0
- package/Utils/Monitor/MonitorStatusHistoryUtil.d.ts +27 -0
- package/Utils/Monitor/MonitorStatusHistoryUtil.js +132 -0
- package/Utils/Monitor/MonitorStatusHistoryUtil.mjs +2 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.d.mts +44 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.d.ts +44 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.js +487 -0
- package/Utils/Monitor/MonitorUptimeSummaryUtil.mjs +2 -0
- package/Utils/OldestKeyMap.d.mts +10 -0
- package/Utils/OldestKeyMap.d.ts +10 -0
- package/Utils/OldestKeyMap.js +91 -0
- package/Utils/OldestKeyMap.mjs +2 -0
- package/Utils/Project/NextNumber.d.mts +4 -3
- package/Utils/Project/NextNumber.d.ts +4 -3
- package/Utils/Project/NextNumber.js +11 -2
- package/Utils/Project/NumberPrefix.d.mts +1 -1
- package/Utils/Project/NumberPrefix.d.ts +1 -1
- package/Utils/Project/NumberPrefix.js +12 -0
- package/Utils/Schema/AnalyticsModelSchema.d.mts +48 -0
- package/Utils/Schema/AnalyticsModelSchema.d.ts +48 -0
- package/Utils/Schema/AnalyticsModelSchema.js +767 -0
- package/Utils/Schema/AnalyticsModelSchema.mjs +2 -0
- package/Utils/Schema/BaseSchema.d.mts +117 -0
- package/Utils/Schema/BaseSchema.d.ts +117 -0
- package/Utils/Schema/BaseSchema.js +257 -0
- package/Utils/Schema/BaseSchema.mjs +3 -0
- package/Utils/Schema/ModelSchema.d.mts +80 -0
- package/Utils/Schema/ModelSchema.d.ts +80 -0
- package/Utils/Schema/ModelSchema.js +1727 -0
- package/Utils/Schema/ModelSchema.mjs +2 -0
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.d.mts +0 -1
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.d.ts +0 -1
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.js +9 -25
- package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.mjs +0 -1
- package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.d.mts +1 -1
- package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.d.ts +1 -1
- package/Utils/SecurityEvent/Connectors/EntraIdNormalizer.js +7 -6
- package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.d.mts +1 -1
- package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.d.ts +1 -1
- package/Utils/SecurityEvent/Connectors/GoogleWorkspaceNormalizer.js +10 -9
- package/Utils/SecurityEvent/Connectors/Microsoft365AuditNormalizer.js +4 -3
- package/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdrNormalizer.js +12 -28
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.d.mts +1 -1
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.d.ts +1 -1
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.js +13 -24
- package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.mjs +1 -1
- package/Utils/SecurityEvent/Connectors/OktaNormalizer.d.mts +2 -2
- package/Utils/SecurityEvent/Connectors/OktaNormalizer.d.ts +2 -2
- package/Utils/SecurityEvent/Connectors/OktaNormalizer.js +7 -6
- package/Utils/SecurityEvent/Connectors/SplunkNormalizer.js +7 -26
- package/Utils/SecurityEvent/LogParsers/AzureActivityLogParser.js +4 -3
- package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.d.mts +2 -2
- package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.d.ts +2 -2
- package/Utils/SecurityEvent/LogParsers/WindowsEventLogParser.js +26 -16
- package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.d.mts +1 -1
- package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.d.ts +1 -1
- package/Utils/SecurityEvent/LogParsers/WindowsEventRecord.js +10 -6
- package/Utils/SecurityEvent/SecurityEventNormalizer.js +17 -11
- package/Utils/SecurityEvent/SecurityEventSearch.js +8 -1
- package/Utils/SecurityEvent/Sigma/SigmaRuleSetParser.js +4 -5
- package/Utils/SecurityEvent/ThreatIntel/StixPatternParser.js +7 -3
- package/Utils/SecurityEvent/UdmNormalizer.js +10 -6
- package/Utils/Telemetry/SavedViewDefault.js +4 -3
- package/Utils/Telemetry/SavedViewScope.d.mts +33 -0
- package/Utils/Telemetry/SavedViewScope.d.ts +33 -0
- package/Utils/Telemetry/SavedViewScope.js +105 -0
- package/Utils/Telemetry/SavedViewScope.mjs +7 -0
- package/package.json +1 -11
- package/UI/Utils/TranslateTemplate.d.mts +0 -8
- package/UI/Utils/TranslateTemplate.d.ts +0 -8
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CliValueError = exports.CLI_NOTE_TARGETS = exports.CLI_NOTE_COLUMN = exports.CLI_STATE_MACHINES = exports.CLI_RESERVED_FLAGS = exports.CLI_ACTIONS = exports.CliAction = exports.CLI_FIELDS_SUBCOMMAND = exports.CLI_OPERATIONS = exports.CliOperation = exports.CLI_MINIMUM_NODE_MAJOR_VERSION = exports.ONEUPTIME_URL_ENVIRONMENT_VARIABLE = exports.ONEUPTIME_CLI_PACKAGE = exports.ONEUPTIME_CLI_COMMAND = void 0;
|
|
7
|
+
exports.toCliCommandName = toCliCommandName;
|
|
8
|
+
exports.getCliResourceName = getCliResourceName;
|
|
9
|
+
exports.toCliFlag = toCliFlag;
|
|
10
|
+
exports.toCommanderAttributeName = toCommanderAttributeName;
|
|
11
|
+
exports.isCliServerSetColumn = isCliServerSetColumn;
|
|
12
|
+
exports.getCliDatabaseOperations = getCliDatabaseOperations;
|
|
13
|
+
exports.getCliDatabaseOperationsOf = getCliDatabaseOperationsOf;
|
|
14
|
+
exports.isAnalyticsModelInPublicApi = isAnalyticsModelInPublicApi;
|
|
15
|
+
exports.getCliAnalyticsOperations = getCliAnalyticsOperations;
|
|
16
|
+
exports.getCliAnalyticsOperationsOf = getCliAnalyticsOperationsOf;
|
|
17
|
+
exports.getCliStateMachine = getCliStateMachine;
|
|
18
|
+
exports.getCliNoteTarget = getCliNoteTarget;
|
|
19
|
+
exports.getModelApiPathOf = getModelApiPathOf;
|
|
20
|
+
exports.getCliActions = getCliActions;
|
|
21
|
+
exports.isCliFieldFlagAllowed = isCliFieldFlagAllowed;
|
|
22
|
+
exports.getCliFieldFlags = getCliFieldFlags;
|
|
23
|
+
exports.getCliFieldFlagsFor = getCliFieldFlagsFor;
|
|
24
|
+
exports.getCliFieldFlagHelp = getCliFieldFlagHelp;
|
|
25
|
+
exports.parseCliList = parseCliList;
|
|
26
|
+
exports.parseCliFieldValue = parseCliFieldValue;
|
|
27
|
+
exports.getCliAnalyticsFields = getCliAnalyticsFields;
|
|
28
|
+
exports.isAnalyticsColumnReadable = isAnalyticsColumnReadable;
|
|
29
|
+
const AlertEpisodeInternalNote_1 = __importDefault(require("../../Models/DatabaseModels/AlertEpisodeInternalNote"));
|
|
30
|
+
const AlertEpisodeStateTimeline_1 = __importDefault(require("../../Models/DatabaseModels/AlertEpisodeStateTimeline"));
|
|
31
|
+
const AlertInternalNote_1 = __importDefault(require("../../Models/DatabaseModels/AlertInternalNote"));
|
|
32
|
+
const AlertState_1 = __importDefault(require("../../Models/DatabaseModels/AlertState"));
|
|
33
|
+
const AlertStateTimeline_1 = __importDefault(require("../../Models/DatabaseModels/AlertStateTimeline"));
|
|
34
|
+
const IncidentEpisodeInternalNote_1 = __importDefault(require("../../Models/DatabaseModels/IncidentEpisodeInternalNote"));
|
|
35
|
+
const IncidentEpisodePublicNote_1 = __importDefault(require("../../Models/DatabaseModels/IncidentEpisodePublicNote"));
|
|
36
|
+
const IncidentEpisodeStateTimeline_1 = __importDefault(require("../../Models/DatabaseModels/IncidentEpisodeStateTimeline"));
|
|
37
|
+
const IncidentInternalNote_1 = __importDefault(require("../../Models/DatabaseModels/IncidentInternalNote"));
|
|
38
|
+
const IncidentPublicNote_1 = __importDefault(require("../../Models/DatabaseModels/IncidentPublicNote"));
|
|
39
|
+
const IncidentState_1 = __importDefault(require("../../Models/DatabaseModels/IncidentState"));
|
|
40
|
+
const IncidentStateTimeline_1 = __importDefault(require("../../Models/DatabaseModels/IncidentStateTimeline"));
|
|
41
|
+
const ScheduledMaintenanceInternalNote_1 = __importDefault(require("../../Models/DatabaseModels/ScheduledMaintenanceInternalNote"));
|
|
42
|
+
const ScheduledMaintenancePublicNote_1 = __importDefault(require("../../Models/DatabaseModels/ScheduledMaintenancePublicNote"));
|
|
43
|
+
const ScheduledMaintenanceState_1 = __importDefault(require("../../Models/DatabaseModels/ScheduledMaintenanceState"));
|
|
44
|
+
const ScheduledMaintenanceStateTimeline_1 = __importDefault(require("../../Models/DatabaseModels/ScheduledMaintenanceStateTimeline"));
|
|
45
|
+
const TableColumnType_1 = __importDefault(require("../../Types/Database/TableColumnType"));
|
|
46
|
+
const HeldPermissions_1 = require("../../Types/HeldPermissions");
|
|
47
|
+
const ObjectID_1 = __importDefault(require("../../Types/ObjectID"));
|
|
48
|
+
const StateOrder_1 = require("../StateOrder");
|
|
49
|
+
const ClientResourceNames_1 = require("./ClientResourceNames");
|
|
50
|
+
const PeopleByEmail_1 = require("./PeopleByEmail");
|
|
51
|
+
const TerraformSchema_1 = require("./TerraformSchema");
|
|
52
|
+
/*
|
|
53
|
+
* THE ONEUPTIME CLI'S COMMANDS, WORKED OUT FROM THE MODELS
|
|
54
|
+
*
|
|
55
|
+
* The CLI (packages/CLI, `oneuptime`) has a command for every resource of
|
|
56
|
+
* the OneUptime REST API, and a subcommand for every request the API
|
|
57
|
+
* takes for it - the very rule the API documents itself by
|
|
58
|
+
* (Common/Server/Utils/OpenAPI.ts) and the Terraform provider is generated
|
|
59
|
+
* from (TerraformSchema.ts repeats it one model at a time):
|
|
60
|
+
*
|
|
61
|
+
* - a record (a database model) has a command when it is documented and
|
|
62
|
+
* has an API path; telemetry (an analytics model) when it has an API
|
|
63
|
+
* path;
|
|
64
|
+
* - it has list, get and count when someone other than a signed-in user
|
|
65
|
+
* alone may read it, create when someone may create it, and so on for
|
|
66
|
+
* update and delete (isApiExcludedForPermissions);
|
|
67
|
+
* - the command is the provider's type name in kebab case: Terraform's
|
|
68
|
+
* oneuptime_on_call_policy is `oneuptime on-call-policy`, its
|
|
69
|
+
* oneuptime_iot_fleet `oneuptime iot-fleet`;
|
|
70
|
+
* - create and update take a flag for each field the API's create or
|
|
71
|
+
* update schema has, named for the field in kebab case
|
|
72
|
+
* (`incidentSeverityId` is `--incident-severity-id`), and a person is
|
|
73
|
+
* named by email address as well as by ID (`--user-email` beside
|
|
74
|
+
* `--user-id`), with the provider's words (PeopleByEmail.ts).
|
|
75
|
+
*
|
|
76
|
+
* So a new model gets its commands, its flags and its page in the
|
|
77
|
+
* dashboard without a line of the CLI changing. The CLI reads this file to
|
|
78
|
+
* build its program; the dashboard's Developer > CLI pages read it to write
|
|
79
|
+
* commands the CLI really takes; the docs' command reference reads it for
|
|
80
|
+
* the list of resource commands. packages/CLI/Tests/ApiParity builds the
|
|
81
|
+
* real OpenAPI spec and fails when the API has a request the CLI has no
|
|
82
|
+
* command for.
|
|
83
|
+
*
|
|
84
|
+
* Pure: no request is made here, so the dashboard and the docs use it too.
|
|
85
|
+
*/
|
|
86
|
+
// The command the CLI installs, and the package it is published as.
|
|
87
|
+
exports.ONEUPTIME_CLI_COMMAND = "oneuptime";
|
|
88
|
+
exports.ONEUPTIME_CLI_PACKAGE = "@oneuptime/cli";
|
|
89
|
+
// The environment variable the CLI reads OneUptime's address from.
|
|
90
|
+
exports.ONEUPTIME_URL_ENVIRONMENT_VARIABLE = "ONEUPTIME_URL";
|
|
91
|
+
// The oldest Node.js the CLI runs on (its package.json's engines).
|
|
92
|
+
exports.CLI_MINIMUM_NODE_MAJOR_VERSION = 22;
|
|
93
|
+
var CliOperation;
|
|
94
|
+
(function (CliOperation) {
|
|
95
|
+
CliOperation["List"] = "list";
|
|
96
|
+
CliOperation["Get"] = "get";
|
|
97
|
+
CliOperation["Create"] = "create";
|
|
98
|
+
CliOperation["Update"] = "update";
|
|
99
|
+
CliOperation["Delete"] = "delete";
|
|
100
|
+
CliOperation["Count"] = "count";
|
|
101
|
+
})(CliOperation || (exports.CliOperation = CliOperation = {}));
|
|
102
|
+
// The order the CLI adds a resource's operations in, as it always has.
|
|
103
|
+
exports.CLI_OPERATIONS = [
|
|
104
|
+
CliOperation.List,
|
|
105
|
+
CliOperation.Get,
|
|
106
|
+
CliOperation.Create,
|
|
107
|
+
CliOperation.Update,
|
|
108
|
+
CliOperation.Delete,
|
|
109
|
+
CliOperation.Count,
|
|
110
|
+
];
|
|
111
|
+
/*
|
|
112
|
+
* The subcommand every resource has that asks OneUptime nothing: the
|
|
113
|
+
* fields a resource has, what each is, and the flag that sets it.
|
|
114
|
+
*/
|
|
115
|
+
exports.CLI_FIELDS_SUBCOMMAND = "fields";
|
|
116
|
+
/*
|
|
117
|
+
* What the dashboard's buttons do on a record, as commands of their own:
|
|
118
|
+
* Acknowledge and Resolve on incidents, alerts and their episodes, Mark
|
|
119
|
+
* Ongoing and End on scheduled maintenance, and a note on any of them.
|
|
120
|
+
*/
|
|
121
|
+
var CliAction;
|
|
122
|
+
(function (CliAction) {
|
|
123
|
+
CliAction["Acknowledge"] = "acknowledge";
|
|
124
|
+
CliAction["Resolve"] = "resolve";
|
|
125
|
+
CliAction["Start"] = "start";
|
|
126
|
+
CliAction["End"] = "end";
|
|
127
|
+
CliAction["AddNote"] = "add-note";
|
|
128
|
+
})(CliAction || (exports.CliAction = CliAction = {}));
|
|
129
|
+
// The order a resource's actions come in, after its operations and fields.
|
|
130
|
+
exports.CLI_ACTIONS = [
|
|
131
|
+
CliAction.Acknowledge,
|
|
132
|
+
CliAction.Resolve,
|
|
133
|
+
CliAction.Start,
|
|
134
|
+
CliAction.End,
|
|
135
|
+
CliAction.AddNote,
|
|
136
|
+
];
|
|
137
|
+
/*
|
|
138
|
+
* NAMES
|
|
139
|
+
*/
|
|
140
|
+
const UNDERSCORES = /_/g;
|
|
141
|
+
/*
|
|
142
|
+
* A resource's command: the Terraform provider's type name in kebab case.
|
|
143
|
+
* "On-Call Policy" -> on-call-policy, "IoT Fleet" -> iot-fleet,
|
|
144
|
+
* "VMware vCenter" -> vcenter (the provider's oneuptime_vcenter).
|
|
145
|
+
*/
|
|
146
|
+
function toCliCommandName(singularName) {
|
|
147
|
+
return (0, TerraformSchema_1.toTerraformTypeSnakeCase)(singularName).replace(UNDERSCORES, "-");
|
|
148
|
+
}
|
|
149
|
+
/*
|
|
150
|
+
* A model's command: `incident`, `on-call-policy`. It is the name every
|
|
151
|
+
* client OneUptime publishes gives the model (ClientResourceNames): its
|
|
152
|
+
* singular name, or for the few worded for a screen rather than a
|
|
153
|
+
* resource, a name of their own - `escalation-rule-team`, as the Terraform
|
|
154
|
+
* provider's oneuptime_escalation_rule_team. No two models share one, so
|
|
155
|
+
* no two resources share a command (packages/CLI/Tests/ApiParity).
|
|
156
|
+
*/
|
|
157
|
+
function getCliResourceName(model) {
|
|
158
|
+
const tableName = model.tableName || "";
|
|
159
|
+
return toCliCommandName((0, ClientResourceNames_1.getClientResourceName)(tableName, model.singularName || tableName));
|
|
160
|
+
}
|
|
161
|
+
// A field's flag: incidentSeverityId -> --incident-severity-id.
|
|
162
|
+
function toCliFlag(columnName) {
|
|
163
|
+
return `--${(0, TerraformSchema_1.toTerraformSnakeCase)(columnName).replace(UNDERSCORES, "-")}`;
|
|
164
|
+
}
|
|
165
|
+
/*
|
|
166
|
+
* The column a flag sets, as Commander names its value: --incident-
|
|
167
|
+
* severity-id is `incidentSeverityId` in a command's options.
|
|
168
|
+
*/
|
|
169
|
+
function toCommanderAttributeName(flag) {
|
|
170
|
+
return flag
|
|
171
|
+
.replace(LEADING_DASHES, "")
|
|
172
|
+
.split("-")
|
|
173
|
+
.map((part, index) => {
|
|
174
|
+
return index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1);
|
|
175
|
+
})
|
|
176
|
+
.join("");
|
|
177
|
+
}
|
|
178
|
+
const LEADING_DASHES = /^-+/;
|
|
179
|
+
/*
|
|
180
|
+
* Flags the CLI uses for itself, which no field may take: the global ones
|
|
181
|
+
* (`--url` is OneUptime's address, `--api-key` the key), and those create
|
|
182
|
+
* and update read their data from. A field of one of these names is set in
|
|
183
|
+
* --data instead: a data source's url, an LLM provider's apiKey, a file's
|
|
184
|
+
* file. `--color` is a field's (labels, states, severities have a color):
|
|
185
|
+
* the program's own is `--no-color`, a flag of another name.
|
|
186
|
+
*/
|
|
187
|
+
exports.CLI_RESERVED_FLAGS = [
|
|
188
|
+
"--api-key",
|
|
189
|
+
"--url",
|
|
190
|
+
"--context",
|
|
191
|
+
"--output",
|
|
192
|
+
"--json",
|
|
193
|
+
"--no-color",
|
|
194
|
+
"--version",
|
|
195
|
+
"--help",
|
|
196
|
+
"--data",
|
|
197
|
+
"--file",
|
|
198
|
+
];
|
|
199
|
+
/*
|
|
200
|
+
* Columns the server fills in, which no flag sets: the project comes from
|
|
201
|
+
* the API key, and who created or deleted a record from the request.
|
|
202
|
+
*/
|
|
203
|
+
const SERVER_SET_COLUMNS = [
|
|
204
|
+
"projectId",
|
|
205
|
+
"createdByUserId",
|
|
206
|
+
"deletedByUserId",
|
|
207
|
+
];
|
|
208
|
+
// Whether the server fills a column in, whatever a create or an update sends.
|
|
209
|
+
function isCliServerSetColumn(columnName) {
|
|
210
|
+
return SERVER_SET_COLUMNS.includes(columnName);
|
|
211
|
+
}
|
|
212
|
+
/*
|
|
213
|
+
* OPERATIONS
|
|
214
|
+
*/
|
|
215
|
+
function operationsFrom(operations) {
|
|
216
|
+
return exports.CLI_OPERATIONS.filter((operation) => {
|
|
217
|
+
switch (operation) {
|
|
218
|
+
case CliOperation.List:
|
|
219
|
+
case CliOperation.Get:
|
|
220
|
+
case CliOperation.Count:
|
|
221
|
+
return operations.canRead;
|
|
222
|
+
case CliOperation.Create:
|
|
223
|
+
return operations.canCreate;
|
|
224
|
+
case CliOperation.Update:
|
|
225
|
+
return operations.canUpdate;
|
|
226
|
+
case CliOperation.Delete:
|
|
227
|
+
return operations.canDelete;
|
|
228
|
+
default:
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/*
|
|
234
|
+
* A record's operations: the requests the API documents for it. None when
|
|
235
|
+
* it is not in the API, and none for a record only its own user may read
|
|
236
|
+
* (a user's sessions, their two-factor keys): an API key reaches none of
|
|
237
|
+
* those, so the CLI makes no command a key could never run.
|
|
238
|
+
*/
|
|
239
|
+
function getCliDatabaseOperations(modelType) {
|
|
240
|
+
return getCliDatabaseOperationsOf(new modelType());
|
|
241
|
+
}
|
|
242
|
+
/*
|
|
243
|
+
* The same, from a model already made: the CLI works this out for every
|
|
244
|
+
* model each time it starts, and making each one once saves a tenth of
|
|
245
|
+
* that start. isModelInPublicApi and getTerraformModelOperations, read off
|
|
246
|
+
* the one instance.
|
|
247
|
+
*/
|
|
248
|
+
function getCliDatabaseOperationsOf(model) {
|
|
249
|
+
if (!(model.tableName && model.enableDocumentation && model.crudApiPath)) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
return operationsFrom({
|
|
253
|
+
canCreate: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.createRecordPermissions),
|
|
254
|
+
canRead: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.readRecordPermissions),
|
|
255
|
+
canUpdate: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.updateRecordPermissions),
|
|
256
|
+
canDelete: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.deleteRecordPermissions),
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
// Whether telemetry is in the API at all (OpenAPIUtil.buildOpenAPISpec).
|
|
260
|
+
function isAnalyticsModelInPublicApi(modelType) {
|
|
261
|
+
const model = new modelType();
|
|
262
|
+
return Boolean(model.tableName && model.crudApiPath);
|
|
263
|
+
}
|
|
264
|
+
// Telemetry's operations, by the same rule as a record's.
|
|
265
|
+
function getCliAnalyticsOperations(modelType) {
|
|
266
|
+
return getCliAnalyticsOperationsOf(new modelType());
|
|
267
|
+
}
|
|
268
|
+
// The same, from a model already made.
|
|
269
|
+
function getCliAnalyticsOperationsOf(model) {
|
|
270
|
+
if (!(model.tableName && model.crudApiPath)) {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
return operationsFrom({
|
|
274
|
+
canCreate: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.getCreatePermissions()),
|
|
275
|
+
canRead: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.getReadPermissions()),
|
|
276
|
+
canUpdate: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.getUpdatePermissions()),
|
|
277
|
+
canDelete: !(0, TerraformSchema_1.isApiExcludedForPermissions)(model.getDeletePermissions()),
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const ACKNOWLEDGE = {
|
|
281
|
+
action: CliAction.Acknowledge,
|
|
282
|
+
stateFlag: "isAcknowledgedState",
|
|
283
|
+
description: "moves it to the project's acknowledged state, as the Acknowledge button does",
|
|
284
|
+
};
|
|
285
|
+
const RESOLVE = {
|
|
286
|
+
action: CliAction.Resolve,
|
|
287
|
+
stateFlag: "isResolvedState",
|
|
288
|
+
description: "moves it to the project's resolved state, as the Resolve button does",
|
|
289
|
+
};
|
|
290
|
+
exports.CLI_STATE_MACHINES = [
|
|
291
|
+
{
|
|
292
|
+
tableName: "Incident",
|
|
293
|
+
stateModelType: IncidentState_1.default,
|
|
294
|
+
timelineModelType: IncidentStateTimeline_1.default,
|
|
295
|
+
recordColumn: "incidentId",
|
|
296
|
+
stateColumn: "incidentStateId",
|
|
297
|
+
currentStateRelation: "currentIncidentState",
|
|
298
|
+
stateList: StateOrder_1.StateListType.IncidentState,
|
|
299
|
+
changes: [ACKNOWLEDGE, RESOLVE],
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
tableName: "Alert",
|
|
303
|
+
stateModelType: AlertState_1.default,
|
|
304
|
+
timelineModelType: AlertStateTimeline_1.default,
|
|
305
|
+
recordColumn: "alertId",
|
|
306
|
+
stateColumn: "alertStateId",
|
|
307
|
+
currentStateRelation: "currentAlertState",
|
|
308
|
+
stateList: StateOrder_1.StateListType.AlertState,
|
|
309
|
+
changes: [ACKNOWLEDGE, RESOLVE],
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
tableName: "IncidentEpisode",
|
|
313
|
+
stateModelType: IncidentState_1.default,
|
|
314
|
+
timelineModelType: IncidentEpisodeStateTimeline_1.default,
|
|
315
|
+
recordColumn: "incidentEpisodeId",
|
|
316
|
+
stateColumn: "incidentStateId",
|
|
317
|
+
currentStateRelation: "currentIncidentState",
|
|
318
|
+
stateList: StateOrder_1.StateListType.IncidentState,
|
|
319
|
+
changes: [ACKNOWLEDGE, RESOLVE],
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
tableName: "AlertEpisode",
|
|
323
|
+
stateModelType: AlertState_1.default,
|
|
324
|
+
timelineModelType: AlertEpisodeStateTimeline_1.default,
|
|
325
|
+
recordColumn: "alertEpisodeId",
|
|
326
|
+
stateColumn: "alertStateId",
|
|
327
|
+
currentStateRelation: "currentAlertState",
|
|
328
|
+
stateList: StateOrder_1.StateListType.AlertState,
|
|
329
|
+
changes: [ACKNOWLEDGE, RESOLVE],
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
tableName: "ScheduledMaintenance",
|
|
333
|
+
stateModelType: ScheduledMaintenanceState_1.default,
|
|
334
|
+
timelineModelType: ScheduledMaintenanceStateTimeline_1.default,
|
|
335
|
+
recordColumn: "scheduledMaintenanceId",
|
|
336
|
+
stateColumn: "scheduledMaintenanceStateId",
|
|
337
|
+
currentStateRelation: "currentScheduledMaintenanceState",
|
|
338
|
+
stateList: StateOrder_1.StateListType.ScheduledMaintenanceState,
|
|
339
|
+
changes: [
|
|
340
|
+
{
|
|
341
|
+
action: CliAction.Start,
|
|
342
|
+
stateFlag: "isOngoingState",
|
|
343
|
+
description: "moves it to the project's ongoing state, as the Mark Ongoing button does",
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
action: CliAction.End,
|
|
347
|
+
stateFlag: "isEndedState",
|
|
348
|
+
description: "moves it to the project's ended state, as the End button does",
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
},
|
|
352
|
+
];
|
|
353
|
+
// The note's text, in every note model.
|
|
354
|
+
exports.CLI_NOTE_COLUMN = "note";
|
|
355
|
+
exports.CLI_NOTE_TARGETS = [
|
|
356
|
+
{
|
|
357
|
+
tableName: "Incident",
|
|
358
|
+
internalNoteModelType: IncidentInternalNote_1.default,
|
|
359
|
+
publicNoteModelType: IncidentPublicNote_1.default,
|
|
360
|
+
recordColumn: "incidentId",
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
tableName: "Alert",
|
|
364
|
+
internalNoteModelType: AlertInternalNote_1.default,
|
|
365
|
+
recordColumn: "alertId",
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
tableName: "IncidentEpisode",
|
|
369
|
+
internalNoteModelType: IncidentEpisodeInternalNote_1.default,
|
|
370
|
+
publicNoteModelType: IncidentEpisodePublicNote_1.default,
|
|
371
|
+
recordColumn: "incidentEpisodeId",
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
tableName: "AlertEpisode",
|
|
375
|
+
internalNoteModelType: AlertEpisodeInternalNote_1.default,
|
|
376
|
+
recordColumn: "alertEpisodeId",
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
tableName: "ScheduledMaintenance",
|
|
380
|
+
internalNoteModelType: ScheduledMaintenanceInternalNote_1.default,
|
|
381
|
+
publicNoteModelType: ScheduledMaintenancePublicNote_1.default,
|
|
382
|
+
recordColumn: "scheduledMaintenanceId",
|
|
383
|
+
},
|
|
384
|
+
];
|
|
385
|
+
function getCliStateMachine(tableName) {
|
|
386
|
+
return exports.CLI_STATE_MACHINES.find((machine) => {
|
|
387
|
+
return machine.tableName === tableName;
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
function getCliNoteTarget(tableName) {
|
|
391
|
+
return exports.CLI_NOTE_TARGETS.find((target) => {
|
|
392
|
+
return target.tableName === tableName;
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
// The model's API path: `/incident-state-timeline`.
|
|
396
|
+
function getModelApiPathOf(modelType) {
|
|
397
|
+
var _a;
|
|
398
|
+
const path = ((_a = new modelType().crudApiPath) === null || _a === void 0 ? void 0 : _a.toString()) || "";
|
|
399
|
+
return `/${path.replace(LEADING_SLASHES, "")}`;
|
|
400
|
+
}
|
|
401
|
+
const LEADING_SLASHES = /^\/+/;
|
|
402
|
+
/*
|
|
403
|
+
* The actions a record has, in their order: its state changes and its
|
|
404
|
+
* notes, each only when the API lets a key make the row it writes.
|
|
405
|
+
*/
|
|
406
|
+
function getCliActions(tableName) {
|
|
407
|
+
const actions = [];
|
|
408
|
+
const machine = getCliStateMachine(tableName);
|
|
409
|
+
if (machine &&
|
|
410
|
+
(0, TerraformSchema_1.getTerraformModelOperations)(machine.timelineModelType).canCreate) {
|
|
411
|
+
actions.push(...machine.changes.map((change) => {
|
|
412
|
+
return change.action;
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
const notes = getCliNoteTarget(tableName);
|
|
416
|
+
if (notes &&
|
|
417
|
+
(0, TerraformSchema_1.getTerraformModelOperations)(notes.internalNoteModelType).canCreate) {
|
|
418
|
+
actions.push(CliAction.AddNote);
|
|
419
|
+
}
|
|
420
|
+
return exports.CLI_ACTIONS.filter((action) => {
|
|
421
|
+
return actions.includes(action);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function getValueName(descriptor) {
|
|
425
|
+
switch (descriptor.kind) {
|
|
426
|
+
case TerraformSchema_1.TerraformValueKind.Number:
|
|
427
|
+
return "<number>";
|
|
428
|
+
case TerraformSchema_1.TerraformValueKind.Bool:
|
|
429
|
+
return "[true|false]";
|
|
430
|
+
case TerraformSchema_1.TerraformValueKind.DateTime:
|
|
431
|
+
return "<date>";
|
|
432
|
+
case TerraformSchema_1.TerraformValueKind.IdSet:
|
|
433
|
+
return "<ids>";
|
|
434
|
+
case TerraformSchema_1.TerraformValueKind.StringSet:
|
|
435
|
+
return "<values>";
|
|
436
|
+
case TerraformSchema_1.TerraformValueKind.Json:
|
|
437
|
+
case TerraformSchema_1.TerraformValueKind.MonitorSteps:
|
|
438
|
+
return "<json>";
|
|
439
|
+
default:
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
if (descriptor.columnType === TableColumnType_1.default.ObjectID ||
|
|
443
|
+
descriptor.relatedModelType) {
|
|
444
|
+
return "<id>";
|
|
445
|
+
}
|
|
446
|
+
return VALUE_NAMES_BY_TYPE[descriptor.columnType] || "<text>";
|
|
447
|
+
}
|
|
448
|
+
// What a text flag of these types takes, in its help.
|
|
449
|
+
const VALUE_NAMES_BY_TYPE = {
|
|
450
|
+
[TableColumnType_1.default.Color]: "<color>",
|
|
451
|
+
[TableColumnType_1.default.Email]: "<email>",
|
|
452
|
+
[TableColumnType_1.default.ShortURL]: "<url>",
|
|
453
|
+
[TableColumnType_1.default.LongURL]: "<url>",
|
|
454
|
+
[TableColumnType_1.default.Phone]: "<phone>",
|
|
455
|
+
[TableColumnType_1.default.Domain]: "<domain>",
|
|
456
|
+
};
|
|
457
|
+
/*
|
|
458
|
+
* A flag that opens with --no- turns its option off in Commander
|
|
459
|
+
* (--no-color sets color to false), so a field named noReply has no flag:
|
|
460
|
+
* it is set in --data.
|
|
461
|
+
*/
|
|
462
|
+
const NEGATED_FLAG_PREFIX = "--no-";
|
|
463
|
+
// Whether a flag is one a field may take.
|
|
464
|
+
function isCliFieldFlagAllowed(flag) {
|
|
465
|
+
return (!exports.CLI_RESERVED_FLAGS.includes(flag) && !flag.startsWith(NEGATED_FLAG_PREFIX));
|
|
466
|
+
}
|
|
467
|
+
/*
|
|
468
|
+
* Whether a field can have a flag: a value the command line can write (not
|
|
469
|
+
* a file's bytes), filled in by the caller rather than the server, and of a
|
|
470
|
+
* name the CLI does not use itself.
|
|
471
|
+
*/
|
|
472
|
+
function canHaveFlag(descriptor) {
|
|
473
|
+
return (descriptor.kind !== TerraformSchema_1.TerraformValueKind.Unsupported &&
|
|
474
|
+
!isCliServerSetColumn(descriptor.columnName) &&
|
|
475
|
+
isCliFieldFlagAllowed(toCliFlag(descriptor.columnName)));
|
|
476
|
+
}
|
|
477
|
+
function getRelatedResource(descriptor) {
|
|
478
|
+
if (!descriptor.relatedModelType) {
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
481
|
+
const related = new descriptor.relatedModelType();
|
|
482
|
+
if (getCliDatabaseOperations(descriptor.relatedModelType).length === 0) {
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
return getCliResourceName(related);
|
|
486
|
+
}
|
|
487
|
+
function getPersonFlag(descriptor, idFlag) {
|
|
488
|
+
if (!descriptor.personEmail) {
|
|
489
|
+
return undefined;
|
|
490
|
+
}
|
|
491
|
+
const isList = descriptor.personEmail.isList;
|
|
492
|
+
const columnName = (0, PeopleByEmail_1.getPersonEmailColumnName)(descriptor.columnName, isList ? PeopleByEmail_1.PersonColumnKind.Many : PeopleByEmail_1.PersonColumnKind.One);
|
|
493
|
+
const flag = toCliFlag(columnName);
|
|
494
|
+
if (!isCliFieldFlagAllowed(flag)) {
|
|
495
|
+
return undefined;
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
columnName,
|
|
499
|
+
flag,
|
|
500
|
+
valueName: isList ? "<emails>" : "<email>",
|
|
501
|
+
isList,
|
|
502
|
+
invitesByEmail: descriptor.personEmail.invitesByEmail,
|
|
503
|
+
description: (0, PeopleByEmail_1.describePersonEmail)({
|
|
504
|
+
idName: idFlag,
|
|
505
|
+
isList,
|
|
506
|
+
invitesByEmail: descriptor.personEmail.invitesByEmail,
|
|
507
|
+
}),
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
const LINE_BREAKS = /\s+/g;
|
|
511
|
+
// What a field is for, on one line: the model's words, or its title.
|
|
512
|
+
function describeField(descriptor) {
|
|
513
|
+
const text = (descriptor.description || descriptor.title || "")
|
|
514
|
+
.replace(LINE_BREAKS, " ")
|
|
515
|
+
.trim();
|
|
516
|
+
return text;
|
|
517
|
+
}
|
|
518
|
+
/*
|
|
519
|
+
* Every field create and update take a flag for, in the order the model
|
|
520
|
+
* declares them: the provider's attributes (TerraformSchema), so the API's
|
|
521
|
+
* create and update schemas, less the ones the server fills in, those the
|
|
522
|
+
* command line cannot write and those whose name the CLI uses itself.
|
|
523
|
+
*/
|
|
524
|
+
function getCliFieldFlags(modelType) {
|
|
525
|
+
const flags = [];
|
|
526
|
+
const seen = new Set();
|
|
527
|
+
for (const descriptor of (0, TerraformSchema_1.getTerraformAttributes)(modelType)) {
|
|
528
|
+
if (!canHaveFlag(descriptor)) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
const flag = toCliFlag(descriptor.columnName);
|
|
532
|
+
// Two columns of one name in kebab case: the first keeps the flag.
|
|
533
|
+
if (seen.has(flag)) {
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
seen.add(flag);
|
|
537
|
+
const person = getPersonFlag(descriptor, flag);
|
|
538
|
+
if (person) {
|
|
539
|
+
seen.add(person.flag);
|
|
540
|
+
}
|
|
541
|
+
flags.push({
|
|
542
|
+
columnName: descriptor.columnName,
|
|
543
|
+
flag,
|
|
544
|
+
valueName: getValueName(descriptor),
|
|
545
|
+
kind: descriptor.kind,
|
|
546
|
+
columnType: descriptor.columnType,
|
|
547
|
+
isRequired: descriptor.isRequired,
|
|
548
|
+
inCreate: descriptor.inCreateSchema,
|
|
549
|
+
inUpdate: descriptor.inUpdateSchema,
|
|
550
|
+
description: describeField(descriptor),
|
|
551
|
+
relatedResource: getRelatedResource(descriptor),
|
|
552
|
+
isSecret: Boolean(descriptor.secretKind),
|
|
553
|
+
person,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
return flags;
|
|
557
|
+
}
|
|
558
|
+
// The flags a create (or an update) takes.
|
|
559
|
+
function getCliFieldFlagsFor(modelType, operation) {
|
|
560
|
+
return getCliFieldFlags(modelType).filter((flag) => {
|
|
561
|
+
return operation === CliOperation.Create ? flag.inCreate : flag.inUpdate;
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
/*
|
|
565
|
+
* A flag's help: what the field is for, then what the flag takes - an ID
|
|
566
|
+
* of which resource, IDs separated by commas, JSON - and whether a create
|
|
567
|
+
* must give it.
|
|
568
|
+
*/
|
|
569
|
+
function getCliFieldFlagHelp(flag, operation) {
|
|
570
|
+
const parts = [];
|
|
571
|
+
if (operation === CliOperation.Create && flag.isRequired) {
|
|
572
|
+
parts.push(flag.person ? `Required, or ${flag.person.flag}.` : "Required.");
|
|
573
|
+
}
|
|
574
|
+
if (flag.description) {
|
|
575
|
+
parts.push(withFullStop(flag.description));
|
|
576
|
+
}
|
|
577
|
+
switch (flag.kind) {
|
|
578
|
+
case TerraformSchema_1.TerraformValueKind.IdSet:
|
|
579
|
+
parts.push(flag.relatedResource
|
|
580
|
+
? `IDs separated by commas, from \`${exports.ONEUPTIME_CLI_COMMAND} ${flag.relatedResource} list\`.`
|
|
581
|
+
: "IDs separated by commas.");
|
|
582
|
+
break;
|
|
583
|
+
case TerraformSchema_1.TerraformValueKind.StringSet:
|
|
584
|
+
parts.push("Values separated by commas, or a JSON array.");
|
|
585
|
+
break;
|
|
586
|
+
case TerraformSchema_1.TerraformValueKind.Json:
|
|
587
|
+
case TerraformSchema_1.TerraformValueKind.MonitorSteps:
|
|
588
|
+
parts.push("JSON.");
|
|
589
|
+
break;
|
|
590
|
+
case TerraformSchema_1.TerraformValueKind.DateTime:
|
|
591
|
+
parts.push("A date and time, such as 2026-11-01T10:00:00Z.");
|
|
592
|
+
break;
|
|
593
|
+
default:
|
|
594
|
+
if (flag.relatedResource) {
|
|
595
|
+
parts.push(`An ID from \`${exports.ONEUPTIME_CLI_COMMAND} ${flag.relatedResource} list\`.`);
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
if (flag.isSecret) {
|
|
600
|
+
parts.push("Secret: OneUptime never shows it again.");
|
|
601
|
+
}
|
|
602
|
+
return parts.join(" ");
|
|
603
|
+
}
|
|
604
|
+
const ENDS_WITH_PUNCTUATION = /[.!?)]$/;
|
|
605
|
+
function withFullStop(text) {
|
|
606
|
+
return ENDS_WITH_PUNCTUATION.test(text) ? text : `${text}.`;
|
|
607
|
+
}
|
|
608
|
+
/*
|
|
609
|
+
* VALUES
|
|
610
|
+
*/
|
|
611
|
+
// A value a flag cannot take, said the way the person fixes it.
|
|
612
|
+
class CliValueError extends Error {
|
|
613
|
+
}
|
|
614
|
+
exports.CliValueError = CliValueError;
|
|
615
|
+
const TRUE_WORDS = ["true", "yes", "1", "on"];
|
|
616
|
+
const FALSE_WORDS = ["false", "no", "0", "off"];
|
|
617
|
+
const LIST_SEPARATOR = ",";
|
|
618
|
+
// "a, b,c" or '["a","b"]' -> ["a", "b", "c"]; "" -> [].
|
|
619
|
+
function parseCliList(flag, raw) {
|
|
620
|
+
const text = raw.trim();
|
|
621
|
+
if (text.startsWith("[")) {
|
|
622
|
+
let parsed;
|
|
623
|
+
try {
|
|
624
|
+
parsed = JSON.parse(text);
|
|
625
|
+
}
|
|
626
|
+
catch (_a) {
|
|
627
|
+
throw new CliValueError(`${flag} takes values separated by commas, or a JSON array, and ${JSON.stringify(raw)} is neither.`);
|
|
628
|
+
}
|
|
629
|
+
if (!Array.isArray(parsed) ||
|
|
630
|
+
!parsed.every((item) => {
|
|
631
|
+
return typeof item === "string";
|
|
632
|
+
})) {
|
|
633
|
+
throw new CliValueError(`${flag} takes a JSON array of strings, such as ["a","b"].`);
|
|
634
|
+
}
|
|
635
|
+
return parsed;
|
|
636
|
+
}
|
|
637
|
+
return text
|
|
638
|
+
.split(LIST_SEPARATOR)
|
|
639
|
+
.map((item) => {
|
|
640
|
+
return item.trim();
|
|
641
|
+
})
|
|
642
|
+
.filter((item) => {
|
|
643
|
+
return item.length > 0;
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
function assertIds(flag, ids) {
|
|
647
|
+
for (const id of ids) {
|
|
648
|
+
if (!ObjectID_1.default.isValidUUID(id)) {
|
|
649
|
+
throw new CliValueError(`${flag.flag} takes ${flag.kind === TerraformSchema_1.TerraformValueKind.IdSet ? "IDs" : "an ID"}, such as 6f1c2a40-3b1e-4c55-9a0b-3e2f8d7c1a11, and ${JSON.stringify(id)} is not one.${flag.relatedResource
|
|
650
|
+
? ` Find them with \`${exports.ONEUPTIME_CLI_COMMAND} ${flag.relatedResource} list\`.`
|
|
651
|
+
: ""}`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
/*
|
|
656
|
+
* What a flag's text is as the API takes it: a number for a number, true
|
|
657
|
+
* or false for a switch (the flag alone is true), the records of a list
|
|
658
|
+
* relation as `{"_id": ...}` objects, JSON parsed, a date as ISO 8601.
|
|
659
|
+
* Throws a CliValueError that says what the flag takes.
|
|
660
|
+
*/
|
|
661
|
+
function parseCliFieldValue(flag, raw) {
|
|
662
|
+
if (typeof raw === "boolean") {
|
|
663
|
+
if (flag.kind === TerraformSchema_1.TerraformValueKind.Bool) {
|
|
664
|
+
return raw;
|
|
665
|
+
}
|
|
666
|
+
throw new CliValueError(`${flag.flag} needs a value: ${flag.valueName}.`);
|
|
667
|
+
}
|
|
668
|
+
switch (flag.kind) {
|
|
669
|
+
case TerraformSchema_1.TerraformValueKind.Bool: {
|
|
670
|
+
const word = raw.trim().toLowerCase();
|
|
671
|
+
if (TRUE_WORDS.includes(word)) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
if (FALSE_WORDS.includes(word)) {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
throw new CliValueError(`${flag.flag} takes true or false, and ${JSON.stringify(raw)} is neither.`);
|
|
678
|
+
}
|
|
679
|
+
case TerraformSchema_1.TerraformValueKind.Number: {
|
|
680
|
+
const value = Number(raw.trim());
|
|
681
|
+
if (raw.trim() === "" || !Number.isFinite(value)) {
|
|
682
|
+
throw new CliValueError(`${flag.flag} takes a number, and ${JSON.stringify(raw)} is not one.`);
|
|
683
|
+
}
|
|
684
|
+
return value;
|
|
685
|
+
}
|
|
686
|
+
case TerraformSchema_1.TerraformValueKind.DateTime: {
|
|
687
|
+
const date = new Date(raw.trim());
|
|
688
|
+
if (raw.trim() === "" || Number.isNaN(date.getTime())) {
|
|
689
|
+
throw new CliValueError(`${flag.flag} takes a date and time, such as 2026-11-01T10:00:00Z, and ${JSON.stringify(raw)} is not one.`);
|
|
690
|
+
}
|
|
691
|
+
return date.toISOString();
|
|
692
|
+
}
|
|
693
|
+
case TerraformSchema_1.TerraformValueKind.IdSet: {
|
|
694
|
+
const ids = parseCliList(flag.flag, raw);
|
|
695
|
+
assertIds(flag, ids);
|
|
696
|
+
return ids.map((id) => {
|
|
697
|
+
return { _id: id };
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
case TerraformSchema_1.TerraformValueKind.StringSet:
|
|
701
|
+
return parseCliList(flag.flag, raw);
|
|
702
|
+
case TerraformSchema_1.TerraformValueKind.Json:
|
|
703
|
+
case TerraformSchema_1.TerraformValueKind.MonitorSteps:
|
|
704
|
+
try {
|
|
705
|
+
return JSON.parse(raw);
|
|
706
|
+
}
|
|
707
|
+
catch (_a) {
|
|
708
|
+
throw new CliValueError(`${flag.flag} takes JSON, and ${JSON.stringify(raw)} is not JSON. In Bash and zsh, wrap it in single quotes.`);
|
|
709
|
+
}
|
|
710
|
+
default:
|
|
711
|
+
if (flag.valueName === "<id>" &&
|
|
712
|
+
flag.columnType === TableColumnType_1.default.ObjectID) {
|
|
713
|
+
assertIds(flag, [raw.trim()]);
|
|
714
|
+
return raw.trim();
|
|
715
|
+
}
|
|
716
|
+
return raw;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
function getCliAnalyticsFields(modelType) {
|
|
720
|
+
const model = new modelType();
|
|
721
|
+
return model
|
|
722
|
+
.getTableColumns()
|
|
723
|
+
.map((column) => {
|
|
724
|
+
var _a, _b, _c;
|
|
725
|
+
return {
|
|
726
|
+
columnName: column.key,
|
|
727
|
+
title: column.title || column.key,
|
|
728
|
+
type: column.type,
|
|
729
|
+
description: (column.description || "")
|
|
730
|
+
.replace(LINE_BREAKS, " ")
|
|
731
|
+
.trim(),
|
|
732
|
+
isRequired: column.required,
|
|
733
|
+
inCreate: (((_a = column.accessControl) === null || _a === void 0 ? void 0 : _a.create) || []).length > 0,
|
|
734
|
+
inUpdate: (((_b = column.accessControl) === null || _b === void 0 ? void 0 : _b.update) || []).length > 0,
|
|
735
|
+
isReadable: isAnalyticsColumnReadable(column.key, (_c = column.accessControl) === null || _c === void 0 ? void 0 : _c.read),
|
|
736
|
+
};
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
/*
|
|
740
|
+
* Whether a key may read a telemetry column: its read rule names someone
|
|
741
|
+
* other than a signed-in user alone, or, with no rule, it is one every
|
|
742
|
+
* select may name (ALWAYS_SELECTABLE_COLUMNS) - the rule the CLI's own
|
|
743
|
+
* select follows (packages/CLI/Utils/SelectFieldGenerator.ts).
|
|
744
|
+
*/
|
|
745
|
+
function isAnalyticsColumnReadable(columnName, read) {
|
|
746
|
+
if (!read) {
|
|
747
|
+
return HeldPermissions_1.ALWAYS_SELECTABLE_COLUMNS.includes(columnName);
|
|
748
|
+
}
|
|
749
|
+
return !(0, TerraformSchema_1.isApiExcludedForPermissions)(read);
|
|
750
|
+
}
|