@skinpricer/sdk 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # @skinpricer/sdk
2
+
3
+ ## 0.1.0
4
+
5
+ Initial release.
6
+
7
+ - `SkinpricerClient` with typed resource namespaces for all 19 API-key-protected pricing endpoints:
8
+ `pricing`, `history`, `nbbo`, `aggregations`, `items`, `status`, `arbitrage`, `recommendations`,
9
+ `marketAnalytics`, `attributePrices`, `buff163`.
10
+ - Zero runtime dependencies — built on the platform `fetch`.
11
+ - Typed error hierarchy (`AuthenticationError`, `FeatureNotAvailableError`, `RateLimitError`,
12
+ `ValidationError`, `NotFoundError`, `ServerError`, `NetworkError`, `TimeoutError`).
13
+ - Rate-limit metadata, request timeouts, `AbortSignal` cancellation, and GET-only retry with backoff.
14
+ - Opt-in money helpers (`centsToUsd`, `formatUsd`) and `parseIsoDate`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Skinpricer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # @skinpricer/sdk
2
+
3
+ Official, fully-typed TypeScript SDK for the [Skinpricer](https://skinpricer.com) pricing API —
4
+ real-time and historical CS2 skin market pricing, NBBO, order-book depth, arbitrage,
5
+ recommendations, and attribute (float/fade/tag) pricing.
6
+
7
+ - **Fully typed** — every request param and response is typed; responses mirror the API exactly.
8
+ - **Zero runtime dependencies** — built on the platform `fetch` (Node 18+, Bun, Deno, edge, browsers).
9
+ - **Typed errors** — `AuthenticationError`, `RateLimitError`, `FeatureNotAvailableError`, and more.
10
+ - **Batteries included** — request timeouts, `AbortSignal` cancellation, automatic retries with
11
+ backoff, and rate-limit metadata.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @skinpricer/sdk
17
+ # or: pnpm add @skinpricer/sdk / yarn add @skinpricer/sdk
18
+ ```
19
+
20
+ Requires Node.js ≥ 18.17 (or any runtime with a global `fetch`).
21
+
22
+ ## Quick start
23
+
24
+ ```ts
25
+ import { SkinpricerClient, centsToUsd } from "@skinpricer/sdk";
26
+
27
+ const client = new SkinpricerClient({
28
+ apiKey: process.env.SKINPRICER_API_KEY!,
29
+ });
30
+
31
+ const price = await client.pricing.get("AK-47 | Redline (Field-Tested)", {
32
+ markets: ["csfloat", "buff163"],
33
+ });
34
+
35
+ console.log(price.aggregate?.minPrice); // integer USD cents
36
+ console.log(centsToUsd(price.aggregate?.minPrice ?? 0)); // 15.5
37
+ ```
38
+
39
+ > **Prices are integer USD cents.** Timestamps are ISO-8601 strings. Use the opt-in helpers
40
+ > `centsToUsd` / `formatUsd` and `parseIsoDate` when you want dollars or `Date`s.
41
+
42
+ ## Configuration
43
+
44
+ ```ts
45
+ const client = new SkinpricerClient({
46
+ apiKey: "sk_live_...", // required
47
+ baseUrl: "https://pricing.skinpricer.com/v1", // default
48
+ timeoutMs: 30_000, // per-request timeout
49
+ authScheme: "Bearer", // or 'ApiKey'
50
+ retry: { maxRetries: 2 }, // or `false` to disable
51
+ headers: { "X-Tenant": "acme" }, // extra headers (Authorization is not overridable)
52
+ // fetch: customFetch, // bring your own fetch
53
+ });
54
+ ```
55
+
56
+ ## Resources
57
+
58
+ | Namespace | Methods |
59
+ | ------------------------ | ---------------------------- |
60
+ | `client.pricing` | `get`, `listings` |
61
+ | `client.history` | `get`, `byMarket` |
62
+ | `client.nbbo` | `get`, `depth` |
63
+ | `client.aggregations` | `minPrices`, `maxOrders` |
64
+ | `client.items` | `search`, `all` |
65
+ | `client.status` | `freshness`, `marketLatency` |
66
+ | `client.arbitrage` | `opportunities` |
67
+ | `client.recommendations` | `get` |
68
+ | `client.marketAnalytics` | `get` |
69
+ | `client.attributePrices` | `latest`, `history` |
70
+ | `client.buff163` | `latest`, `history` |
71
+
72
+ Every method accepts an optional trailing `RequestOptions` (`{ signal, timeoutMs, retry }`).
73
+
74
+ ## Error handling
75
+
76
+ ```ts
77
+ import {
78
+ SkinpricerError,
79
+ AuthenticationError,
80
+ FeatureNotAvailableError,
81
+ RateLimitError,
82
+ NotFoundError,
83
+ } from "@skinpricer/sdk";
84
+
85
+ try {
86
+ await client.nbbo.get({ marketHashName: "AWP | Asiimov (Field-Tested)" });
87
+ } catch (err) {
88
+ if (err instanceof RateLimitError) {
89
+ console.log(`Rate limited — retry after ${err.retryAfterSeconds}s`);
90
+ } else if (err instanceof FeatureNotAvailableError) {
91
+ console.log("Your plan does not include this endpoint.");
92
+ } else if (err instanceof AuthenticationError) {
93
+ console.log("Invalid or inactive API key.");
94
+ } else if (err instanceof NotFoundError) {
95
+ console.log("Item not tracked.");
96
+ } else if (err instanceof SkinpricerError) {
97
+ console.log(`API error ${err.status}: ${err.message}`);
98
+ }
99
+ }
100
+ ```
101
+
102
+ ## Rate-limit metadata
103
+
104
+ Methods return the response data directly. Rate-limit headers and status are attached as
105
+ non-enumerable metadata — read them with `getMeta`:
106
+
107
+ ```ts
108
+ import { getMeta } from "@skinpricer/sdk";
109
+
110
+ const nbbo = await client.nbbo.get({ id: "clx123" });
111
+ const meta = getMeta(nbbo);
112
+ console.log(meta?.rateLimit.remaining, meta?.rateLimit.resetSeconds);
113
+ ```
114
+
115
+ ## Cancellation & timeouts
116
+
117
+ ```ts
118
+ const controller = new AbortController();
119
+ setTimeout(() => controller.abort(), 1_000);
120
+
121
+ await client.items.all({ signal: controller.signal, timeoutMs: 5_000 });
122
+ ```
123
+
124
+ ## Power features
125
+
126
+ **Typed markets** — `markets` filters autocomplete the known market ids while still accepting any string:
127
+
128
+ ```ts
129
+ import { KNOWN_MARKETS } from "@skinpricer/sdk";
130
+ await client.pricing.get(name, { markets: ["csfloat", "buff163"] }); // ↖ autocompleted
131
+ ```
132
+
133
+ **Auto-pagination** — iterate every result without managing pages or cursors:
134
+
135
+ ```ts
136
+ for await (const item of client.items.searchEach({ search: "AK-47" })) {
137
+ console.log(item.name);
138
+ }
139
+ // cursor-based endpoints too:
140
+ for await (const bucket of client.attributePrices.latestEach({
141
+ canonicalItemId,
142
+ })) {
143
+ /* … */
144
+ }
145
+ ```
146
+
147
+ **Auto-batching** — `minPricesAll` / `maxOrdersAll` transparently chunk >100 ids (the server cap) with bounded concurrency and merge the results:
148
+
149
+ ```ts
150
+ const { items } = await client.aggregations.minPricesAll(thousandsOfIds, {
151
+ concurrency: 5,
152
+ });
153
+ ```
154
+
155
+ **Proactive rate-limit throttling** (opt-in) — when a response reports `X-RateLimit-Remaining: 0`, the client waits for the window to reset instead of firing a request that is guaranteed to 429:
156
+
157
+ ```ts
158
+ const client = new SkinpricerClient({ apiKey, autoThrottle: true });
159
+ ```
160
+
161
+ **Observability hooks** — for logging, metrics, and tracing (hook errors never break a request):
162
+
163
+ ```ts
164
+ const client = new SkinpricerClient({
165
+ apiKey,
166
+ hooks: {
167
+ onRequest: ({ method, url, attempt }) =>
168
+ log.debug({ method, url, attempt }),
169
+ onResponse: ({ status, rateLimit }) =>
170
+ metrics.record(status, rateLimit.remaining),
171
+ onRetry: ({ attempt, delayMs, status }) =>
172
+ log.warn(`retry #${attempt + 1} in ${delayMs}ms (status ${status})`),
173
+ },
174
+ });
175
+ ```
176
+
177
+ ## License
178
+
179
+ MIT