@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 +88 -33
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,33 +1,88 @@
|
|
|
1
|
-
# @sc-db/sdk
|
|
2
|
-
|
|
3
|
-
Typed client for the SCDB API
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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:
|
|
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(
|
|
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 ?? "
|
|
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