Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 13900343a3 | |||
| cc54ef85e1 |
+6
-28
@@ -33,7 +33,7 @@ this will check the health, and if not setup, it will prompt you to set up the C
|
|||||||
- `shsf get namespace <id>`: Get details of a specific namespace by its ID
|
- `shsf get namespace <id>`: Get details of a specific namespace by its ID
|
||||||
- `shsf get trigger <functionId> <triggerId>`: Get details of a specific trigger from a function.
|
- `shsf get trigger <functionId> <triggerId>`: Get details of a specific trigger from a function.
|
||||||
|
|
||||||
- `shsf execute --id <id> [--payload <json>] [--no-stream]`: Execute a function and stream the output (debug/internal).
|
- `shsf function execute --id <id> [--payload <json>] [--no-stream]`: Execute a function and stream the output (debug/internal).
|
||||||
|
|
||||||
- `shsf storage create --name <name> --purpose <purpose>`: Create a new storage.
|
- `shsf storage create --name <name> --purpose <purpose>`: Create a new storage.
|
||||||
- `shsf storage delete --name <name>`: Delete a storage.
|
- `shsf storage delete --name <name>`: Delete a storage.
|
||||||
@@ -52,6 +52,11 @@ this will check the health, and if not setup, it will prompt you to set up the C
|
|||||||
- `shsf file rename`: Rename a file in a function. (use `shsf file rename -h` first)
|
- `shsf file rename`: Rename a file in a function. (use `shsf file rename -h` first)
|
||||||
- `shsf file delete`: Delete a file from a function. (use `shsf file delete -h` first)
|
- `shsf file delete`: Delete a file from a function. (use `shsf file delete -h` first)
|
||||||
|
|
||||||
|
- `shsf env add --id <id> --name <name> --value <value>`: Adds or updates an environment variable for a function.
|
||||||
|
- `shsf env remove --id <id> --name <name>`: Removes a specific environment variable from a function.
|
||||||
|
- `shsf env list --id <id>`: Lists all environment variables for a function.
|
||||||
|
- `shsf env flush --id <id>`: Removes ALL environment variables from a function.
|
||||||
|
|
||||||
- `shsf remote pull --id <id> --into <path> [--force]`: Pull files from a function into a local directory.
|
- `shsf remote pull --id <id> --into <path> [--force]`: Pull files from a function into a local directory.
|
||||||
- `shsf remote push --id <id> --from <path> [--force]`: Push files from a local directory to a function.
|
- `shsf remote push --id <id> --from <path> [--force]`: Push files from a local directory to a function.
|
||||||
|
|
||||||
@@ -67,33 +72,6 @@ Get the ui url with:
|
|||||||
shsf uiurl
|
shsf uiurl
|
||||||
```
|
```
|
||||||
|
|
||||||
## Available UI Routes
|
|
||||||
|
|
||||||
Below are the main routes you can use in the SHSF web UI. These are not clickable links, but you can navigate to them in your browser.
|
|
||||||
|
|
||||||
**General**
|
|
||||||
- `/`: Home Page
|
|
||||||
|
|
||||||
**Documentation**
|
|
||||||
- `/docs`: Documentation
|
|
||||||
|
|
||||||
**Account**
|
|
||||||
- `/account`: Account Settings
|
|
||||||
- `/login`: Login
|
|
||||||
- `/register`: Register
|
|
||||||
|
|
||||||
**Functions**
|
|
||||||
- `/functions`: Shows your functions, grouped by their respective namespaces (requires auth).
|
|
||||||
- `/functions/:id`: View details for a specific function (requires auth).
|
|
||||||
|
|
||||||
**Other**
|
|
||||||
- `/admin`: Admin dashboard (admin only, requires authentication)
|
|
||||||
- `/storage`: Storage management (requires auth)
|
|
||||||
- `/cron-jobs`: Cron job management (requires auth)
|
|
||||||
- `/access-tokens`: Access token management (requires auth)
|
|
||||||
- `/guest-users`: Guest user management (requires auth)
|
|
||||||
- `/guest-access`: Guest access portal
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
After creating a function and receiving an ID (for example, 81), you can share the following URL with your human so they can view the function in the UI:
|
After creating a function and receiving an ID (for example, 81), you can share the following URL with your human so they can view the function in the UI:
|
||||||
```
|
```
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "shsf-cli",
|
"name": "shsf-cli",
|
||||||
"version": "2.2.2",
|
"version": "2.2.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
Vendored
+96
@@ -0,0 +1,96 @@
|
|||||||
|
import chalk from "chalk";
|
||||||
|
import { getApiClient } from "../../api.js";
|
||||||
|
|
||||||
|
export const updateFunctionDefinition = {
|
||||||
|
name: "add",
|
||||||
|
description:
|
||||||
|
"Adds or updates environment variables for a serverless function.",
|
||||||
|
options: [
|
||||||
|
{ name: "--id <id>", description: "Function ID", required: true },
|
||||||
|
{
|
||||||
|
name: "--name <name>",
|
||||||
|
description: "Environment variable name",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "--value <value>",
|
||||||
|
description: "Environment variable value",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
action: async (options: any) => {
|
||||||
|
if (!options.id || !options.name || !options.value) {
|
||||||
|
console.error(
|
||||||
|
`${chalk.red("✗")} Error: Missing required options (--id, --name, --value)`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = await getApiClient();
|
||||||
|
let existingEnv: { name: string; value: string }[] = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await client.get(`/api/function/${options.id}`);
|
||||||
|
const functionData = response.data.data || response.data;
|
||||||
|
existingEnv = functionData.env || [];
|
||||||
|
|
||||||
|
if (typeof existingEnv === 'string') {
|
||||||
|
try {
|
||||||
|
existingEnv = JSON.parse(existingEnv);
|
||||||
|
} catch (e: any) {
|
||||||
|
existingEnv = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Array.isArray(existingEnv)) {
|
||||||
|
existingEnv = [];
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(
|
||||||
|
`${chalk.red("✗")} Error fetching function data: ${error.message}`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newEnv = [...existingEnv];
|
||||||
|
const existingIndex = newEnv.findIndex((env) => env.name === options.name);
|
||||||
|
const isUpdate = existingIndex !== -1;
|
||||||
|
|
||||||
|
if (isUpdate) {
|
||||||
|
newEnv[existingIndex].value = options.value;
|
||||||
|
} else {
|
||||||
|
newEnv.push({ name: options.name, value: options.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalCount = newEnv.length;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await client.patch(`/api/function/${options.id}`, {
|
||||||
|
environment: newEnv,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
const actionText = isUpdate ? "updated" : "added";
|
||||||
|
console.log(
|
||||||
|
`${chalk.green("✓")} Environment variable ${chalk.cyan(options.name)} ${actionText} successfully for function ${chalk.cyan(options.id)}.`,
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${chalk.blue("ℹ")} Total environment variables: ${totalCount}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
`${chalk.red("✗")} Unexpected response from server: ${response.status}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.response?.status === 404) {
|
||||||
|
console.error(
|
||||||
|
`${chalk.red("✗")} Function with ID ${chalk.yellow(options.id)} not found.`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
`${chalk.red("✗")} Failed to update: ${chalk.yellow(error.response?.data?.message || error.message)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
import chalk from "chalk";
|
||||||
|
import { getApiClient } from "../../api.js";
|
||||||
|
|
||||||
|
export const flushFunctionDefinition = {
|
||||||
|
name: "flush",
|
||||||
|
description: "Removes ALL environment variables from a serverless function.",
|
||||||
|
options: [
|
||||||
|
{ name: "--id <id>", description: "Function ID", required: true },
|
||||||
|
],
|
||||||
|
action: async (options: any) => {
|
||||||
|
if (!options.id) {
|
||||||
|
console.error(`${chalk.red("✗")} Error: --id is required`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = await getApiClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await client.patch(`/api/function/${options.id}`, {
|
||||||
|
environment: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log(
|
||||||
|
`${chalk.green("✓")} All environment variables flushed for function ${chalk.cyan(options.id)}.`
|
||||||
|
);
|
||||||
|
console.log(`${chalk.blue("ℹ")} Total environment variables: 0`);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(`${chalk.red("✗")} Error: ${error.response?.data?.message || error.message}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
Vendored
+53
@@ -0,0 +1,53 @@
|
|||||||
|
import chalk from "chalk";
|
||||||
|
import { getApiClient } from "../../api.js";
|
||||||
|
|
||||||
|
export const listEnvDefinition = {
|
||||||
|
name: "list",
|
||||||
|
description: "Lists all environment variables for a serverless function.",
|
||||||
|
options: [
|
||||||
|
{ name: "--id <id>", description: "Function ID", required: true },
|
||||||
|
],
|
||||||
|
action: async (options: any) => {
|
||||||
|
if (!options.id) {
|
||||||
|
console.error(`${chalk.red("✗")} Error: --id is required`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = await getApiClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await client.get(`/api/function/${options.id}`);
|
||||||
|
|
||||||
|
const functionData = response.data.data || response.data;
|
||||||
|
let env = functionData.env;
|
||||||
|
|
||||||
|
if (typeof env === 'string' && env.length > 0) {
|
||||||
|
try {
|
||||||
|
env = JSON.parse(env);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error(`${chalk.red("✗")} Error parsing env string: ${e.message}`);
|
||||||
|
env = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const envList: { name: string; value: string }[] = Array.isArray(env) ? env : [];
|
||||||
|
|
||||||
|
if (envList.length === 0) {
|
||||||
|
console.log(`${chalk.yellow("!")} No environment variables found for function ${chalk.cyan(options.id)}.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${chalk.blue("ℹ")} Environment variables for function ${chalk.cyan(options.id)}:`);
|
||||||
|
envList.forEach((item) => {
|
||||||
|
console.log(`${chalk.green("•")} ${chalk.cyan(item.name)}=${chalk.white(item.value)}`);
|
||||||
|
});
|
||||||
|
console.log(`${chalk.blue("ℹ")} Total: ${envList.length}`);
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.response?.status === 404) {
|
||||||
|
console.error(`${chalk.red("✗")} Function with ID ${chalk.yellow(options.id)} not found.`);
|
||||||
|
} else {
|
||||||
|
console.error(`${chalk.red("✗")} Error fetching environment variables: ${chalk.yellow(error.response?.data?.message || error.message)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
Vendored
+62
@@ -0,0 +1,62 @@
|
|||||||
|
import chalk from "chalk";
|
||||||
|
import { getApiClient } from "../../api.js";
|
||||||
|
|
||||||
|
export const removeFunctionDefinition = {
|
||||||
|
name: "remove",
|
||||||
|
description: "Removes a specific environment variable from a serverless function.",
|
||||||
|
options: [
|
||||||
|
{ name: "--id <id>", description: "Function ID", required: true },
|
||||||
|
{
|
||||||
|
name: "--name <name>",
|
||||||
|
description: "Environment variable name to remove",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
action: async (options: any) => {
|
||||||
|
if (!options.id || !options.name) {
|
||||||
|
console.error(`${chalk.red("✗")} Error: --id and --name are required`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = await getApiClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await client.get(`/api/function/${options.id}`);
|
||||||
|
const functionData = response.data.data || response.data;
|
||||||
|
let existingEnv: { name: string; value: string }[] = functionData.env || [];
|
||||||
|
|
||||||
|
if (typeof existingEnv === 'string') {
|
||||||
|
try {
|
||||||
|
existingEnv = JSON.parse(existingEnv);
|
||||||
|
} catch (e: any) {
|
||||||
|
existingEnv = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Array.isArray(existingEnv)) {
|
||||||
|
existingEnv = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialCount = existingEnv.length;
|
||||||
|
const filteredEnv = existingEnv.filter((env) => env.name !== options.name);
|
||||||
|
|
||||||
|
if (filteredEnv.length === initialCount) {
|
||||||
|
console.warn(`${chalk.yellow("!")} Variable ${chalk.cyan(options.name)} not found. No changes made.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const patchResponse = await client.patch(`/api/function/${options.id}`, {
|
||||||
|
environment: filteredEnv,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (patchResponse.status === 200) {
|
||||||
|
console.log(
|
||||||
|
`${chalk.green("✓")} Variable ${chalk.cyan(options.name)} removed successfully from function ${chalk.cyan(options.id)}.`
|
||||||
|
);
|
||||||
|
console.log(`${chalk.blue("ℹ")} Remaining environment variables: ${filteredEnv.length}`);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(`${chalk.red("✗")} Error: ${error.response?.data?.message || error.message}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user