Node CLI
Kommentar is primarily meant to be consumed via the HTTP API. Any SDKs that are published will also use the HTTP API under the hood.
That being said, I am aware that some functionalities that are available in the code are not exposed via the HTTP API yet. The main reason for this is that I have not yet worked out a decent but not-so-complex authorization strategy for these operations.
As a middle ground, I have created some scripts in the source code that you can use to execute these operations. The scripts are located in the scripts
directory, and you can run them using pnpm
, the package manager used in this project.
The scripts can be run using the node scripts in the package.json
, so you don’t have to worry about making sure all the dependencies are initialized or anything like that.
Available Scripts
Section titled “Available Scripts”The following scripts are available:
pnpm manage
: This script is used to manage the Consumers.pnpm setup:admin
: This script is used to set up the admin user’s API key and secret. This is a one-time setup script that you should run after deploying Kommentar for the first time.
There are other “dev” scripts that I created to help me do some fun stuff, but they don’t really provide any value to you as a user of Kommentar. You can find them in the package.json
file.
There are two ways to execute the scripts in the Available Scripts section:
-
Using
pnpm
: You can run the scripts directly usingpnpm
. For example, to manage consumers, you can run:Terminal window pnpm manage -
Using
docker exec
: If you are running Kommentar in a Docker container (as outlined in the Deploy with Docker), you can execute the scripts inside the container usingdocker exec
. For example, to manage consumers, you can run:Terminal window docker exec -it kommentar-app-1 pnpm manageThis will execute the
manage
script inside the Kommentar container. This is helpful if you want to make sure any changes in the database are synced with the container’s environment, especially if your environment for Docker is not the same as your local development environment.
pnpm manage
Section titled “pnpm manage”Script Arguments
Section titled “Script Arguments”Each command accepts specific arguments and options:
create <name> [options]
Section titled “create <name> [options]”Creates a new consumer.
Options:
--description <desc>
: Optional description for the consumer.--hosts <host1,host2>
: Comma-separated list of allowed hosts.--rate-limit <number>
: Rate limit per minute (number).--inactive
: Create the consumer as inactive.
Example:
pnpm manage create "My Blog" --description "Blog comment system" --hosts "blog.com,www.blog.com" --rate-limit 100
list
or ls
Section titled “list or ls”Lists all consumers.
Example:
pnpm manage list
show <id>
Section titled “show <id>”Shows details for a specific consumer.
Example:
pnpm manage show <consumer-id>
activate <id>
Section titled “activate <id>”Activates a consumer.
Example:
pnpm manage activate <consumer-id>
deactivate <id>
Section titled “deactivate <id>”Deactivates a consumer.
Example:
pnpm manage deactivate <consumer-id>
delete <id>
Section titled “delete <id>”Deletes a consumer.
Example:
pnpm manage delete <consumer-id>
pnpm setup:admin
Section titled “pnpm setup:admin”Script Arguments
Section titled “Script Arguments”This script does not accept any arguments. It is a one-time setup script that generates an API key and secret for the admin user.
The script will generate three things:
- An API key for the admin user.
- A hashed API secret for the admin user.
- An unhashed API secret for the admin user (this is printed to the console, so make sure to copy it somewhere safe).
The API key and the hashed API secret should be stored in the environment variables under the the keys ADMIN_KEY
and ADMIN_SECRET_HASH
, respectively. The unhashed API secret is the one you will need to pass in the X-Admin-Secret
header when making admin requests to the Kommentar API.