20 releases

0.7.0 Jan 3, 2024
0.5.5 May 26, 2023
0.4.1 Feb 28, 2023
0.4.0 Jan 28, 2023
0.1.5 Jan 5, 2023

#851 in Web programming

Download history 5/week @ 2024-01-03 44/week @ 2024-02-28 401/week @ 2024-03-06 2/week @ 2024-03-13

447 downloads per month

MIT license

1.5MB
40K SLoC

Rust 23K SLoC // 0.0% comments TSX 10K SLoC // 0.0% comments TypeScript 3.5K SLoC // 0.0% comments SQL 2.5K SLoC // 0.1% comments JavaScript 25 SLoC Shell 4 SLoC

Deploying

Running in a Kubernetes cluster

TODO: Write

For developers

Set up development environment

1. Create user config

This config will be picked up automatically

echo "DB_USER=$(whoami)
DB_NAME=samling
SECRET=abc123
LOG_LEVEL=info
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
CLOUDFLARE_ACCOUNT_ID=abc
CLOUDFLARE_TOKEN=123
SAMLING_PRETTY_RESPONSES=true" > .env

2. Create database and migrate

createdb samling
cargo run migrate

3. Create user

Export the user ID as an environment variable, we'll use it later. USER_ID should be 1 as in this example, if the database is clean. We'll also store SUPERUSER_ID for CLI access.

cargo run users create --name 'My Name' --email my@email.com --password MyPassword
export USER_ID=1
echo SUPERUSER_ID=$USER_ID >> .env

4. Create organization

cargo run organizations create 'Company Name'
export ORGANIZATION_ID=1

5. Associate all roles to superuser

NOTE: ORGANIZATION_ID might be something different than 1.

cargo run users associate-roles --all $USER_ID $ORGANIZATION_ID

6. Start the API server

cargo run serve

7. (Optional) Store API token for conveniently making API calls

NOTE: The stored API token will have to be updated every 7 days for the api command to work.

echo SAMLING_TOKEN=$(cargo run generate-user-token $USER_ID) >> .env

Pro tip! You can use cargo-watch to have the server restart every time the code changes.

cargo watch -- cargo run serve

8. Start the frontend

This is easy! Just do:

cd ui
npm install
npm start

Creating data via API

Currently the only way to create categories, prices, styles etc is via the API.

For example, to create a category called T-Shirts:

echo '{"name": {"en": "T-shirts"}}' | samling api -d - PUT 1/categories/external_id:BC-TShirts

A style:

echo '{"number": "A12345", "name": {"en": "Cool t-shirt"}}' | samling api -d - PUT 1/styles/external_id:BC-A12345

A color, associated with the above style:

echo '{"number": "HBlue", "name": {"en": "Hazy Blue"}, "style": {"external_id": "BC-A12345"}}' | samling api -d - PUT 1/colors/external_id:BC-A12345-HBlue

A size, associated with the above color:

echo '{"number": "XS", "name": {"en": "Extra small"}, "position": 1, "color": {"external_id": "BC-A12345-HBlue"}}' | samling api -d - PUT 1/sizes/external_id:BC-A12345-HBlue-XS

Notice how we're doing PUT requests here, with an External ID specified in the URL. This would be the typical way of syncing data from your ERP system.

Dependencies

~38–55MB
~1M SLoC