Compare commits

...

5 commits

8 changed files with 489 additions and 55 deletions

View file

@ -46,4 +46,5 @@
## Third-Party Libraries and Licenses
- [eslint/eslint](https://github.com/eslint/eslint) — [MIT](https://github.com/eslint/eslint/blob/main/LICENSE)
- [prettier/prettier](https://github.com/prettier/prettier) — [MIT](https://github.com/prettier/prettier/blob/main/LICENSE)
- [prettier/prettier](https://github.com/prettier/prettier) — [MIT](https://github.com/prettier/prettier/blob/main/LICENSE)
- [withastro/starlight](https://github.com/withastro/starlight) - [MIT](https://github.com/withastro/starlight/blob/main/LICENSE)

View file

@ -1,54 +0,0 @@
# Starlight Starter Kit: Basics
[![Built with Starlight](https://astro.badg.es/v2/built-with-starlight/tiny.svg)](https://starlight.astro.build)
```
npm create astro@latest -- --template starlight
```
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/starlight/tree/main/examples/basics)
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/withastro/starlight&create_from_path=examples/basics)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fwithastro%2Fstarlight%2Ftree%2Fmain%2Fexamples%2Fbasics&project-name=my-starlight-docs&repository-name=my-starlight-docs)
> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
## 🚀 Project Structure
Inside of your Astro + Starlight project, you'll see the following folders and files:
```
.
├── public/
├── src/
│ ├── assets/
│ ├── content/
│ │ ├── docs/
│ └── content.config.ts
├── astro.config.mjs
├── package.json
└── tsconfig.json
```
Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name.
Images can be added to `src/assets/` and embedded in Markdown with a relative link.
Static assets, like favicons, can be placed in the `public/` directory.
## 🧞 Commands
All commands are run from the root of the project, from a terminal:
| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |
## 👀 Want to learn more?
Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat).

View file

@ -33,6 +33,31 @@ export default defineConfig({
label: 'Get currency rate - /api/getRate',
slug: 'docs/endpoints/getrate'
},
{
label: 'Create charts - /api/getChart',
slug: 'docs/endpoints/create-chart'
},
{
label: 'Get metadata - /api/metadata',
slug: 'docs/endpoints/metadata'
}
],
},
{
label: 'Config',
items: [
{
label: 'Configure .env',
slug: 'docs/config/config-env'
},
{
label: 'Configure config.yaml',
slug: 'docs/config/config-yaml'
},
{
label: 'Configure Nginx',
slug: 'docs/config/config-nginx'
}
],
},
],

View file

@ -0,0 +1,31 @@
---
title: Configure .env
---
import { Aside, Code } from '@astrojs/starlight/components';
Kekkai can be configured using the `.env` file in the working directory. `.env.example`.
`.env` config is used to configure PosgreSQL running in Docker Compose.
<Aside>
If you are not using Docker Compose, you do not need to edit this config
</Aside>
<Code code=
'
# Connection secret for postgres. You should change it to a random password
# Please use only the characters `A-Za-z0-9`, without special characters or spaces
POSTGRES_PASSWORD=my_password
# If you do not know what you are doing, then you should not edit the values below
###################################################################################
POSTGRES_DB=kekkai
DB_HOST=postgres
POSTGRES_USER=postgres
' title='.env.example'/>
This config only edits the password for PosgreSQL.
Please use only the characters `A-Za-z0-9`, without special characters or spaces

View file

@ -0,0 +1,32 @@
---
title: Nginx configuration
---
import { Code } from '@astrojs/starlight/components';
Kekkai is used by `Nginx` to redirect to the correct microservice.
## Change domain
Change localhost to your `domain` or `ipv4` based on your needs.
If you need to use Kekkai locally, you don't need to change anything,
<Code code='
...
server_name localhost; # Your domain
...
'title='nginx.conf'/>
## Change name for SSL
This is where the name of the SSL files changes. This needs to be edited if you have a different one
Change `privkey.pem` and `fullchain.pem` to the names of the files you have.
<Code code=
'
...
ssl_certificate /etc/nginx/ssl/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
...
' title='nginx.conf'/>

View file

