@boltic/cli 1.0.35 → 1.1.1-dev.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.
@@ -0,0 +1,174 @@
1
+ import axios from "axios";
2
+ import FormData from "form-data";
3
+ import fs from "fs";
4
+ import https from "https";
5
+ import { handleError } from "../helper/error.js";
6
+ import { logApi } from "../helper/verbose.js";
7
+
8
+ const getHttpsAgentForUrl = (baseUrl) => {
9
+ try {
10
+ const host = new URL(baseUrl).hostname;
11
+ if (
12
+ host.endsWith("fcz0.de") ||
13
+ host.endsWith("uat.fcz0.de") ||
14
+ host.endsWith("fyndx1.de") ||
15
+ process.env.BOLTCI_INSECURE_TLS === "true"
16
+ ) {
17
+ return new https.Agent({ rejectUnauthorized: false });
18
+ }
19
+ } catch (_) {
20
+ // ignore URL parse errors and fall back to default agent
21
+ }
22
+ return undefined;
23
+ };
24
+
25
+ const listAllServerless = async (
26
+ apiUrl,
27
+ token,
28
+ accountId,
29
+ session,
30
+ query = null
31
+ ) => {
32
+ if (!token || !session || !accountId) {
33
+ console.error(
34
+ "\x1b[31mError:\x1b[0m Authentication credentials are required."
35
+ );
36
+ console.log("\nšŸ”¹ Please log in first using:");
37
+ console.log("\x1b[32m$ boltic login\x1b[0m\n");
38
+ process.exit(1); // Exit the CLI with an error code
39
+ }
40
+ try {
41
+ const params = {
42
+ page: 1,
43
+ limit: 999,
44
+ sortBy: "CreatedAt",
45
+ sortOrder: "desc",
46
+ };
47
+
48
+ // Add query parameter if provided
49
+ if (query) {
50
+ params.q = query;
51
+ }
52
+
53
+ const axiosOptions = {
54
+ method: "get",
55
+ url: `${apiUrl}/service/panel/serverless/v1.0/apps`,
56
+ params,
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ Authorization: `Bearer ${token}`,
60
+ Cookie: session,
61
+ },
62
+ httpsAgent: getHttpsAgentForUrl(apiUrl),
63
+ };
64
+
65
+ const response = await axios(axiosOptions);
66
+ logApi(axiosOptions.method, axiosOptions.url, response.status);
67
+ return response.data.data;
68
+ } catch (error) {
69
+ handleError(error);
70
+ }
71
+ };
72
+
73
+ const pullServerless = async (apiUrl, token, accountId, session, id) => {
74
+ if (!token || !session || !accountId) {
75
+ console.error(
76
+ "\x1b[31mError:\x1b[0m Authentication credentials are required."
77
+ );
78
+ console.log("\nšŸ”¹ Please log in first using:");
79
+ console.log("\x1b[32m$ boltic login\x1b[0m\n");
80
+ process.exit(1); // Exit the CLI with an error code
81
+ }
82
+ try {
83
+ const response = await axios({
84
+ method: "get",
85
+ url: `${apiUrl}/service/panel/serverless/v1.0/apps/${id}`,
86
+ headers: {
87
+ "Content-Type": "application/json",
88
+ Authorization: `Bearer ${token}`,
89
+ Cookie: session,
90
+ },
91
+ httpsAgent: getHttpsAgentForUrl(apiUrl),
92
+ });
93
+ return response?.data;
94
+ } catch (error) {
95
+ handleError(error);
96
+ }
97
+ };
98
+
99
+ const publishServerless = async (apiUrl, token, session, payload) => {
100
+ if (!token || !session) {
101
+ console.error(
102
+ "\x1b[31mError:\x1b[0m Authentication credentials are required."
103
+ );
104
+ console.log("\nšŸ”¹ Please log in first using:");
105
+ console.log("\x1b[32m$ boltic login\x1b[0m\n");
106
+ process.exit(1);
107
+ }
108
+
109
+ try {
110
+ const axiosOptions = {
111
+ method: "post",
112
+ url: `https://asia-south1.api.boltic.io/service/panel/serverless/v1.0/apps`,
113
+ headers: {
114
+ "Content-Type": "application/json",
115
+ Authorization: `Bearer ${token}`,
116
+ Cookie: session,
117
+ },
118
+ data: payload,
119
+ httpsAgent: getHttpsAgentForUrl(apiUrl),
120
+ };
121
+
122
+ const response = await axios(axiosOptions);
123
+ logApi(axiosOptions.method, axiosOptions.url, response.status);
124
+ return response.data;
125
+ } catch (error) {
126
+ handleError(error);
127
+ return null;
128
+ }
129
+ };
130
+
131
+ const updateServerless = async (
132
+ apiUrl,
133
+ token,
134
+ session,
135
+ serverlessId,
136
+ payload
137
+ ) => {
138
+ if (!token || !session) {
139
+ console.error(
140
+ "\x1b[31mError:\x1b[0m Authentication credentials are required."
141
+ );
142
+ console.log("\nšŸ”¹ Please log in first using:");
143
+ console.log("\x1b[32m$ boltic login\x1b[0m\n");
144
+ process.exit(1);
145
+ }
146
+
147
+ try {
148
+ const axiosOptions = {
149
+ method: "put",
150
+ url: `https://asia-south1.api.boltic.io/service/panel/serverless/v1.0/apps/${serverlessId}`,
151
+ headers: {
152
+ "Content-Type": "application/json",
153
+ Authorization: `Bearer ${token}`,
154
+ Cookie: session,
155
+ },
156
+ data: payload,
157
+ httpsAgent: getHttpsAgentForUrl(apiUrl),
158
+ };
159
+
160
+ const response = await axios(axiosOptions);
161
+ logApi(axiosOptions.method, axiosOptions.url, response.status);
162
+ return response.data;
163
+ } catch (error) {
164
+ handleError(error);
165
+ return null;
166
+ }
167
+ };
168
+
169
+ export {
170
+ listAllServerless,
171
+ pullServerless,
172
+ publishServerless,
173
+ updateServerless,
174
+ };
package/cli.js CHANGED
@@ -6,6 +6,7 @@ import EnvironmentCommands from "./commands/env.js";
6
6
  import IntegrationCommands from "./commands/integration.js";
7
7
  import AuthCommands from "./commands/login.js";
8
8
  import McpCommands from "./commands/mcp.js";
9
+ import ServerlessCommands from "./commands/serverless.js";
9
10
 
10
11
  // Create a CLI module with functional approach
11
12
  import { findSimilarCommands } from "./helper/command-suggestions.js";
@@ -43,6 +44,10 @@ const createCLI = (consoleUrl, apiUrl, serviceName, env) => {
43
44
  description: "Display the version of the CLI.",
44
45
  action: () => showVersion(),
45
46
  },
47
+ serverless: {
48
+ description: "Manage serverless (create, list, test)",
49
+ action: (args) => handleServerless(args),
50
+ },
46
51
  };
47
52
 
48
53
  return {
@@ -168,6 +173,9 @@ async function handleMcp(args) {
168
173
  await McpCommands.execute(args);
169
174
  }
170
175
 
176
+ async function handleServerless(args) {
177
+ await ServerlessCommands.execute(args);
178
+ }
171
179
  async function showVersion() {
172
180
  let version = "1.0.0";
173
181
  try {