@sc-db/sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,33 +1,88 @@
1
- # @sc-db/sdk — TypeScript SDK
2
-
3
- Typed client for the SCDB API. Types are generated from the API's OpenAPI spec,
4
- so the SDK always matches the server.
5
-
6
- ```ts
7
- import { createScdb } from "@sc-db/sdk";
8
-
9
- const scdb = createScdb({ baseUrl: "http://127.0.0.1:8000" });
10
-
11
- await scdb.stats();
12
- await scdb.types();
13
- await scdb.records({ type: "EntityClassDefinition", name: "gladius", is_main: true });
14
- await scdb.record(guid); // full record + raw body
15
- await scdb.refs(guid); // outgoing references
16
- await scdb.refsIn(guid); // incoming references
17
- ```
18
-
19
- ## Dev
20
- ```bash
21
- npm install
22
- npm run gen # regenerate src/schema.ts from openapi.json
23
- npm run build # tsc -> dist/
24
- node example.mjs # smoke test (API must be running)
25
- ```
26
-
27
- Refresh `openapi.json` after API changes:
28
- ```bash
29
- # from repo root
30
- uv run python -c "import json; from api.main import app; json.dump(app.openapi(), open('sdk/js/openapi.json','w'), indent=2)"
31
- ```
32
-
33
- Other language SDKs will live alongside this one: `sdk/python/`, etc.
1
+ # @sc-db/sdk
2
+
3
+ Typed TypeScript client for the **[SCDB](https://sc-db.fr) API** open, free data for
4
+ [Star Citizen](https://robertsspaceindustries.com/), derived 100% from the game files
5
+ (DataForge + the `Data.p4k` archive): ships, items, FPS gear, missions & contracts,
6
+ crafting blueprints, the 3D starmap, and per-body mining tables.
7
+
8
+ The API is public and read-only — **no API key, no auth**. Types are generated from the
9
+ API's OpenAPI spec, so the client always matches the live server.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm i @sc-db/sdk
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { createScdb } from "@sc-db/sdk";
21
+
22
+ const scdb = createScdb(); // defaults to https://api.sc-db.fr
23
+
24
+ // ships
25
+ const ships = await scdb.ships({ name: "gladius" });
26
+ const ship = await scdb.ship(guid); // detail + default loadout
27
+
28
+ // items / FPS gear (filter by type, size, manufacturer…)
29
+ const rifles = await scdb.items({ category: "fps_weapon", size: 3 });
30
+
31
+ // mining — what's mineable where, with probabilities
32
+ const cellin = await scdb.miningBody("Stanton2a");
33
+ const spots = await scdb.miningProspect(["Quantainium", "Taranite"]); // best places
34
+
35
+ // starmap
36
+ const systems = await scdb.starmapSystems();
37
+ const crusader = await scdb.starmapObject("Stanton2");
38
+ ```
39
+
40
+ Point it at your own instance with `createScdb({ baseUrl: "https://…" })`.
41
+
42
+ ## What you can query
43
+
44
+ | Area | Methods |
45
+ | --- | --- |
46
+ | Meta | `stats` · `meta` · `types` |
47
+ | Records (raw + graph) | `records` · `record` · `refs` · `refsIn` |
48
+ | Ships | `ships` · `ship` |
49
+ | Items | `items` · `itemFacets` · `item` · `compareItems` |
50
+ | Missions & contracts | `missions` · `mission` · `contracts` · `contract` · `contractTypes` · `contractFactions` |
51
+ | Blueprints | `blueprints` · `blueprint` · `blueprintCategories` |
52
+ | Starmap & locations | `starmap` · `starmapObject` · `starmapSystems` · `locations` · `locationTypes` |
53
+ | Mining | `miningBodies` · `miningBody` · `miningElements` · `miningDeposits` · `miningProspect` |
54
+ | Localization | `localization` · `localizationKey` |
55
+
56
+ Every method is fully typed (request + response). Errors throw `ScdbError`.
57
+ `scdb.raw` exposes the underlying [openapi-fetch](https://openapi-ts.dev/openapi-fetch/)
58
+ client as an escape hatch.
59
+
60
+ ## Caching
61
+
62
+ GET responses are cached in memory. The data only changes once per game patch, so the
63
+ cache **never expires by time** — instead it's keyed on the build version and refreshes
64
+ automatically when the API ships a new patch:
65
+
66
+ ```ts
67
+ await scdb.checkVersion(); // poll for a new patch; flushes the cache if it changed
68
+ scdb.clearCache(); // drop everything manually
69
+ createScdb({ cache: false }); // opt out entirely
70
+ ```
71
+
72
+ ## Rate limit
73
+
74
+ The public API is rate-limited per IP (120 requests / 60s by default). On `429` the
75
+ response carries `Retry-After`. Please cache responses (the SDK does) rather than hammering
76
+ it — and use this client instead of scraping the website.
77
+
78
+ ## Links
79
+
80
+ - API reference (Swagger): https://api.sc-db.fr/docs
81
+ - OpenAPI spec: https://api.sc-db.fr/openapi.json
82
+ - Website: https://sc-db.fr
83
+ - Source: https://github.com/Romain-Boudot/sc-db
84
+
85
+ ## License
86
+
87
+ MIT · Unofficial project, not affiliated with Cloud Imperium Games. Data belongs to CIG;
88
+ this only re-exposes what ships in the game client.
package/dist/index.d.ts CHANGED
@@ -47,7 +47,7 @@ export type ShipsQuery = NonNullable<paths["/ships"]["get"]["parameters"]["query
47
47
  export type ItemsQuery = NonNullable<paths["/items"]["get"]["parameters"]["query"]>;
48
48
  export type ItemFacetsQuery = NonNullable<paths["/items/facets"]["get"]["parameters"]["query"]>;
49
49
  export interface ScdbOptions {
50
- /** API base URL. Default: http://127.0.0.1:8000 */
50
+ /** API base URL. Default: https://api.sc-db.fr */
51
51
  baseUrl?: string;
52
52
  /** Custom fetch (e.g. for SSR / auth). Default: global fetch. */
53
53
  fetch?: typeof fetch;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * SCDB SDK — typed TypeScript client for the SCDB API.
3
3
  *
4
4
  * import { createScdb } from "@sc-db/sdk";
5
- * const scdb = createScdb({ baseUrl: "http://127.0.0.1:8000" });
5
+ * const scdb = createScdb(); // defaults to https://api.sc-db.fr
6
6
  * const page = await scdb.records({ type: "EntityClassDefinition", name: "gladius" });
7
7
  */
8
8
  import createClient from "openapi-fetch";
@@ -15,7 +15,7 @@ function unwrap(data, error) {
15
15
  return data;
16
16
  }
17
17
  export function createScdb(opts = {}) {
18
- const baseUrl = opts.baseUrl ?? "http://127.0.0.1:8000";
18
+ const baseUrl = opts.baseUrl ?? "https://api.sc-db.fr";
19
19
  const baseFetch = opts.fetch ?? globalThis.fetch;
20
20
  const useCache = opts.cache !== false;
21
21
  // url -> Response (kept un-consumed; every read returns a fresh clone)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sc-db/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "TypeScript SDK for the SCDB API — open Star Citizen data (DataForge)",
5
5
  "keywords": ["star-citizen", "starcitizen", "dataforge", "scdb", "sdk", "api-client"],
6
6
  "license": "MIT",