Skip to content

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.

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:

  1. Using pnpm: You can run the scripts directly using pnpm. For example, to manage consumers, you can run:

    Terminal window
    pnpm manage
  2. 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 using docker exec. For example, to manage consumers, you can run:

    Terminal window
    docker exec -it kommentar-app-1 pnpm manage

    This 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.

Each command accepts specific arguments and 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:

Terminal window
pnpm manage create "My Blog" --description "Blog comment system" --hosts "blog.com,www.blog.com" --rate-limit 100

Lists all consumers.

Example:

Terminal window
pnpm manage list

Shows details for a specific consumer.

Example:

Terminal window
pnpm manage show <consumer-id>

Activates a consumer.

Example:

Terminal window
pnpm manage activate <consumer-id>

Deactivates a consumer.

Example:

Terminal window
pnpm manage deactivate <consumer-id>

Deletes a consumer.

Example:

Terminal window
pnpm manage delete <consumer-id>

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.