diff --git a/package.json b/package.json index c35de2d..664a860 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shsf-cli", - "version": "2.2.0", + "version": "2.2.1", "description": "", "type": "module", "files": [ diff --git a/src/commands/req/add.ts b/src/commands/req/add.ts index 1f2c646..16f21df 100644 --- a/src/commands/req/add.ts +++ b/src/commands/req/add.ts @@ -63,18 +63,10 @@ export const reqAddDefinition = { } content += pkg + "\n"; - // 3. Get function details to find storageId - const funcResponse = await client.get(`/api/function/${functionId}`); - const func = funcResponse.data.data; - if (!func || !func.namespace || !func.namespace.storageId) { - throw new Error("Could not determine storage ID for function."); - } - const storageId = func.namespace.storageId; - - // 4. Overwrite/Create requirements.txt - await client.put(`/api/storage/${storageId}/files`, { - path: "requirements.txt", - content: content + // 3. Overwrite/Create requirements.txt using function-based API + await client.put(`/api/function/${functionId}/file`, { + filename: "requirements.txt", + code: content, }); console.log(`${chalk.green("✓")} Added ${chalk.cyan(pkg)} to requirements.txt for function ${chalk.yellow(functionId)}.`); @@ -86,7 +78,7 @@ export const reqAddDefinition = { function handleError(error: any, task: string) { if (error.response) { - console.error(`${chalk.red("✗")} Failed to ${task}: ${chalk.yellow(error.response.data?.message || error.message)}`); + console.error(`${chalk.red("✗")} Failed to ${task}: ${chalk.yellow(error.response.data?.message || (error.response.data ? JSON.stringify(error.response.data) : error.message))}`); } else if (error.request) { console.error( `${chalk.red("✗")} Failed to ${task}: ${chalk.yellow( diff --git a/src/commands/req/remove.ts b/src/commands/req/remove.ts index ecb670a..1b70e46 100644 --- a/src/commands/req/remove.ts +++ b/src/commands/req/remove.ts @@ -69,18 +69,10 @@ export const reqRemoveDefinition = { const newContent = newLines.join("\n"); - // 2. Get function details to find storageId - const funcResponse = await client.get(`/api/function/${functionId}`); - const func = funcResponse.data.data; - if (!func || !func.namespace || !func.namespace.storageId) { - throw new Error("Could not determine storage ID for function."); - } - const storageId = func.namespace.storageId; - - // 3. Overwrite requirements.txt - await client.put(`/api/storage/${storageId}/files`, { - path: "requirements.txt", - content: newContent + // 2. Overwrite requirements.txt using function-based API + await client.put(`/api/function/${functionId}/file`, { + filename: "requirements.txt", + code: newContent, }); console.log(`${chalk.green("✓")} Removed ${chalk.cyan(pkgToRemove)} from requirements.txt for function ${chalk.yellow(functionId)}.`); @@ -92,7 +84,7 @@ export const reqRemoveDefinition = { function handleError(error: any, task: string) { if (error.response) { - console.error(`${chalk.red("✗")} Failed to ${task}: ${chalk.yellow(error.response.data?.message || error.message)}`); + console.error(`${chalk.red("✗")} Failed to ${task}: ${chalk.yellow(error.response.data?.message || (error.response.data ? JSON.stringify(error.response.data) : error.message))}`); } else if (error.request) { console.error( `${chalk.red("✗")} Failed to ${task}: ${chalk.yellow(