XYLEX Group

or specify a different project name

Update latest version

Purpose: keep the root package.json version in sync with the latest entry from the versioning table for a given project_name.

How it works

  • Fetch: posts to https://api.suitsbooks.com/fetch/data with table_name: "versioning" and a condition on project_name.
  • Select latest: reads the first row from the response and extracts version_major, version_minor, version_patch.
  • Write: composes major.minor.patch and updates the root package.json version if it differs.

Usage

python scripts/update_latest_version.py
# or specify a different project name
python scripts/update_latest_version.py -p app.suitsbooks.nl
```typescript

- **Flags**:
  - `-p`, `--project_name`: which `versioning.project_name` to query. Defaults to `app.suitsbooks.nl`.

- **Requirements**:
  - Python 3.9+
  - `requests` (`pip install requests`)

### Script reference

API call and header setup:

```python
import requests
import json
import os
import argparse

API_URL = "https://api.suitsbooks.com/fetch/data"
HEADERS = {
    "apikey": "0bX3I2fTMACUNTHNJC0lChzGXWl_V6kXPI_i8b0153a5",
    "x-xbp-telemetry": "true",
    "Content-Type": "application/json",
}
```typescript

Core update flow:

```python
def update_package_json_version(project_name: str = "app.suitsbooks.nl"):
    data = {
        "table_name": "versioning",
        "conditions": [{"eq_column": "project_name", "eq_value": project_name}],
        "limit": 100,
        "schema": "public",
    }

    resp = requests.post(API_URL, headers=HEADERS, data=json.dumps(data))
    if resp.status_code != 200:
        print(f"Failed to fetch versioning info: {resp.status_code}")
        exit(1)
    res = resp.json()
    if not res.get("success") or not res.get("data"):
        print("No versioning info received or request unsuccessful.")
        exit(1)
    latest = res["data"][0]
    major = latest["version_major"]
    minor = latest["version_minor"]
    patch = latest["version_patch"]
    new_version = f"{major}.{minor}.{patch}"
```typescript

CLI entrypoint and flag:

```python
if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Update package.json version based on latest 'versioning' table entry for a project."
    )
    parser.add_argument(
        "--project_name",
        "-p",
        type=str,
        default="app.suitsbooks.nl",
        help="The project_name to look up from the versioning table. Defaults to 'app.suitsbooks.nl'.",
    )
    args = parser.parse_args()
    update_package_json_version(project_name=args.project_name)
```typescript

### Notes

- The script only updates `package.json` when the computed version differs.
- Non-200 responses or missing data will exit with an error message.