c8y-nitro 0.7.0 → 0.7.2

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.
@@ -1,147 +0,0 @@
1
- import { c as getTenantOptionsByCategory, f as upsertTenantOption, i as deleteTenantOption, n as createBasicAuthHeader, p as createC8yManifest, s as getTenantOption } from "./c8y-api-BFjK6AYb.mjs";
2
- import { n as validateBootstrapEnv, t as loadC8yConfig } from "./config-BVQHqlgV.mjs";
3
- import { defineCommand } from "citty";
4
- import { consola } from "consola";
5
- //#region src/cli/commands/options.ts
6
- var options_default = defineCommand({
7
- meta: {
8
- name: "options",
9
- description: "Manage tenant options on the development tenant"
10
- },
11
- args: {},
12
- async run() {
13
- consola.info("Loading configuration...");
14
- const { env, nitroConfig, configDir } = await loadC8yConfig();
15
- consola.info("Validating environment variables...");
16
- const envVars = validateBootstrapEnv(env);
17
- consola.info("Loading manifest...");
18
- const manifest = await createC8yManifest(configDir, nitroConfig);
19
- const category = manifest.settingsCategory || manifest.contextPath || manifest.name;
20
- if (!manifest.settings || manifest.settings.length === 0) throw new Error("No settings defined in manifest. Add settings to your c8y.manifest configuration.");
21
- consola.success(`Using category: ${category}`);
22
- const authHeader = createBasicAuthHeader(envVars.C8Y_DEVELOPMENT_TENANT, envVars.C8Y_DEVELOPMENT_USER, envVars.C8Y_DEVELOPMENT_PASSWORD);
23
- consola.info("Fetching current tenant options...");
24
- const currentOptions = await getTenantOptionsByCategory(envVars.C8Y_BASEURL, category, authHeader);
25
- const availableKeys = manifest.settings.map((s) => s.key);
26
- consola.success(`Found ${Object.keys(currentOptions).length} options set on tenant`);
27
- const action = await consola.prompt("What do you want to do?", {
28
- type: "select",
29
- options: [
30
- {
31
- label: "Read option value",
32
- value: "read"
33
- },
34
- {
35
- label: "Update/Create option",
36
- value: "update"
37
- },
38
- {
39
- label: "Delete option(s)",
40
- value: "delete"
41
- }
42
- ]
43
- });
44
- if (action === "read") await handleRead(envVars.C8Y_BASEURL, category, authHeader, availableKeys, currentOptions);
45
- else if (action === "update") await handleUpdate(envVars.C8Y_BASEURL, category, authHeader, availableKeys, currentOptions);
46
- else if (action === "delete") await handleDelete(envVars.C8Y_BASEURL, category, authHeader, availableKeys, currentOptions);
47
- }
48
- });
49
- /**
50
- * Handle reading a single option
51
- * @param baseUrl - The Cumulocity base URL
52
- * @param category - The tenant option category
53
- * @param authHeader - The Basic Auth header
54
- * @param availableKeys - List of available option keys
55
- * @param currentOptions - Current option values from tenant
56
- */
57
- async function handleRead(baseUrl, category, authHeader, availableKeys, currentOptions) {
58
- const setKeys = availableKeys.filter((k) => !k.startsWith("credentials.") && currentOptions[k] !== void 0);
59
- const credentialsKeys = availableKeys.filter((k) => k.startsWith("credentials."));
60
- const allKeys = [...setKeys, ...credentialsKeys];
61
- if (allKeys.length === 0) {
62
- consola.warn("No options are currently set");
63
- return;
64
- }
65
- if (credentialsKeys.length > 0) consola.warn("Encrypted credentials.* options cannot be read in decrypted form with the development user in this CLI.");
66
- const key = await consola.prompt("Select option to read:", {
67
- type: "select",
68
- options: allKeys.map((k) => ({
69
- label: k.startsWith("credentials.") ? `${k} (unknown)` : k,
70
- value: k
71
- })),
72
- cancel: "reject"
73
- });
74
- consola.info(`Reading option: ${key}`);
75
- const value = await getTenantOption(baseUrl, category, key, authHeader);
76
- if (value === void 0) consola.warn(`Option '${key}' is not set`);
77
- else consola.success(`Value: ${value}`);
78
- }
79
- /**
80
- * Handle updating options (with loop for multiple updates)
81
- * @param baseUrl - The Cumulocity base URL
82
- * @param category - The tenant option category
83
- * @param authHeader - The Basic Auth header
84
- * @param availableKeys - List of available option keys
85
- * @param currentOptions - Current option values from tenant
86
- */
87
- async function handleUpdate(baseUrl, category, authHeader, availableKeys, currentOptions) {
88
- let continueUpdating = true;
89
- while (continueUpdating) {
90
- const key = await consola.prompt("Select option to update:", {
91
- type: "select",
92
- options: availableKeys.map((k) => ({
93
- label: currentOptions[k] !== void 0 ? `${k} (current: ${currentOptions[k]})` : k.startsWith("credentials.") ? `${k} (current: unknown)` : `${k} (not set)`,
94
- value: k
95
- })),
96
- cancel: "reject"
97
- });
98
- const currentValue = currentOptions[key];
99
- const newValue = await consola.prompt("Enter new value:", {
100
- type: "text",
101
- default: currentValue,
102
- cancel: "reject"
103
- });
104
- consola.info(`Updating option: ${key}`);
105
- await upsertTenantOption(baseUrl, category, key, newValue, authHeader);
106
- currentOptions[key] = newValue;
107
- consola.success(`Option '${key}' updated successfully`);
108
- if (!await consola.prompt("Update another option?", {
109
- type: "confirm",
110
- initial: false,
111
- cancel: "reject"
112
- })) continueUpdating = false;
113
- }
114
- }
115
- /**
116
- * Handle deleting multiple options
117
- * @param baseUrl - The Cumulocity base URL
118
- * @param category - The tenant option category
119
- * @param authHeader - The Basic Auth header
120
- * @param availableKeys - List of available option keys
121
- * @param currentOptions - Current option values from tenant
122
- */
123
- async function handleDelete(baseUrl, category, authHeader, availableKeys, currentOptions) {
124
- const setKeys = availableKeys.filter((k) => !k.startsWith("credentials.") && currentOptions[k] !== void 0);
125
- const credentialsKeys = availableKeys.filter((k) => k.startsWith("credentials."));
126
- const allKeys = [...setKeys, ...credentialsKeys];
127
- if (allKeys.length === 0) {
128
- consola.warn("No options are currently set");
129
- return;
130
- }
131
- const keysToDelete = await consola.prompt("Select option(s) to delete:", {
132
- type: "multiselect",
133
- options: allKeys,
134
- required: true,
135
- cancel: "reject"
136
- });
137
- consola.info(`Deleting ${keysToDelete.length} option(s)...`);
138
- for (const key of keysToDelete) {
139
- consola.info(`Deleting option: ${key}`);
140
- await deleteTenantOption(baseUrl, category, key, authHeader);
141
- delete currentOptions[key];
142
- consola.success(`✓ Deleted: ${key}`);
143
- }
144
- consola.success("Delete operation completed");
145
- }
146
- //#endregion
147
- export { options_default as default };