@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 +14 -0
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/index.cjs +1103 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +947 -0
- package/dist/index.d.ts +947 -0
- package/dist/index.js +1061 -0
- package/dist/index.js.map +1 -0
- package/package.json +90 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1061 @@
|
|
|
1
|
+
// src/errors/base.ts
|
|
2
|
+
var SkinpricerError = class _SkinpricerError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
code;
|
|
5
|
+
requestId;
|
|
6
|
+
responseBody;
|
|
7
|
+
rateLimit;
|
|
8
|
+
constructor(message, options = {}) {
|
|
9
|
+
super(
|
|
10
|
+
message,
|
|
11
|
+
options.cause !== void 0 ? { cause: options.cause } : void 0
|
|
12
|
+
);
|
|
13
|
+
this.name = new.target.name;
|
|
14
|
+
this.status = options.status;
|
|
15
|
+
this.code = options.code;
|
|
16
|
+
this.requestId = options.requestId ?? null;
|
|
17
|
+
this.responseBody = options.responseBody;
|
|
18
|
+
this.rateLimit = options.rateLimit;
|
|
19
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
20
|
+
}
|
|
21
|
+
static isSkinpricerError(value) {
|
|
22
|
+
return value instanceof _SkinpricerError;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/errors/network-errors.ts
|
|
27
|
+
var NetworkError = class extends SkinpricerError {
|
|
28
|
+
};
|
|
29
|
+
var TimeoutError = class extends NetworkError {
|
|
30
|
+
};
|
|
31
|
+
var ConfigurationError = class extends SkinpricerError {
|
|
32
|
+
};
|
|
33
|
+
var ParseError = class extends SkinpricerError {
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/version.ts
|
|
37
|
+
var VERSION = "0.1.0";
|
|
38
|
+
|
|
39
|
+
// src/config.ts
|
|
40
|
+
var DEFAULT_BASE_URL = "https://pricing.skinpricer.com/v1";
|
|
41
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
42
|
+
var DEFAULT_RETRY = {
|
|
43
|
+
maxRetries: 2,
|
|
44
|
+
baseDelayMs: 250,
|
|
45
|
+
maxDelayMs: 8e3,
|
|
46
|
+
retryOnMethods: ["GET"],
|
|
47
|
+
respectRetryAfter: true
|
|
48
|
+
};
|
|
49
|
+
function resolveFetch(custom) {
|
|
50
|
+
if (custom) return custom;
|
|
51
|
+
const globalFetch = globalThis.fetch;
|
|
52
|
+
if (typeof globalFetch === "function") {
|
|
53
|
+
return globalFetch.bind(globalThis);
|
|
54
|
+
}
|
|
55
|
+
throw new ConfigurationError(
|
|
56
|
+
"No global `fetch` is available. Provide a `fetch` implementation in the client config (required on Node < 18 or non-fetch runtimes)."
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
function resolveRetry(retry) {
|
|
60
|
+
if (retry === false) return null;
|
|
61
|
+
if (retry === void 0) return DEFAULT_RETRY;
|
|
62
|
+
return { ...DEFAULT_RETRY, ...retry };
|
|
63
|
+
}
|
|
64
|
+
function normalizeBaseUrl(baseUrl) {
|
|
65
|
+
const trimmed = baseUrl.replace(/\/+$/, "");
|
|
66
|
+
let parsed;
|
|
67
|
+
try {
|
|
68
|
+
parsed = new URL(trimmed);
|
|
69
|
+
} catch {
|
|
70
|
+
throw new ConfigurationError(
|
|
71
|
+
`\`baseUrl\` is not a valid URL: "${baseUrl}"`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
75
|
+
throw new ConfigurationError(
|
|
76
|
+
`\`baseUrl\` must use http: or https: (got "${parsed.protocol}").`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return trimmed;
|
|
80
|
+
}
|
|
81
|
+
function resolveConfig(config) {
|
|
82
|
+
if (typeof config.apiKey !== "string" || config.apiKey.trim().length === 0) {
|
|
83
|
+
throw new ConfigurationError(
|
|
84
|
+
"A non-empty `apiKey` is required to construct SkinpricerClient."
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
apiKey: config.apiKey,
|
|
89
|
+
baseUrl: normalizeBaseUrl(config.baseUrl ?? DEFAULT_BASE_URL),
|
|
90
|
+
fetch: resolveFetch(config.fetch),
|
|
91
|
+
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
92
|
+
retry: resolveRetry(config.retry),
|
|
93
|
+
headers: { ...config.headers },
|
|
94
|
+
authScheme: config.authScheme ?? "Bearer",
|
|
95
|
+
userAgent: config.userAgent ?? `skinpricer-sdk/${VERSION}`,
|
|
96
|
+
autoThrottle: config.autoThrottle ?? false,
|
|
97
|
+
hooks: config.hooks ?? {}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/errors/http-errors.ts
|
|
102
|
+
var APIError = class extends SkinpricerError {
|
|
103
|
+
};
|
|
104
|
+
var ValidationError = class extends APIError {
|
|
105
|
+
messages;
|
|
106
|
+
constructor(message, options = {}) {
|
|
107
|
+
super(message, options);
|
|
108
|
+
this.messages = options.messages ?? [];
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var AuthenticationError = class extends APIError {
|
|
112
|
+
};
|
|
113
|
+
var PermissionError = class extends APIError {
|
|
114
|
+
};
|
|
115
|
+
var FeatureNotAvailableError = class extends PermissionError {
|
|
116
|
+
};
|
|
117
|
+
var NotFoundError = class extends APIError {
|
|
118
|
+
};
|
|
119
|
+
var RateLimitError = class extends APIError {
|
|
120
|
+
/** Seconds to wait before retrying (`Retry-After`). */
|
|
121
|
+
retryAfterSeconds;
|
|
122
|
+
limit;
|
|
123
|
+
remaining;
|
|
124
|
+
resetSeconds;
|
|
125
|
+
constructor(message, options = {}) {
|
|
126
|
+
super(message, options);
|
|
127
|
+
this.retryAfterSeconds = options.retryAfterSeconds ?? null;
|
|
128
|
+
this.limit = options.limit ?? null;
|
|
129
|
+
this.remaining = options.remaining ?? null;
|
|
130
|
+
this.resetSeconds = options.resetSeconds ?? null;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var ServerError = class extends APIError {
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/hooks.ts
|
|
137
|
+
async function runHook(hook, ctx) {
|
|
138
|
+
if (!hook) return;
|
|
139
|
+
try {
|
|
140
|
+
await hook(ctx);
|
|
141
|
+
} catch {
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/utils/abort.ts
|
|
146
|
+
function abortError(signal) {
|
|
147
|
+
const reason = signal?.reason;
|
|
148
|
+
if (reason instanceof Error) return reason;
|
|
149
|
+
return new DOMException("The operation was aborted.", "AbortError");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/utils/sleep.ts
|
|
153
|
+
function sleep(ms, signal) {
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
if (signal?.aborted) {
|
|
156
|
+
reject(abortError(signal));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
function cleanup() {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
signal?.removeEventListener("abort", onAbort);
|
|
162
|
+
}
|
|
163
|
+
function onAbort() {
|
|
164
|
+
cleanup();
|
|
165
|
+
reject(abortError(signal));
|
|
166
|
+
}
|
|
167
|
+
const timer = setTimeout(() => {
|
|
168
|
+
cleanup();
|
|
169
|
+
resolve();
|
|
170
|
+
}, ms);
|
|
171
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/errors/from-response.ts
|
|
176
|
+
function defaultMessage(status) {
|
|
177
|
+
return `Request failed with status ${status}`;
|
|
178
|
+
}
|
|
179
|
+
function truncate(value, max) {
|
|
180
|
+
return value.length > max ? `${value.slice(0, max)}\u2026` : value;
|
|
181
|
+
}
|
|
182
|
+
function isRecord(value) {
|
|
183
|
+
return typeof value === "object" && value !== null;
|
|
184
|
+
}
|
|
185
|
+
function extractErrorFields(body, status) {
|
|
186
|
+
if (isRecord(body)) {
|
|
187
|
+
if (body.success === false && isRecord(body.error)) {
|
|
188
|
+
const err = body.error;
|
|
189
|
+
const message = typeof err.message === "string" ? err.message : defaultMessage(status);
|
|
190
|
+
const result = { message };
|
|
191
|
+
if (typeof err.code === "string") result.code = err.code;
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
const rawMessage = body.message;
|
|
195
|
+
if (Array.isArray(rawMessage)) {
|
|
196
|
+
const messages = rawMessage.filter(
|
|
197
|
+
(entry) => typeof entry === "string"
|
|
198
|
+
);
|
|
199
|
+
return {
|
|
200
|
+
message: messages.length > 0 ? messages.join(", ") : defaultMessage(status),
|
|
201
|
+
messages
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (typeof rawMessage === "string") {
|
|
205
|
+
return { message: rawMessage };
|
|
206
|
+
}
|
|
207
|
+
if (typeof body.error === "string") {
|
|
208
|
+
return { message: body.error };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (typeof body === "string" && body.trim().length > 0) {
|
|
212
|
+
return { message: truncate(body, 500) };
|
|
213
|
+
}
|
|
214
|
+
return { message: defaultMessage(status) };
|
|
215
|
+
}
|
|
216
|
+
function looksLikeFeatureError(message) {
|
|
217
|
+
return /feature|does not include|plan/i.test(message);
|
|
218
|
+
}
|
|
219
|
+
function errorFromResponse(input) {
|
|
220
|
+
const { status, body, meta } = input;
|
|
221
|
+
const { code, message, messages } = extractErrorFields(body, status);
|
|
222
|
+
const base = {
|
|
223
|
+
status,
|
|
224
|
+
code,
|
|
225
|
+
requestId: meta.requestId,
|
|
226
|
+
responseBody: body,
|
|
227
|
+
rateLimit: meta.rateLimit
|
|
228
|
+
};
|
|
229
|
+
switch (status) {
|
|
230
|
+
case 400:
|
|
231
|
+
return new ValidationError(message, { ...base, messages });
|
|
232
|
+
case 401:
|
|
233
|
+
return new AuthenticationError(message, base);
|
|
234
|
+
case 403:
|
|
235
|
+
return code === "FEATURE_NOT_AVAILABLE" || looksLikeFeatureError(message) ? new FeatureNotAvailableError(message, base) : new PermissionError(message, base);
|
|
236
|
+
case 404:
|
|
237
|
+
return new NotFoundError(message, base);
|
|
238
|
+
case 429:
|
|
239
|
+
return new RateLimitError(message, {
|
|
240
|
+
...base,
|
|
241
|
+
retryAfterSeconds: meta.rateLimit.retryAfterSeconds,
|
|
242
|
+
limit: meta.rateLimit.limit,
|
|
243
|
+
remaining: meta.rateLimit.remaining,
|
|
244
|
+
resetSeconds: meta.rateLimit.resetSeconds
|
|
245
|
+
});
|
|
246
|
+
default:
|
|
247
|
+
if (status >= 500) return new ServerError(message, base);
|
|
248
|
+
return new APIError(message, base);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/http/rate-limit.ts
|
|
253
|
+
function readInt(headers, name) {
|
|
254
|
+
const raw = headers.get(name);
|
|
255
|
+
if (raw === null) return null;
|
|
256
|
+
const value = Number.parseInt(raw, 10);
|
|
257
|
+
return Number.isFinite(value) ? value : null;
|
|
258
|
+
}
|
|
259
|
+
function parseRateLimit(headers) {
|
|
260
|
+
return {
|
|
261
|
+
limit: readInt(headers, "x-ratelimit-limit"),
|
|
262
|
+
remaining: readInt(headers, "x-ratelimit-remaining"),
|
|
263
|
+
resetSeconds: readInt(headers, "x-ratelimit-reset"),
|
|
264
|
+
month: {
|
|
265
|
+
limit: readInt(headers, "x-ratelimit-limit-month"),
|
|
266
|
+
remaining: readInt(headers, "x-ratelimit-remaining-month"),
|
|
267
|
+
resetSeconds: readInt(headers, "x-ratelimit-reset-month")
|
|
268
|
+
},
|
|
269
|
+
retryAfterSeconds: readInt(headers, "retry-after")
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/http/parse-response.ts
|
|
274
|
+
function buildMeta(response) {
|
|
275
|
+
return {
|
|
276
|
+
status: response.status,
|
|
277
|
+
requestId: response.headers.get("x-request-id"),
|
|
278
|
+
rateLimit: parseRateLimit(response.headers),
|
|
279
|
+
headers: response.headers
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function tryJsonParse(text) {
|
|
283
|
+
try {
|
|
284
|
+
return JSON.parse(text);
|
|
285
|
+
} catch {
|
|
286
|
+
return void 0;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function parseResponse(response) {
|
|
290
|
+
const meta = buildMeta(response);
|
|
291
|
+
const text = await response.text();
|
|
292
|
+
if (response.ok) {
|
|
293
|
+
if (text.length === 0) {
|
|
294
|
+
return { data: {}, meta };
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
return { data: JSON.parse(text), meta };
|
|
298
|
+
} catch (cause) {
|
|
299
|
+
throw new ParseError("Failed to parse response body as JSON.", {
|
|
300
|
+
status: response.status,
|
|
301
|
+
responseBody: text,
|
|
302
|
+
cause,
|
|
303
|
+
rateLimit: meta.rateLimit,
|
|
304
|
+
requestId: meta.requestId
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const parsed = text.length > 0 ? tryJsonParse(text) : void 0;
|
|
309
|
+
const body = parsed !== void 0 ? parsed : text.length > 0 ? text : void 0;
|
|
310
|
+
throw errorFromResponse({ status: response.status, body, meta });
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/utils/url.ts
|
|
314
|
+
function encodePathSegment(segment) {
|
|
315
|
+
return encodeURIComponent(segment);
|
|
316
|
+
}
|
|
317
|
+
function joinUrl(baseUrl, path) {
|
|
318
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
319
|
+
return `${baseUrl}${normalizedPath}`;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/http/query.ts
|
|
323
|
+
function serializeQuery(params) {
|
|
324
|
+
const search = new URLSearchParams();
|
|
325
|
+
for (const [key, value] of Object.entries(params)) {
|
|
326
|
+
if (value === void 0 || value === null) continue;
|
|
327
|
+
if (value instanceof Date) {
|
|
328
|
+
search.append(key, value.toISOString());
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (Array.isArray(value)) {
|
|
332
|
+
if (value.length === 0) continue;
|
|
333
|
+
search.append(key, value.map((entry) => String(entry)).join(","));
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
search.append(key, String(value));
|
|
337
|
+
}
|
|
338
|
+
const serialized = search.toString();
|
|
339
|
+
return serialized.length > 0 ? `?${serialized}` : "";
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/http/request-builder.ts
|
|
343
|
+
function buildRequest(config, input) {
|
|
344
|
+
const queryString = input.query ? serializeQuery(input.query) : "";
|
|
345
|
+
const url = joinUrl(config.baseUrl, input.path) + queryString;
|
|
346
|
+
const headers = {
|
|
347
|
+
Accept: "application/json",
|
|
348
|
+
"User-Agent": config.userAgent,
|
|
349
|
+
"X-Skinpricer-Client": config.userAgent,
|
|
350
|
+
...config.headers
|
|
351
|
+
};
|
|
352
|
+
let body;
|
|
353
|
+
if (input.body !== void 0) {
|
|
354
|
+
body = JSON.stringify(input.body);
|
|
355
|
+
headers["Content-Type"] = "application/json";
|
|
356
|
+
}
|
|
357
|
+
headers["Authorization"] = `${config.authScheme} ${config.apiKey}`;
|
|
358
|
+
const prepared = { url, method: input.method, headers };
|
|
359
|
+
if (body !== void 0) prepared.body = body;
|
|
360
|
+
return prepared;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/http/retry.ts
|
|
364
|
+
function isRetryableStatus(status) {
|
|
365
|
+
return status === 429 || status >= 500;
|
|
366
|
+
}
|
|
367
|
+
function shouldRetry(input) {
|
|
368
|
+
const { method, attempt, retry, status } = input;
|
|
369
|
+
if (attempt >= retry.maxRetries) return false;
|
|
370
|
+
if (!retry.retryOnMethods.includes(method)) return false;
|
|
371
|
+
if (status === null) return true;
|
|
372
|
+
return isRetryableStatus(status);
|
|
373
|
+
}
|
|
374
|
+
function backoffDelayMs(attempt, retry, rng = Math.random) {
|
|
375
|
+
const ceiling = Math.min(retry.baseDelayMs * 2 ** attempt, retry.maxDelayMs);
|
|
376
|
+
return Math.floor(rng() * ceiling);
|
|
377
|
+
}
|
|
378
|
+
function retryDelayMs(input) {
|
|
379
|
+
const { attempt, retry, retryAfterSeconds, rng } = input;
|
|
380
|
+
if (retry.respectRetryAfter && retryAfterSeconds !== null && retryAfterSeconds >= 0) {
|
|
381
|
+
return Math.min(retryAfterSeconds * 1e3, retry.maxDelayMs);
|
|
382
|
+
}
|
|
383
|
+
return backoffDelayMs(attempt, retry, rng);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/http/timeout.ts
|
|
387
|
+
function withTimeout(timeoutMs, external) {
|
|
388
|
+
const controller = new AbortController();
|
|
389
|
+
let timedOut = false;
|
|
390
|
+
let timer;
|
|
391
|
+
function onExternalAbort() {
|
|
392
|
+
controller.abort(external ? abortError(external) : void 0);
|
|
393
|
+
}
|
|
394
|
+
if (external) {
|
|
395
|
+
if (external.aborted) {
|
|
396
|
+
controller.abort(abortError(external));
|
|
397
|
+
} else {
|
|
398
|
+
external.addEventListener("abort", onExternalAbort, { once: true });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (timeoutMs > 0 && !controller.signal.aborted) {
|
|
402
|
+
timer = setTimeout(() => {
|
|
403
|
+
timedOut = true;
|
|
404
|
+
controller.abort(
|
|
405
|
+
new DOMException(
|
|
406
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
407
|
+
"TimeoutError"
|
|
408
|
+
)
|
|
409
|
+
);
|
|
410
|
+
}, timeoutMs);
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
signal: controller.signal,
|
|
414
|
+
cleanup() {
|
|
415
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
416
|
+
external?.removeEventListener("abort", onExternalAbort);
|
|
417
|
+
},
|
|
418
|
+
didTimeout() {
|
|
419
|
+
return timedOut;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/http/http-client.ts
|
|
425
|
+
var MAX_THROTTLE_WAIT_MS = 6e4;
|
|
426
|
+
function resolveRequestRetry(base, override) {
|
|
427
|
+
if (override === false) return null;
|
|
428
|
+
if (override === void 0) return base;
|
|
429
|
+
return { ...base ?? DEFAULT_RETRY, ...override };
|
|
430
|
+
}
|
|
431
|
+
function networkMessage(error) {
|
|
432
|
+
return error instanceof Error ? error.message : "Network request failed.";
|
|
433
|
+
}
|
|
434
|
+
var HttpClient = class {
|
|
435
|
+
constructor(config) {
|
|
436
|
+
this.config = config;
|
|
437
|
+
}
|
|
438
|
+
config;
|
|
439
|
+
throttleUntil = 0;
|
|
440
|
+
async request(input, options = {}) {
|
|
441
|
+
const prepared = buildRequest(this.config, input);
|
|
442
|
+
const retry = resolveRequestRetry(this.config.retry, options.retry);
|
|
443
|
+
const timeoutMs = options.timeoutMs ?? this.config.timeoutMs;
|
|
444
|
+
const callerSignal = options.signal;
|
|
445
|
+
const { hooks } = this.config;
|
|
446
|
+
await this.awaitThrottle(callerSignal);
|
|
447
|
+
let attempt = 0;
|
|
448
|
+
for (; ; ) {
|
|
449
|
+
const handle = withTimeout(timeoutMs, callerSignal);
|
|
450
|
+
await runHook(hooks.onRequest, {
|
|
451
|
+
method: input.method,
|
|
452
|
+
url: prepared.url,
|
|
453
|
+
attempt
|
|
454
|
+
});
|
|
455
|
+
let response;
|
|
456
|
+
try {
|
|
457
|
+
response = await this.config.fetch(prepared.url, {
|
|
458
|
+
method: prepared.method,
|
|
459
|
+
headers: prepared.headers,
|
|
460
|
+
body: prepared.body,
|
|
461
|
+
signal: handle.signal
|
|
462
|
+
});
|
|
463
|
+
} catch (error) {
|
|
464
|
+
handle.cleanup();
|
|
465
|
+
if (callerSignal?.aborted && !handle.didTimeout()) {
|
|
466
|
+
throw abortError(callerSignal);
|
|
467
|
+
}
|
|
468
|
+
if (retry && shouldRetry({ method: input.method, attempt, retry, status: null })) {
|
|
469
|
+
const delayMs = retryDelayMs({
|
|
470
|
+
attempt,
|
|
471
|
+
retry,
|
|
472
|
+
retryAfterSeconds: null
|
|
473
|
+
});
|
|
474
|
+
await runHook(hooks.onRetry, {
|
|
475
|
+
method: input.method,
|
|
476
|
+
url: prepared.url,
|
|
477
|
+
attempt,
|
|
478
|
+
delayMs,
|
|
479
|
+
status: null
|
|
480
|
+
});
|
|
481
|
+
await sleep(delayMs, callerSignal);
|
|
482
|
+
attempt += 1;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (handle.didTimeout()) {
|
|
486
|
+
throw new TimeoutError(`Request timed out after ${timeoutMs}ms`, {
|
|
487
|
+
cause: error
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
throw new NetworkError(networkMessage(error), { cause: error });
|
|
491
|
+
}
|
|
492
|
+
handle.cleanup();
|
|
493
|
+
try {
|
|
494
|
+
const parsed = await parseResponse(response);
|
|
495
|
+
this.recordRateLimit(parsed.meta.rateLimit);
|
|
496
|
+
await runHook(hooks.onResponse, {
|
|
497
|
+
method: input.method,
|
|
498
|
+
url: prepared.url,
|
|
499
|
+
attempt,
|
|
500
|
+
status: parsed.meta.status,
|
|
501
|
+
rateLimit: parsed.meta.rateLimit
|
|
502
|
+
});
|
|
503
|
+
return parsed;
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if (error instanceof RateLimitError) {
|
|
506
|
+
this.recordRateLimit(error.rateLimit, error.retryAfterSeconds);
|
|
507
|
+
}
|
|
508
|
+
if (error instanceof SkinpricerError && error.status !== void 0 && retry && shouldRetry({
|
|
509
|
+
method: input.method,
|
|
510
|
+
attempt,
|
|
511
|
+
retry,
|
|
512
|
+
status: error.status
|
|
513
|
+
})) {
|
|
514
|
+
const retryAfterSeconds = error instanceof RateLimitError ? error.retryAfterSeconds : error.rateLimit?.retryAfterSeconds ?? null;
|
|
515
|
+
const delayMs = retryDelayMs({ attempt, retry, retryAfterSeconds });
|
|
516
|
+
await runHook(hooks.onRetry, {
|
|
517
|
+
method: input.method,
|
|
518
|
+
url: prepared.url,
|
|
519
|
+
attempt,
|
|
520
|
+
delayMs,
|
|
521
|
+
status: error.status,
|
|
522
|
+
error
|
|
523
|
+
});
|
|
524
|
+
await sleep(delayMs, callerSignal);
|
|
525
|
+
attempt += 1;
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
throw error;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
recordRateLimit(rateLimit, retryAfterSeconds) {
|
|
533
|
+
if (!this.config.autoThrottle || !rateLimit) return;
|
|
534
|
+
const waitSeconds = retryAfterSeconds ?? (rateLimit.remaining === 0 ? rateLimit.resetSeconds : null);
|
|
535
|
+
if (waitSeconds === null || waitSeconds <= 0) return;
|
|
536
|
+
const waitMs = Math.min(waitSeconds * 1e3, MAX_THROTTLE_WAIT_MS);
|
|
537
|
+
this.throttleUntil = Math.max(this.throttleUntil, Date.now() + waitMs);
|
|
538
|
+
}
|
|
539
|
+
async awaitThrottle(signal) {
|
|
540
|
+
if (!this.config.autoThrottle) return;
|
|
541
|
+
const waitMs = this.throttleUntil - Date.now();
|
|
542
|
+
if (waitMs > 0) {
|
|
543
|
+
await sleep(waitMs, signal);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// src/utils/batch.ts
|
|
549
|
+
function chunk(items, size) {
|
|
550
|
+
if (size <= 0) throw new RangeError("chunk size must be greater than 0");
|
|
551
|
+
const out = [];
|
|
552
|
+
for (let i = 0; i < items.length; i += size) {
|
|
553
|
+
out.push(items.slice(i, i + size));
|
|
554
|
+
}
|
|
555
|
+
return out;
|
|
556
|
+
}
|
|
557
|
+
async function mapWithConcurrency(items, limit, fn) {
|
|
558
|
+
if (limit <= 0)
|
|
559
|
+
throw new RangeError("concurrency limit must be greater than 0");
|
|
560
|
+
const results = new Array(items.length);
|
|
561
|
+
let cursor = 0;
|
|
562
|
+
async function worker() {
|
|
563
|
+
for (; ; ) {
|
|
564
|
+
const index = cursor++;
|
|
565
|
+
if (index >= items.length) return;
|
|
566
|
+
results[index] = await fn(items[index], index);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const poolSize = Math.min(limit, items.length);
|
|
570
|
+
await Promise.all(Array.from({ length: poolSize }, () => worker()));
|
|
571
|
+
return results;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/meta.ts
|
|
575
|
+
var RESPONSE_META = /* @__PURE__ */ Symbol("skinpricer.responseMeta");
|
|
576
|
+
function attachMeta(data, meta) {
|
|
577
|
+
if (data !== null && typeof data === "object") {
|
|
578
|
+
Object.defineProperty(data, RESPONSE_META, {
|
|
579
|
+
value: meta,
|
|
580
|
+
enumerable: false,
|
|
581
|
+
writable: false,
|
|
582
|
+
configurable: true
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
return data;
|
|
586
|
+
}
|
|
587
|
+
function getMeta(value) {
|
|
588
|
+
if (value !== null && typeof value === "object") {
|
|
589
|
+
return value[RESPONSE_META];
|
|
590
|
+
}
|
|
591
|
+
return void 0;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// src/resources/resource.ts
|
|
595
|
+
var BaseResource = class {
|
|
596
|
+
constructor(http) {
|
|
597
|
+
this.http = http;
|
|
598
|
+
}
|
|
599
|
+
http;
|
|
600
|
+
/** Performs a request and returns the data with {@link ResponseMeta} attached. */
|
|
601
|
+
async call(input, options) {
|
|
602
|
+
const { data, meta } = await this.http.request(input, options);
|
|
603
|
+
return attachMeta(data, meta);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// src/resources/aggregations.ts
|
|
608
|
+
var MAX_IDS_PER_REQUEST = 100;
|
|
609
|
+
var DEFAULT_BATCH_CONCURRENCY = 5;
|
|
610
|
+
var AggregationsResource = class extends BaseResource {
|
|
611
|
+
/** GET /v1/aggregations/min-prices — minimum sell price per market (max 100 ids). */
|
|
612
|
+
minPrices(params, options) {
|
|
613
|
+
return this.call(
|
|
614
|
+
{
|
|
615
|
+
method: "GET",
|
|
616
|
+
path: "/aggregations/min-prices",
|
|
617
|
+
query: { ids: params.ids, markets: params.markets }
|
|
618
|
+
},
|
|
619
|
+
options
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
/** GET /v1/aggregations/max-orders — maximum buy order per market (max 100 ids). */
|
|
623
|
+
maxOrders(params, options) {
|
|
624
|
+
return this.call(
|
|
625
|
+
{
|
|
626
|
+
method: "GET",
|
|
627
|
+
path: "/aggregations/max-orders",
|
|
628
|
+
query: { ids: params.ids, markets: params.markets }
|
|
629
|
+
},
|
|
630
|
+
options
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
/** Like `minPrices` but splits more than 100 ids into batches and merges them. */
|
|
634
|
+
async minPricesAll(ids, params = {}, options) {
|
|
635
|
+
const items = await this.runBatched(
|
|
636
|
+
ids,
|
|
637
|
+
params,
|
|
638
|
+
(chunkIds) => this.minPrices(
|
|
639
|
+
{ ids: chunkIds, markets: params.markets },
|
|
640
|
+
options
|
|
641
|
+
).then((res) => res.items)
|
|
642
|
+
);
|
|
643
|
+
return { items };
|
|
644
|
+
}
|
|
645
|
+
/** Like `maxOrders` but splits more than 100 ids into batches and merges them. */
|
|
646
|
+
async maxOrdersAll(ids, params = {}, options) {
|
|
647
|
+
const items = await this.runBatched(
|
|
648
|
+
ids,
|
|
649
|
+
params,
|
|
650
|
+
(chunkIds) => this.maxOrders(
|
|
651
|
+
{ ids: chunkIds, markets: params.markets },
|
|
652
|
+
options
|
|
653
|
+
).then((res) => res.items)
|
|
654
|
+
);
|
|
655
|
+
return { items };
|
|
656
|
+
}
|
|
657
|
+
async runBatched(ids, params, fetchChunk) {
|
|
658
|
+
if (ids.length === 0) return [];
|
|
659
|
+
const chunks = chunk(ids, MAX_IDS_PER_REQUEST);
|
|
660
|
+
const concurrency = params.concurrency ?? DEFAULT_BATCH_CONCURRENCY;
|
|
661
|
+
const batches = await mapWithConcurrency(chunks, concurrency, fetchChunk);
|
|
662
|
+
return batches.flat();
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
// src/resources/arbitrage.ts
|
|
667
|
+
var ArbitrageResource = class extends BaseResource {
|
|
668
|
+
/** `GET /v1/arbitrage/opportunities` — ranked cross-market opportunities. */
|
|
669
|
+
opportunities(params = {}, options) {
|
|
670
|
+
return this.call(
|
|
671
|
+
{
|
|
672
|
+
method: "GET",
|
|
673
|
+
path: "/arbitrage/opportunities",
|
|
674
|
+
query: {
|
|
675
|
+
limit: params.limit,
|
|
676
|
+
minSpreadBps: params.minSpreadBps,
|
|
677
|
+
minNotionalCents: params.minNotionalCents,
|
|
678
|
+
minNotional: params.minNotional,
|
|
679
|
+
sort: params.sort,
|
|
680
|
+
markets: params.markets,
|
|
681
|
+
candidateLimit: params.candidateLimit
|
|
682
|
+
}
|
|
683
|
+
},
|
|
684
|
+
options
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/resources/attribute-prices.ts
|
|
690
|
+
var AttributePricesResource = class extends BaseResource {
|
|
691
|
+
/** GET /v1/attribute-prices/latest — latest attribute buckets across markets. */
|
|
692
|
+
latest(params = {}, options) {
|
|
693
|
+
return this.call(
|
|
694
|
+
{
|
|
695
|
+
method: "GET",
|
|
696
|
+
path: "/attribute-prices/latest",
|
|
697
|
+
query: {
|
|
698
|
+
canonicalItemId: params.canonicalItemId,
|
|
699
|
+
marketHashName: params.marketHashName,
|
|
700
|
+
attributes: params.attributes,
|
|
701
|
+
limit: params.limit,
|
|
702
|
+
cursor: params.cursor,
|
|
703
|
+
markets: params.markets
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
options
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
/** GET /v1/attribute-prices/history — OHLC attribute bucket history. */
|
|
710
|
+
history(params = {}, options) {
|
|
711
|
+
return this.call(
|
|
712
|
+
{
|
|
713
|
+
method: "GET",
|
|
714
|
+
path: "/attribute-prices/history",
|
|
715
|
+
query: {
|
|
716
|
+
canonicalItemId: params.canonicalItemId,
|
|
717
|
+
marketHashName: params.marketHashName,
|
|
718
|
+
bucketId: params.bucketId,
|
|
719
|
+
bucketIds: params.bucketIds,
|
|
720
|
+
attributes: params.attributes,
|
|
721
|
+
from: params.from,
|
|
722
|
+
to: params.to,
|
|
723
|
+
granularity: params.granularity,
|
|
724
|
+
limit: params.limit,
|
|
725
|
+
markets: params.markets
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
options
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
/** Async iterator over every latest attribute item, following `nextCursor`. */
|
|
732
|
+
async *latestEach(params = {}, options) {
|
|
733
|
+
let cursor = params.cursor;
|
|
734
|
+
for (; ; ) {
|
|
735
|
+
const res = await this.latest({ ...params, cursor }, options);
|
|
736
|
+
for (const item of res.items) {
|
|
737
|
+
yield item;
|
|
738
|
+
}
|
|
739
|
+
const next = res.nextCursor;
|
|
740
|
+
if (next === null || next === cursor) return;
|
|
741
|
+
cursor = next;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
// src/resources/buff163.ts
|
|
747
|
+
var Buff163Resource = class extends BaseResource {
|
|
748
|
+
/** GET /v1/markets/buff163/latest — latest Buff163 attribute buckets. */
|
|
749
|
+
latest(params = {}, options) {
|
|
750
|
+
return this.call(
|
|
751
|
+
{
|
|
752
|
+
method: "GET",
|
|
753
|
+
path: "/markets/buff163/latest",
|
|
754
|
+
query: {
|
|
755
|
+
canonicalItemId: params.canonicalItemId,
|
|
756
|
+
marketHashName: params.marketHashName,
|
|
757
|
+
attributes: params.attributes,
|
|
758
|
+
limit: params.limit,
|
|
759
|
+
cursor: params.cursor
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
options
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
/** GET /v1/markets/buff163/history — OHLC Buff163 attribute bucket history. */
|
|
766
|
+
history(params = {}, options) {
|
|
767
|
+
return this.call(
|
|
768
|
+
{
|
|
769
|
+
method: "GET",
|
|
770
|
+
path: "/markets/buff163/history",
|
|
771
|
+
query: {
|
|
772
|
+
canonicalItemId: params.canonicalItemId,
|
|
773
|
+
marketHashName: params.marketHashName,
|
|
774
|
+
bucketId: params.bucketId,
|
|
775
|
+
bucketIds: params.bucketIds,
|
|
776
|
+
attributes: params.attributes,
|
|
777
|
+
from: params.from,
|
|
778
|
+
to: params.to,
|
|
779
|
+
granularity: params.granularity,
|
|
780
|
+
limit: params.limit
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
options
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
/** Async iterator over every latest Buff163 attribute item, following `nextCursor`. */
|
|
787
|
+
async *latestEach(params = {}, options) {
|
|
788
|
+
let cursor = params.cursor;
|
|
789
|
+
for (; ; ) {
|
|
790
|
+
const res = await this.latest({ ...params, cursor }, options);
|
|
791
|
+
for (const item of res.items) {
|
|
792
|
+
yield item;
|
|
793
|
+
}
|
|
794
|
+
const next = res.nextCursor;
|
|
795
|
+
if (next === null || next === cursor) return;
|
|
796
|
+
cursor = next;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
// src/resources/history.ts
|
|
802
|
+
function historyQuery(params) {
|
|
803
|
+
return {
|
|
804
|
+
from: params.from,
|
|
805
|
+
to: params.to,
|
|
806
|
+
markets: params.markets,
|
|
807
|
+
listingType: params.listingType,
|
|
808
|
+
salesWindow: params.salesWindow,
|
|
809
|
+
interval: params.interval
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
var HistoryResource = class extends BaseResource {
|
|
813
|
+
/** `GET /v1/pricing/:marketHashName/history` — aggregated time series. */
|
|
814
|
+
get(marketHashName, params = {}, options) {
|
|
815
|
+
return this.call(
|
|
816
|
+
{
|
|
817
|
+
method: "GET",
|
|
818
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/history`,
|
|
819
|
+
query: historyQuery(params)
|
|
820
|
+
},
|
|
821
|
+
options
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
/** `GET /v1/pricing/:marketHashName/history/markets` — per-market series. */
|
|
825
|
+
byMarket(marketHashName, params = {}, options) {
|
|
826
|
+
return this.call(
|
|
827
|
+
{
|
|
828
|
+
method: "GET",
|
|
829
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/history/markets`,
|
|
830
|
+
query: historyQuery(params)
|
|
831
|
+
},
|
|
832
|
+
options
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
// src/resources/items.ts
|
|
838
|
+
var ItemsResource = class extends BaseResource {
|
|
839
|
+
/** GET /v1/items — paginated item search with current pricing. */
|
|
840
|
+
search(params = {}, options) {
|
|
841
|
+
return this.call(
|
|
842
|
+
{
|
|
843
|
+
method: "GET",
|
|
844
|
+
path: "/items",
|
|
845
|
+
query: {
|
|
846
|
+
search: params.search,
|
|
847
|
+
markets: params.markets,
|
|
848
|
+
page: params.page,
|
|
849
|
+
perPage: params.perPage
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
options
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
/** GET /v1/items/all — every tracked item with latest prices (capped, unpaginated). */
|
|
856
|
+
all(options) {
|
|
857
|
+
return this.call(
|
|
858
|
+
{ method: "GET", path: "/items/all" },
|
|
859
|
+
options
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
/** Async iterator over every matching item, walking pages. */
|
|
863
|
+
async *searchEach(params = {}, options) {
|
|
864
|
+
let page = params.page ?? 1;
|
|
865
|
+
for (; ; ) {
|
|
866
|
+
const res = await this.search({ ...params, page }, options);
|
|
867
|
+
for (const item of res.data) {
|
|
868
|
+
yield item;
|
|
869
|
+
}
|
|
870
|
+
const next = res.pagination.nextPage;
|
|
871
|
+
if (next === null || next <= page) return;
|
|
872
|
+
page = next;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
// src/resources/market-analytics.ts
|
|
878
|
+
var MarketAnalyticsResource = class extends BaseResource {
|
|
879
|
+
/** `GET /v1/market-analytics/:marketHashName` — per-market analytics rows. */
|
|
880
|
+
get(marketHashName, params = {}, options) {
|
|
881
|
+
return this.call(
|
|
882
|
+
{
|
|
883
|
+
method: "GET",
|
|
884
|
+
path: `/market-analytics/${encodePathSegment(marketHashName)}`,
|
|
885
|
+
query: { markets: params.markets, windowHours: params.windowHours }
|
|
886
|
+
},
|
|
887
|
+
options
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
// src/resources/nbbo.ts
|
|
893
|
+
var NbboResource = class extends BaseResource {
|
|
894
|
+
/** `GET /v1/nbbo` — best bid/ask across markets. Pass `id` or `marketHashName`. */
|
|
895
|
+
get(params, options) {
|
|
896
|
+
return this.call(
|
|
897
|
+
{
|
|
898
|
+
method: "GET",
|
|
899
|
+
path: "/nbbo",
|
|
900
|
+
query: {
|
|
901
|
+
id: params.id,
|
|
902
|
+
market_hash_name: params.marketHashName,
|
|
903
|
+
markets: params.markets
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
options
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
/** `GET /v1/nbbo/depth` — aggregated order-book depth per side. */
|
|
910
|
+
depth(params, options) {
|
|
911
|
+
return this.call(
|
|
912
|
+
{
|
|
913
|
+
method: "GET",
|
|
914
|
+
path: "/nbbo/depth",
|
|
915
|
+
query: {
|
|
916
|
+
id: params.id,
|
|
917
|
+
market_hash_name: params.marketHashName,
|
|
918
|
+
markets: params.markets,
|
|
919
|
+
depth: params.depth
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
options
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
// src/resources/pricing.ts
|
|
928
|
+
var PricingResource = class extends BaseResource {
|
|
929
|
+
/** `GET /v1/pricing/:marketHashName` — full cross-market pricing snapshot. */
|
|
930
|
+
get(marketHashName, params = {}, options) {
|
|
931
|
+
return this.call(
|
|
932
|
+
{
|
|
933
|
+
method: "GET",
|
|
934
|
+
path: `/pricing/${encodePathSegment(marketHashName)}`,
|
|
935
|
+
query: { markets: params.markets }
|
|
936
|
+
},
|
|
937
|
+
options
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
/** `GET /v1/pricing/:marketHashName/listings` — individual listing samples. */
|
|
941
|
+
listings(marketHashName, params = {}, options) {
|
|
942
|
+
return this.call(
|
|
943
|
+
{
|
|
944
|
+
method: "GET",
|
|
945
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/listings`,
|
|
946
|
+
query: { limit: params.limit, markets: params.markets }
|
|
947
|
+
},
|
|
948
|
+
options
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
// src/resources/recommendations.ts
|
|
954
|
+
var RecommendationsResource = class extends BaseResource {
|
|
955
|
+
/** `GET /v1/recommendations/:marketHashName` — suggested price + confidence. */
|
|
956
|
+
get(marketHashName, params = {}, options) {
|
|
957
|
+
return this.call(
|
|
958
|
+
{
|
|
959
|
+
method: "GET",
|
|
960
|
+
path: `/recommendations/${encodePathSegment(marketHashName)}`,
|
|
961
|
+
query: { markets: params.markets }
|
|
962
|
+
},
|
|
963
|
+
options
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
// src/resources/status.ts
|
|
969
|
+
var StatusResource = class extends BaseResource {
|
|
970
|
+
/** `GET /v1/status/freshness` — per-market data freshness and overall health. */
|
|
971
|
+
freshness(options) {
|
|
972
|
+
return this.call(
|
|
973
|
+
{ method: "GET", path: "/status/freshness" },
|
|
974
|
+
options
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
/** `GET /v1/status/market-latency` — fetch-to-ingest latency metrics per market. */
|
|
978
|
+
marketLatency(options) {
|
|
979
|
+
return this.call(
|
|
980
|
+
{ method: "GET", path: "/status/market-latency" },
|
|
981
|
+
options
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
// src/client.ts
|
|
987
|
+
var SkinpricerClient = class {
|
|
988
|
+
pricing;
|
|
989
|
+
history;
|
|
990
|
+
nbbo;
|
|
991
|
+
aggregations;
|
|
992
|
+
items;
|
|
993
|
+
status;
|
|
994
|
+
arbitrage;
|
|
995
|
+
recommendations;
|
|
996
|
+
marketAnalytics;
|
|
997
|
+
attributePrices;
|
|
998
|
+
buff163;
|
|
999
|
+
httpClient;
|
|
1000
|
+
constructor(config) {
|
|
1001
|
+
this.httpClient = new HttpClient(resolveConfig(config));
|
|
1002
|
+
this.pricing = new PricingResource(this.httpClient);
|
|
1003
|
+
this.history = new HistoryResource(this.httpClient);
|
|
1004
|
+
this.nbbo = new NbboResource(this.httpClient);
|
|
1005
|
+
this.aggregations = new AggregationsResource(this.httpClient);
|
|
1006
|
+
this.items = new ItemsResource(this.httpClient);
|
|
1007
|
+
this.status = new StatusResource(this.httpClient);
|
|
1008
|
+
this.arbitrage = new ArbitrageResource(this.httpClient);
|
|
1009
|
+
this.recommendations = new RecommendationsResource(this.httpClient);
|
|
1010
|
+
this.marketAnalytics = new MarketAnalyticsResource(this.httpClient);
|
|
1011
|
+
this.attributePrices = new AttributePricesResource(this.httpClient);
|
|
1012
|
+
this.buff163 = new Buff163Resource(this.httpClient);
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
// src/types/markets.ts
|
|
1017
|
+
var KNOWN_MARKETS = [
|
|
1018
|
+
"skinport",
|
|
1019
|
+
"skindeck",
|
|
1020
|
+
"buff163",
|
|
1021
|
+
"csfloat",
|
|
1022
|
+
"marketcsgo",
|
|
1023
|
+
"cstrade",
|
|
1024
|
+
"dmarket",
|
|
1025
|
+
"itrade",
|
|
1026
|
+
"lis-skins",
|
|
1027
|
+
"swapgg",
|
|
1028
|
+
"whitemarket",
|
|
1029
|
+
"waxpeer",
|
|
1030
|
+
"lootfarm",
|
|
1031
|
+
"tradeit-store",
|
|
1032
|
+
"tradeit-trade",
|
|
1033
|
+
"steamcommunity"
|
|
1034
|
+
];
|
|
1035
|
+
var ATTRIBUTE_MARKETS = [
|
|
1036
|
+
"buff163",
|
|
1037
|
+
"steamcommunity",
|
|
1038
|
+
"marketcsgo",
|
|
1039
|
+
"csfloat",
|
|
1040
|
+
"dmarket"
|
|
1041
|
+
];
|
|
1042
|
+
|
|
1043
|
+
// src/utils/money.ts
|
|
1044
|
+
function centsToUsd(cents) {
|
|
1045
|
+
return cents / 100;
|
|
1046
|
+
}
|
|
1047
|
+
function formatUsd(cents, options = {}) {
|
|
1048
|
+
const { currency = "USD", locale = "en-US" } = options;
|
|
1049
|
+
return new Intl.NumberFormat(locale, { style: "currency", currency }).format(
|
|
1050
|
+
cents / 100
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// src/utils/dates.ts
|
|
1055
|
+
function parseIsoDate(value) {
|
|
1056
|
+
return new Date(value);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
export { APIError, ATTRIBUTE_MARKETS, AggregationsResource, ArbitrageResource, AttributePricesResource, AuthenticationError, BaseResource, Buff163Resource, ConfigurationError, DEFAULT_BASE_URL, DEFAULT_RETRY, DEFAULT_TIMEOUT_MS, FeatureNotAvailableError, HistoryResource, ItemsResource, KNOWN_MARKETS, MarketAnalyticsResource, NbboResource, NetworkError, NotFoundError, ParseError, PermissionError, PricingResource, RESPONSE_META, RateLimitError, RecommendationsResource, ServerError, SkinpricerClient, SkinpricerError, StatusResource, TimeoutError, VERSION, ValidationError, centsToUsd, chunk, errorFromResponse, formatUsd, getMeta, mapWithConcurrency, parseIsoDate, resolveConfig };
|
|
1060
|
+
//# sourceMappingURL=index.js.map
|
|
1061
|
+
//# sourceMappingURL=index.js.map
|