diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index d798d65..794e7a9 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -19,13 +19,13 @@ This is a modular single-binary Rust utility that fetches Antares B2B product da - `src/api/client.rs` - handles URL construction for the Antares B2B API - `src/tools/excel.rs` - implements Excel export with selective field mapping and business rule validation - `src/tools/logger.rs` - provides dual output (terminal + file) logging to `log/{YYYY-MM-DD}.log` -- `src/template/antares.rs` - serde models with `#[serde(rename_all = "PascalCase")]`; top-level is `Antares` alias for `Vec` +- `src/template/antares.rs` - serde models with `#[serde(rename_all = "PascalCase")]`; top-level is `Antares` alias for `Vec`; also contains `AntaresLogin` struct holding credentials and base URL **Pipeline:** 1. Initialize logger (creates `log/` dir if needed) 2. Load credentials from `.env` via `dotenv` -3. Build Antares API URL using `src/api/client::make_url()` -4. Fetch with 300-second timeout via blocking `reqwest::blocking::Client` +3. Build Antares API URL using `src/api/client::make_url()` (takes an `AntaresLogin` struct) +4. Fetch with 600-second timeout via blocking `reqwest::blocking::Client` (in `src/tools/request.rs`) 5. Deserialize into typed `Antares` structs; if schema mismatch, preserve response as JSON/text 6. Write `antares.json` with pretty formatting 7. Export filtered rows to `out/antares_export.xlsx` via `src/tools/excel::export_to_excel()` @@ -39,13 +39,15 @@ This is a modular single-binary Rust utility that fetches Antares B2B product da ## Key conventions **Credentials:** -- Load only via `ANTARES_USERCODE` and `ANTARES_PASSWORD` env vars from `.env` +- Load via `URL`, `ANTARES_USERCODE`, `ANTARES_PASSWORD`, and `OUT` env vars from `.env` +- `URL` is the Antares B2B base URL; `OUT` is the output file path for the Excel export - `.env.example` documents required variables - No hardcoded credentials; missing vars cause graceful failure with instructions +- `PASSWORD` is wrapped in `Zeroizing` (from the `zeroize` crate) to securely wipe it from memory after use **Artifacts:** -- `antares.json` - saved at repo root after each successful API fetch -- `out/antares_export.xlsx` - Excel export; `out/` directory created auto if missing +- `temp/antares.json` - saved in `temp/` after each successful API fetch; directory created auto if missing +- Excel export path is configured via the `OUT` env var; parent directory created auto if missing - `log/{YYYY-MM-DD}.log` - daily logs; `log/` directory created auto if missing - `.gitignore` excludes: `*.json`, `*.xlsx`, `.env`, `/out`, `/log` @@ -64,9 +66,9 @@ This is a modular single-binary Rust utility that fetches Antares B2B product da **Modularity:** - Extend by adding new files to `src/tools/` (e.g., `csv.rs`, `database.rs`) - Each tool should be self-contained and exposed via `src/tools/mod.rs` -- HTTP client logic stays in `src/api/`; reuse `make_request()` from `main.rs` for consistency +- HTTP client logic stays in `src/tools/request.rs`; reuse `make_request()` from there for consistency **Blocking HTTP:** -- Uses `reqwest::blocking::Client` with 300-second timeout +- Uses `reqwest::blocking::Client` with 600-second timeout (in `src/tools/request.rs`) - No async runtime; synchronous flow is intentional - Only change to async if architecture overhaul is deliberate diff --git a/AGENTS.md b/AGENTS.md deleted file mode 100644 index 3fadb87..0000000 --- a/AGENTS.md +++ /dev/null @@ -1,30 +0,0 @@ -# Antares Data Exporter - Operational Guide for Agents - -This repository contains a synchronous Rust utility that fetches product data from the Antares B2B API and exports it to Excel. Follow these instructions for successful operation and development. - -## โš™๏ธ Execution & Setup -1. **Setup:** Always run `cp .env.example .env` first, then fill credentials in `.env`. -2. **Build/Run Order:** The intended command sequence is: `cargo build --release` followed by running the binary (`./target/release/antares_get_data`). -3. **Development Flow:** Use this order when developing or verifying changes: - * `cargo fmt --all -- --check` (Linting) - * `cargo check` (Compile/Verify) - run after any file modifications - * `cargo test` (Testing) - -## ๐Ÿ’ป Architecture & Quirks -* **Blocking HTTP:** The API client uses `reqwest::blocking::Client`. This is intentional; the entire process is synchronous, and a 300-second timeout must be respected. -* **Credentials:** Only use `ANTARES_USERCODE` and `ANTARES_PASSWORD` from `.env`. Hardcoding credentials is prohibited. -* **Artifacts (Persistence):** Three key artifacts are generated daily/per run: - 1. `antares.json`: Raw API response data. Saved at the repo root. - 2. `out/antares_export.xlsx`: Final Excel export. The `out/` directory must exist. - 3. `log/{YYYY-MM-DD}.log`: Daily operational logs. The `log/` directory must exist. - -## ๐Ÿ“Š Business Logic (Excel Export Rules) -The Excel sheet does not use a simple JSON dump; it implements specific business rules: -* **Required Fields:** Rows are skipped if the product code (`cikkszam`) or product name is missing. -* **Column Mapping Precedence:** - * `BESZCIKKNEV`: Use `cikk_megnevezes_rovid`, falling back to `cikk_megnevezes`. - * **Export Filter:** Rows are skipped if the unit price (`EGYSEGAR`) is zero after applying business logic. - -## ๐Ÿ—‚๏ธ Module Ownership -* **Schema Changes:** Always update struct definitions in `src/template/antares.rs` before making changes to data handling logic. -* **Tooling:** New utility functions (e.g., CSV export) should be added as self-contained modules within `src/tools/`. \ No newline at end of file diff --git a/README.md b/README.md index 604af65..797be27 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ Rust utility to fetch product data from Antares B2B and export to Excel which ca ## Quick Start +Linux / MacOS: + ```bash cp .env.example .env # Edit .env with your credentials and output path @@ -18,6 +20,14 @@ cargo build --release ./target/release/antares_get_data ``` +Windows: +```cmd +copy .env.example .env +# Edit .env with your credentials and output path +cargo build --release +./target/release/antares_get_data +``` + ## Configuration `.env` file: @@ -36,7 +46,7 @@ OUT=out\\test.xlsx ## How It Works 1. Load credentials from `.env` -2. Fetch product data from Antares B2B API (300s timeout) +2. Fetch product data from Antares B2B API (600s timeout) 3. Save raw JSON to `antares.json` 4. Export filtered data to Excel 5. Log all operations to `log/YYYY-MM-DD.log` @@ -56,16 +66,8 @@ OUT=out\\test.xlsx | ME | [mennyisegi_egyseg_kod](./src/template/antares.rs#L17) | | EGYSEGAR | [netto_kisker_ar](./src/template/antares.rs#L19) or "Alap รกr" [jellemzo](./src/template/antares.rs#L34) | -Rows skipped if `cikkszam` or product name missing. +Rows skipped if `BESZCIKKSZAM` or `BESZCIKKNEV` missing. -## Development - -```bash -cargo build -cargo fmt --all -- --check -cargo clippy --all-targets -- -D warnings -cargo test -``` ## License