@ -0,0 +1,148 @@
---
title: Configure config.yaml
---
import { Aside } from '@astrojs/starlight/components';
Kekkai can be configured using the `config.yaml` file in the working directory.
`config.example.yaml`.
```yaml
# For more information, see the documentation
# https://kekkai-docs.redume.su/
database:
user: 'DATABASE_USERNAME'
password: 'DATABASE_PASSWORD'
host: 'DATABASE_HOST'
name: 'DATABASE_NAME'
port: 5432
server:
host: '0.0.0.0'
ssl:
private_key: '/CertSSL/privkey.pem'
cert: '/CertSSL/fullchain.pem'
work: true
log:
print: true
level: 'info'
analytics:
plausible_api: 'https://plausible.io/api/event/'
plausible_domain: 'PLAUSIBLE_DOMAIN'
plausible_token: 'PLAUSIBLE_TOKEN'
work: false
currency:
chart:
save: false
collecting:
fiat: true
schedule: '30 8 * * *'
fiat:
- USD
- RUB
- EUR
- UAH
- TRY
- KZT
```
## Database
Kekkai is used as a `PostgreSQL` database.
<Aside>
If you installed Kekkai via Docker Compose,
then install it in the `database.host` value of `postgres`.
The rest of the data does not have to be filled in.
They need to be filled in `.env`.
What should it look like:
```yaml
database:
...
host: 'postgres'
...
...
```
</Aside>
## Server
<Aside>
If you installed Kekkai via Docker Compose, then changing `server.host`, `
server.ssl` is not recommended.
</Aside>
### SSL
Create a folder CertSSL to store your certificates
```shell
mkdir CertSSL
```
Copy your certificates to the CertSSL folder.
It is recommended to rename the certificates to `privkey.pem` and `fullchain.pem`.
If this is not possible,
you need to change the SSL name in `nginx.conf` (if using Docker Compose)
## Analytics
Kekkai uses [`Plausbile`](https://plausible.io/) as an analyst.
Minimal data is transferred for anilithics.
Such as: browser, OS, status code, url, where the user came from.
Most of the data is built on User Agent.
It is possible to disable analytics in Kekkai.
```yaml
...
analytics:
plausible_api: 'https://plausible.io/api/event/'
plausible_domain: 'PLAUSIBLE_DOMAIN'
plausible_token: 'PLAUSIBLE_TOKEN'
work: true
...
```
- `plausible_api`: This is where the Plausible instance is specified.
The official instance is specified by default.
- `plausible_domain`: Kekkai Instance Domain.
It should be added to Plausible first, and then to the config.
You can add the domain [here](https://plausible.io/sites/new?flow=provisioning).
- `plausible_token`: Api token for authorization and sending requests.
You can create it [here](https://plausible.io/settings/api-keys).
- `work`: Enable or disable analytics.
## Currency
`DuckDuckGo` (fiat currency collection) and `CoinMarketCap` (cryptocurrency collection)
are used to collect currency rates.
```yaml
...
currency:
chart:
save: false # Enable or disable saving graphs to an image (Boolean)
collecting:
fiat: true # Turn off or turn on the collection of the fiat currency rate [Boolean]
crypto: false
schedule: '30 8 * * *' # Currency collection schedule in crontab format [String]
crypto_apikey: 'APIKEY'
fiat: # List of fiat currency to save the exchange rate [Array]
- USD
- RUB
- EUR
- UAH
- TRY
- KZT
crypto:
- ETH
- TON
- USDT
```
- `currency.chart.save`: Enable or disable saving graphs.
- `currency.collecting`: Enable or disable cryptocurrency
or fiat currency exchange rate collection.
- `currency.schedule`: Currency collection interval (Configurable via cron.
It is recommended to use [crontab.guru](https://crontab.guru),
not supported in `Non-standard format`, like `@daily`).
- `crypto.crypto_apiKey`: API-key from CoinMarketCap service
- `currency.fiat`: A list of fiat currencies that will be saved to the database.
- `currency.crypto`: A list of crypto currencies that will be saved to the database.

View file

@ -0,0 +1,172 @@
---
title: Create Charts - /api/getChart
---
Creating a currency rate chart.
import { Tabs, TabItem, Aside } from '@astrojs/starlight/components';
## Creating a graph for a certain period
### Request
<Tabs>
<TabItem label='Shell'>
<Tabs>
<TabItem label='curl'>
```shell
curl --request GET --url https://kekkai-api.redume.su/api/getChart/week?from_currency=RUB&conv_currency=USD
```
</TabItem>
</Tabs>
</TabItem>
<TabItem label='Python'>
<Tabs>
<TabItem label='requests'>
```python
import requests
res = requests.get('https://kekkai-api.redume.su/api/getChart/week', {
'from_currency': 'USD',
'conv_currency': 'RUB',
}, timeout=3)
print(res.json())
```
</TabItem>
</Tabs>
</TabItem>
<TabItem label='Node.JS'>
<Tabs>
<TabItem label='axios'>
```javascript
const axios = require('axios');
axios.get('https://kekkai-api.redume.su/api/getChart/week', {
timeout: 3000,
'from_currency': 'USD',
'conv_currency': 'RUB',
})
.then((res) => {
console.log(res['data']);
})
.catch((err) => {
console.error(err);
});
```
</TabItem>
</Tabs>
</TabItem>
</Tabs>
### Query params
| Parameter | Description |
|-------------------|-------------------------------------------------------------------------|
| `from_currency`* | `ISO 4217` code of the currency from which the conversion takes place |
| `conv_currency`* | `ISO 4217` code of the currency to which the conversion is performed |
### URL params
| Parameter | Description |
|---------------|-------------------------------------------------------------------------|
| `period` | Available parameters: `week`, `month`, `quarter`, `year` |
`*` - Required arguments
### Response
<Aside title='Output'>
```json
{
"status": 201,
"message": "http://kekkai-api.redume.su/static/charts/RUB_USD_20241108_DQVDN7.png"
}
```
</Aside>
## Creating a schedule for specific days
### Request
<Tabs>
<TabItem label='Shell'>
<Tabs>
<TabItem label='curl'>
```shell
curl --request GET --url https://kekkai-api.redume.su/api/getChart/?from_currency=RUB&conv_currency=USD&start_date=2024-10-31&end_date=2024-11-08
```
</TabItem>
</Tabs>
</TabItem>
<TabItem label='Python'>
<Tabs>
<TabItem label='requests'>
```python
import requests
res = requests.get('https://kekkai-api.redume.su/api/getChart/', {
'from_currency': 'USD',
'conv_currency': 'RUB',
'start_date': '2024-10-31',
'end_date': '2024-11-08'
}, timeout=3)
print(res.json())
```
</TabItem>
</Tabs>
</TabItem>
<TabItem label='Node.JS'>
<Tabs>
<TabItem label='axios'>
```javascript
const axios = require('axios');
axios.get('https://kekkai-api.redume.su/api/getChart/', {
timeout: 3000,
'from_currency': 'USD',
'conv_currency': 'RUB',
'start_date': '2024-10-31',
'end_date': '2024-11-08'
})
.then((res) => {
console.log(res['data']);
})
.catch((err) => {
console.error(err);
});
```
</TabItem>
</Tabs>
</TabItem>
</Tabs>
### Query params
| Parameter | Description |
|------------------|------------------------------------------------------------------------|
| `from_currency`* | `ISO 4217` code of the currency from which the conversion takes place |
| `conv_currency`* | `ISO 4217` code of the currency to which the conversion is performed |
| `start_date`* | Start date of the period in the format `YYYYY-DD-MM` |
| `end_date`* | Period end date in the format `YYYYY-DD-MM` |
`*` - Required arguments
### Response
<Aside title='Output'>
```json
{
"status": 201,
"message": "http://kekkai-api.redume.su/static/charts/RUB_USD_20250226_RX02RN.png"
}
```
</Aside>
## What the name of the chart file consists of
Example: ``.../RUB_USD_20241108_DQVDN7.png``
- `RUB_USD` - Name of currencies.
- `20241108` - Schedule request date in `YYYMMDD` format.
- `DQVDN7` - Random file character identifier.
All charts are in the charts folder, which is in the root directory (`/chart`)

View file

@ -0,0 +1,79 @@
---
title: Get metadata - /api/metadata
---
Currencies are identified by standard three-letter `ISO 4217` currency codes.
import { Tabs, TabItem, Aside } from '@astrojs/starlight/components';
## Get data on available dates and currencies.
### Request
<Tabs>
<TabItem label='Shell'>
<Tabs>
<TabItem label='curl'>
```shell
curl --request GET --url https://kekkai-api.redume.su/api/metadata/
```
</TabItem>
</Tabs>
</TabItem>
<TabItem label='Python'>
<Tabs>
<TabItem label='requests'>
```python
import requests
res = requests.get('https://kekkai-api.redume.su/api/metadata/', timeout=3)
print(res.json())
```
</TabItem>
</Tabs>
</TabItem>
<TabItem label='Node.JS'>
<Tabs>
<TabItem label='axios'>
```javascript
const axios = require('axios');
axios.get('https://kekkai-api.redume.su/api/metadata/')
.then((res) => {
console.log(JSON.stringify(res.json()));
})
.catch((err) => {
console.error(err);
});
```
</TabItem>
</Tabs>
</TabItem>
</Tabs>
### Response
<Aside title='Output'>
```json
{
"first_date": "2024-11-26T21:00:00.000Z",
"last_date": "2025-01-01T21:00:00.000Z",
"currencies": {
"crypto": [
"USDT",
"TON",
"BTC",
"ETH"
],
"fiat": [
"USD",
"RUB",
"EUR",
"UAH",
"TRY",
"KZT"
]
}
}
```
</Aside>