@1medium/cli 1.9.0 → 1.9.1
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/package.json +1 -1
- package/src/api.js +11 -59
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -89,54 +89,6 @@ async function request(method, path, body = null, params = null) {
|
|
|
89
89
|
return data;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
/**
|
|
93
|
-
* Make an authenticated API request to non-agent routes (e.g. /scripts, /script-events)
|
|
94
|
-
*/
|
|
95
|
-
async function requestDirect(method, path, body = null, params = null) {
|
|
96
|
-
const baseUrl = getApiUrl();
|
|
97
|
-
const token = getToken();
|
|
98
|
-
|
|
99
|
-
let url = `${baseUrl}${path}`;
|
|
100
|
-
if (params) {
|
|
101
|
-
const searchParams = new URLSearchParams();
|
|
102
|
-
for (const [key, value] of Object.entries(params)) {
|
|
103
|
-
if (value !== undefined && value !== null) {
|
|
104
|
-
searchParams.append(key, value);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const queryString = searchParams.toString();
|
|
108
|
-
if (queryString) {
|
|
109
|
-
url += `?${queryString}`;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const options = {
|
|
114
|
-
method,
|
|
115
|
-
headers: {
|
|
116
|
-
Authorization: `Bearer ${token}`,
|
|
117
|
-
"Content-Type": "application/json",
|
|
118
|
-
"User-Agent": "1m-cli/1.0.0",
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
if (body && (method === "POST" || method === "PATCH" || method === "PUT")) {
|
|
123
|
-
options.body = JSON.stringify(body);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const response = await fetch(url, options);
|
|
127
|
-
const data = await response.json();
|
|
128
|
-
|
|
129
|
-
if (!response.ok) {
|
|
130
|
-
const message = data.message || data.error || "API request failed";
|
|
131
|
-
const error = new Error(message);
|
|
132
|
-
error.statusCode = response.status;
|
|
133
|
-
error.details = data.details;
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return data;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
92
|
/**
|
|
141
93
|
* Token introspection
|
|
142
94
|
*/
|
|
@@ -264,28 +216,28 @@ async function deleteProject(id) {
|
|
|
264
216
|
* List scripts
|
|
265
217
|
*/
|
|
266
218
|
async function listScripts(params = {}) {
|
|
267
|
-
return
|
|
219
|
+
return request("GET", "/scripts", null, params);
|
|
268
220
|
}
|
|
269
221
|
|
|
270
222
|
/**
|
|
271
223
|
* Get a single script
|
|
272
224
|
*/
|
|
273
225
|
async function getScript(id) {
|
|
274
|
-
return
|
|
226
|
+
return request("GET", `/scripts/${id}`);
|
|
275
227
|
}
|
|
276
228
|
|
|
277
229
|
/**
|
|
278
230
|
* Push (create/update) a script
|
|
279
231
|
*/
|
|
280
232
|
async function pushScript(payload) {
|
|
281
|
-
return
|
|
233
|
+
return request("POST", "/scripts/push", payload);
|
|
282
234
|
}
|
|
283
235
|
|
|
284
236
|
/**
|
|
285
237
|
* Deprecate a script
|
|
286
238
|
*/
|
|
287
239
|
async function deprecateScript(id) {
|
|
288
|
-
return
|
|
240
|
+
return request("POST", `/scripts/${id}/deprecate`);
|
|
289
241
|
}
|
|
290
242
|
|
|
291
243
|
// ============================================================================
|
|
@@ -296,49 +248,49 @@ async function deprecateScript(id) {
|
|
|
296
248
|
* List script events
|
|
297
249
|
*/
|
|
298
250
|
async function listScriptEvents(params = {}) {
|
|
299
|
-
return
|
|
251
|
+
return request("GET", "/script-events", null, params);
|
|
300
252
|
}
|
|
301
253
|
|
|
302
254
|
/**
|
|
303
255
|
* Get a single script event
|
|
304
256
|
*/
|
|
305
257
|
async function getScriptEvent(id) {
|
|
306
|
-
return
|
|
258
|
+
return request("GET", `/script-events/${id}`);
|
|
307
259
|
}
|
|
308
260
|
|
|
309
261
|
/**
|
|
310
262
|
* Create a script event
|
|
311
263
|
*/
|
|
312
264
|
async function createScriptEvent(payload) {
|
|
313
|
-
return
|
|
265
|
+
return request("POST", "/script-events", payload);
|
|
314
266
|
}
|
|
315
267
|
|
|
316
268
|
/**
|
|
317
269
|
* Update a script event
|
|
318
270
|
*/
|
|
319
271
|
async function updateScriptEvent(id, payload) {
|
|
320
|
-
return
|
|
272
|
+
return request("PUT", `/script-events/${id}`, payload);
|
|
321
273
|
}
|
|
322
274
|
|
|
323
275
|
/**
|
|
324
276
|
* Delete a script event
|
|
325
277
|
*/
|
|
326
278
|
async function deleteScriptEvent(id) {
|
|
327
|
-
return
|
|
279
|
+
return request("DELETE", `/script-events/${id}`);
|
|
328
280
|
}
|
|
329
281
|
|
|
330
282
|
/**
|
|
331
283
|
* Pause a script event
|
|
332
284
|
*/
|
|
333
285
|
async function pauseScriptEvent(id) {
|
|
334
|
-
return
|
|
286
|
+
return request("POST", `/script-events/${id}/pause`);
|
|
335
287
|
}
|
|
336
288
|
|
|
337
289
|
/**
|
|
338
290
|
* Resume a script event
|
|
339
291
|
*/
|
|
340
292
|
async function resumeScriptEvent(id) {
|
|
341
|
-
return
|
|
293
|
+
return request("POST", `/script-events/${id}/resume`);
|
|
342
294
|
}
|
|
343
295
|
|
|
344
296
|
module.exports = {
|