@carddb/client 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/README.md +33 -0
- package/dist/index.cjs +1249 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +780 -0
- package/dist/index.d.ts +780 -0
- package/dist/index.js +1219 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import * as _carddb_core from '@carddb/core';
|
|
2
|
+
import { Logger, LogLevel, Cache, ResourceType, CardDBConfig, RateLimitInfo, GraphQLErrorInfo, Collection, Publisher, Game, Dataset, Deck, DeckCreateInput, DeckUpdateInput, HydrateDeckEntryInput, HydratedDeckEntry, FilterInput, DatasetRecord, APIKeyInfo } from '@carddb/core';
|
|
3
|
+
export * from '@carddb/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration management for CardDB client
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const DEFAULT_ENDPOINT = "https://carddb.xtda.org/query";
|
|
10
|
+
declare const DEFAULT_TIMEOUT = 30000;
|
|
11
|
+
declare const DEFAULT_OPEN_TIMEOUT = 10000;
|
|
12
|
+
declare const DEFAULT_CACHE_TTL = 300;
|
|
13
|
+
declare const DEFAULT_MAX_RETRIES = 3;
|
|
14
|
+
declare const DEFAULT_MAX_NETWORK_RETRIES = 2;
|
|
15
|
+
declare const DEFAULT_RETRY_BASE_DELAY = 1000;
|
|
16
|
+
declare const DEFAULT_RETRY_MAX_DELAY = 30000;
|
|
17
|
+
declare class Configuration {
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
endpoint: string;
|
|
20
|
+
timeout: number;
|
|
21
|
+
openTimeout: number;
|
|
22
|
+
defaultPublisher?: string;
|
|
23
|
+
defaultGame?: string;
|
|
24
|
+
allowedPublishers?: string[];
|
|
25
|
+
allowedGames?: Record<string, string[]>;
|
|
26
|
+
logger?: Logger;
|
|
27
|
+
logLevel: LogLevel;
|
|
28
|
+
retryOnRateLimit: boolean;
|
|
29
|
+
maxRetries: number;
|
|
30
|
+
retryOnNetworkError: boolean;
|
|
31
|
+
maxNetworkRetries: number;
|
|
32
|
+
retryBaseDelay: number;
|
|
33
|
+
retryMaxDelay: number;
|
|
34
|
+
cache?: Cache;
|
|
35
|
+
cacheTtl: number;
|
|
36
|
+
cacheTtls: Partial<Record<ResourceType, number>>;
|
|
37
|
+
constructor(config?: CardDBConfig);
|
|
38
|
+
/**
|
|
39
|
+
* Calculate delay for exponential backoff
|
|
40
|
+
* @param attempt - The attempt number (0-indexed)
|
|
41
|
+
* @returns Delay in milliseconds with jitter
|
|
42
|
+
*/
|
|
43
|
+
calculateRetryDelay(attempt: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* Get the cache TTL for a specific resource type
|
|
46
|
+
*/
|
|
47
|
+
cacheTtlFor(resource: ResourceType): number;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve publisher slug, using default if not provided
|
|
50
|
+
*/
|
|
51
|
+
resolvePublisher(publisherSlug?: string): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve game key, using default if not provided
|
|
54
|
+
*/
|
|
55
|
+
resolveGame(gameKey?: string): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Validate that a publisher is allowed by the configuration
|
|
58
|
+
*/
|
|
59
|
+
validatePublisher(publisherSlug: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Validate that a game is allowed by the configuration
|
|
62
|
+
*/
|
|
63
|
+
validateGame(publisherSlug: string, gameKey: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Validate both publisher and game access
|
|
66
|
+
*/
|
|
67
|
+
validateAccess(publisherSlug?: string, gameKey?: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Check if a log level should be logged
|
|
70
|
+
*/
|
|
71
|
+
shouldLog(level: LogLevel): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Create a copy of this configuration with overrides
|
|
74
|
+
*/
|
|
75
|
+
merge(overrides: Partial<CardDBConfig>): Configuration;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* HTTP connection wrapper for GraphQL requests
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
interface GraphQLResponse {
|
|
83
|
+
data?: Record<string, unknown>;
|
|
84
|
+
errors?: GraphQLErrorInfo[];
|
|
85
|
+
}
|
|
86
|
+
declare function getRateLimitInfo(): RateLimitInfo | null;
|
|
87
|
+
declare class Connection {
|
|
88
|
+
private config;
|
|
89
|
+
constructor(config: Configuration);
|
|
90
|
+
/**
|
|
91
|
+
* Execute a GraphQL query
|
|
92
|
+
*/
|
|
93
|
+
execute(query: string, variables?: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
94
|
+
/**
|
|
95
|
+
* Check if an error is a retryable network error
|
|
96
|
+
*/
|
|
97
|
+
private isRetryableNetworkError;
|
|
98
|
+
private fetch;
|
|
99
|
+
private handleResponse;
|
|
100
|
+
private handleSuccessResponse;
|
|
101
|
+
private handleGraphQLErrors;
|
|
102
|
+
private handleRateLimitResponse;
|
|
103
|
+
private handleClientError;
|
|
104
|
+
private parseBody;
|
|
105
|
+
private extractRateLimitInfo;
|
|
106
|
+
private extractOperationName;
|
|
107
|
+
private sleep;
|
|
108
|
+
private logRequest;
|
|
109
|
+
private logResponse;
|
|
110
|
+
private logRateLimitRetry;
|
|
111
|
+
private logNetworkRetry;
|
|
112
|
+
private logError;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Base resource class with common functionality
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
declare abstract class BaseResource {
|
|
120
|
+
protected connection: Connection;
|
|
121
|
+
protected config: Configuration;
|
|
122
|
+
constructor(connection: Connection, config: Configuration);
|
|
123
|
+
/**
|
|
124
|
+
* Resolve publisher slug, using default if not provided
|
|
125
|
+
*/
|
|
126
|
+
protected resolvePublisher(publisherSlug?: string): string;
|
|
127
|
+
/**
|
|
128
|
+
* Resolve game key, using default if not provided
|
|
129
|
+
*/
|
|
130
|
+
protected resolveGame(gameKey?: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* Validate access to publisher/game
|
|
133
|
+
*/
|
|
134
|
+
protected validateAccess(publisherSlug?: string, gameKey?: string): void;
|
|
135
|
+
/**
|
|
136
|
+
* Execute a query with optional caching
|
|
137
|
+
*/
|
|
138
|
+
protected withCache<T>(key: string, resource: ResourceType, options: {
|
|
139
|
+
cache?: boolean;
|
|
140
|
+
}, fn: () => Promise<T>): Promise<T>;
|
|
141
|
+
/**
|
|
142
|
+
* Generate a cache key
|
|
143
|
+
*/
|
|
144
|
+
protected cacheKey(resource: string, method: string, params: Record<string, unknown>): string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Publishers resource for CardDB API
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
interface SearchPublishersOptions {
|
|
152
|
+
/** Search term to filter publishers by name */
|
|
153
|
+
search?: string;
|
|
154
|
+
/** Maximum number of results per page (default: 20, max: 100) */
|
|
155
|
+
first?: number;
|
|
156
|
+
/** Cursor for pagination */
|
|
157
|
+
after?: string;
|
|
158
|
+
/** Whether to use cache (defaults to client config) */
|
|
159
|
+
cache?: boolean;
|
|
160
|
+
}
|
|
161
|
+
interface GetPublisherOptions {
|
|
162
|
+
/** Whether to use cache (defaults to client config) */
|
|
163
|
+
cache?: boolean;
|
|
164
|
+
}
|
|
165
|
+
declare class PublishersResource extends BaseResource {
|
|
166
|
+
constructor(connection: Connection, config: Configuration);
|
|
167
|
+
/**
|
|
168
|
+
* Search for publishers
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* const publishers = await client.publishers.search({ search: 'pokemon' })
|
|
172
|
+
* for await (const publisher of publishers) {
|
|
173
|
+
* console.log(publisher.name)
|
|
174
|
+
* }
|
|
175
|
+
*/
|
|
176
|
+
search(options?: SearchPublishersOptions): Promise<Collection<Publisher>>;
|
|
177
|
+
/**
|
|
178
|
+
* Get a single publisher by slug or ID
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const publisher = await client.publishers.get('pokemon')
|
|
182
|
+
* const publisher = await client.publishers.get('550e8400-e29b-41d4-a716-446655440000')
|
|
183
|
+
*/
|
|
184
|
+
get(slugOrId: string, options?: GetPublisherOptions): Promise<Publisher | null>;
|
|
185
|
+
/**
|
|
186
|
+
* Get multiple publishers by slug
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* const publishers = await client.publishers.getMany(['pokemon', 'wizards'])
|
|
190
|
+
*/
|
|
191
|
+
getMany(slugs: string[], options?: GetPublisherOptions): Promise<Publisher[]>;
|
|
192
|
+
/**
|
|
193
|
+
* Check if a string is a valid UUID
|
|
194
|
+
*/
|
|
195
|
+
private isUUID;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Games resource for CardDB API
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
interface SearchGamesOptions {
|
|
203
|
+
/** Publisher slug to filter games */
|
|
204
|
+
publisherSlug?: string;
|
|
205
|
+
/** Search term to filter games by name */
|
|
206
|
+
search?: string;
|
|
207
|
+
/** Maximum number of results per page (default: 20, max: 100) */
|
|
208
|
+
first?: number;
|
|
209
|
+
/** Cursor for pagination */
|
|
210
|
+
after?: string;
|
|
211
|
+
/** Whether to use cache (defaults to client config) */
|
|
212
|
+
cache?: boolean;
|
|
213
|
+
}
|
|
214
|
+
interface GetGameOptions {
|
|
215
|
+
/** Whether to use cache (defaults to client config) */
|
|
216
|
+
cache?: boolean;
|
|
217
|
+
}
|
|
218
|
+
declare class GamesResource extends BaseResource {
|
|
219
|
+
constructor(connection: Connection, config: Configuration);
|
|
220
|
+
/**
|
|
221
|
+
* Search for games
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* // Search all games
|
|
225
|
+
* const games = await client.games.search({ search: 'trading card' })
|
|
226
|
+
*
|
|
227
|
+
* // Search games from a specific publisher
|
|
228
|
+
* const games = await client.games.search({ publisherSlug: 'pokemon' })
|
|
229
|
+
*/
|
|
230
|
+
search(options?: SearchGamesOptions): Promise<Collection<Game>>;
|
|
231
|
+
/**
|
|
232
|
+
* Get a single game by ID
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* const game = await client.games.get('550e8400-e29b-41d4-a716-446655440000')
|
|
236
|
+
*/
|
|
237
|
+
get(id: string, options?: GetGameOptions): Promise<Game | null>;
|
|
238
|
+
/**
|
|
239
|
+
* Get a single game by publisher slug and game key
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* const game = await client.games.get('pokemon', 'tcg')
|
|
243
|
+
*/
|
|
244
|
+
get(publisherSlug: string, gameKey: string, options?: GetGameOptions): Promise<Game | null>;
|
|
245
|
+
/**
|
|
246
|
+
* Get multiple games by ID
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* const games = await client.games.getMany(['id1', 'id2', 'id3'])
|
|
250
|
+
*/
|
|
251
|
+
getMany(ids: string[], options?: GetGameOptions): Promise<Game[]>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Datasets resource for CardDB API
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
interface SearchDatasetsOptions {
|
|
259
|
+
/** Publisher slug to filter datasets */
|
|
260
|
+
publisherSlug?: string;
|
|
261
|
+
/** Game key to filter datasets (requires publisherSlug) */
|
|
262
|
+
gameKey?: string;
|
|
263
|
+
/** Search term to filter datasets by name */
|
|
264
|
+
search?: string;
|
|
265
|
+
/** Dataset purpose to filter by */
|
|
266
|
+
purpose?: 'DATA' | 'RULES';
|
|
267
|
+
/** Maximum number of results per page (default: 20, max: 100) */
|
|
268
|
+
first?: number;
|
|
269
|
+
/** Cursor for pagination */
|
|
270
|
+
after?: string;
|
|
271
|
+
/** Whether to use cache (defaults to client config) */
|
|
272
|
+
cache?: boolean;
|
|
273
|
+
}
|
|
274
|
+
interface GetDatasetOptions {
|
|
275
|
+
/** Whether to use cache (defaults to client config) */
|
|
276
|
+
cache?: boolean;
|
|
277
|
+
}
|
|
278
|
+
declare class DatasetsResource extends BaseResource {
|
|
279
|
+
constructor(connection: Connection, config: Configuration);
|
|
280
|
+
/**
|
|
281
|
+
* Search for datasets
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* // Search all datasets
|
|
285
|
+
* const datasets = await client.datasets.search({ search: 'cards' })
|
|
286
|
+
*
|
|
287
|
+
* // Search datasets from a specific publisher and game
|
|
288
|
+
* const datasets = await client.datasets.search({
|
|
289
|
+
* publisherSlug: 'pokemon',
|
|
290
|
+
* gameKey: 'tcg'
|
|
291
|
+
* })
|
|
292
|
+
*/
|
|
293
|
+
search(options?: SearchDatasetsOptions): Promise<Collection<Dataset>>;
|
|
294
|
+
/**
|
|
295
|
+
* Get a single dataset by ID (includes schema)
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* const dataset = await client.datasets.get('550e8400-e29b-41d4-a716-446655440000')
|
|
299
|
+
*/
|
|
300
|
+
get(id: string, options?: GetDatasetOptions): Promise<Dataset | null>;
|
|
301
|
+
/**
|
|
302
|
+
* Get a single dataset by publisher slug, game key, and dataset key (includes schema)
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* const dataset = await client.datasets.get('pokemon', 'tcg', 'cards')
|
|
306
|
+
*/
|
|
307
|
+
get(publisherSlug: string, gameKey: string, datasetKey: string, options?: GetDatasetOptions): Promise<Dataset | null>;
|
|
308
|
+
/**
|
|
309
|
+
* Get multiple datasets by ID
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* const datasets = await client.datasets.getMany(['id1', 'id2', 'id3'])
|
|
313
|
+
*/
|
|
314
|
+
getMany(ids: string[], options?: GetDatasetOptions): Promise<Dataset[]>;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Decks resource for CardDB API
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
interface ListDecksOptions {
|
|
322
|
+
/** Maximum number of results per page */
|
|
323
|
+
first?: number;
|
|
324
|
+
/** Cursor for pagination */
|
|
325
|
+
after?: string;
|
|
326
|
+
/** Whether to use cache (defaults to client config) */
|
|
327
|
+
cache?: boolean;
|
|
328
|
+
}
|
|
329
|
+
interface FetchDeckOptions {
|
|
330
|
+
/** Whether to use cache (defaults to client config) */
|
|
331
|
+
cache?: boolean;
|
|
332
|
+
}
|
|
333
|
+
type FetchDeckByExternalRefOptions = FetchDeckOptions;
|
|
334
|
+
interface HydrateDeckEntriesOptions {
|
|
335
|
+
/** Publisher slug (uses default if configured) */
|
|
336
|
+
publisherSlug?: string;
|
|
337
|
+
/** Game key (uses default if configured) */
|
|
338
|
+
gameKey?: string;
|
|
339
|
+
/** Dataset key containing the deck entries */
|
|
340
|
+
datasetKey: string;
|
|
341
|
+
/** Field key used to map returned records to input identifiers */
|
|
342
|
+
identifierField?: string;
|
|
343
|
+
/** Deck entries to hydrate */
|
|
344
|
+
entries: HydrateDeckEntryInput[];
|
|
345
|
+
/** Whether to use cache (defaults to client config) */
|
|
346
|
+
cache?: boolean;
|
|
347
|
+
}
|
|
348
|
+
declare class DecksResource extends BaseResource {
|
|
349
|
+
constructor(connection: Connection, config: Configuration);
|
|
350
|
+
/**
|
|
351
|
+
* Fetch a hosted deck by CardDB UUID.
|
|
352
|
+
*/
|
|
353
|
+
fetch(id: string, options?: FetchDeckOptions): Promise<Deck | null>;
|
|
354
|
+
/**
|
|
355
|
+
* Fetch a hosted deck by external reference for the current API application.
|
|
356
|
+
*/
|
|
357
|
+
fetchByExternalRef(externalRef: string, options?: FetchDeckByExternalRefOptions): Promise<Deck | null>;
|
|
358
|
+
/**
|
|
359
|
+
* List decks owned by the current account or API application.
|
|
360
|
+
*/
|
|
361
|
+
listMine(options?: ListDecksOptions): Promise<Collection<Deck>>;
|
|
362
|
+
/**
|
|
363
|
+
* Create a hosted deck.
|
|
364
|
+
*/
|
|
365
|
+
create(input: DeckCreateInput): Promise<Deck>;
|
|
366
|
+
/**
|
|
367
|
+
* Update a hosted deck.
|
|
368
|
+
*/
|
|
369
|
+
update(id: string, input: DeckUpdateInput): Promise<Deck>;
|
|
370
|
+
/**
|
|
371
|
+
* Delete a hosted deck.
|
|
372
|
+
*/
|
|
373
|
+
delete(id: string): Promise<boolean>;
|
|
374
|
+
/**
|
|
375
|
+
* Hydrate third-party-owned deck entries without storing them in CardDB.
|
|
376
|
+
*/
|
|
377
|
+
hydrateEntries(options: HydrateDeckEntriesOptions): Promise<HydratedDeckEntry[]>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Records resource for CardDB API
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
interface SearchRecordsOptions {
|
|
385
|
+
/** Publisher slug (uses default if configured) */
|
|
386
|
+
publisherSlug?: string;
|
|
387
|
+
/** Game key (uses default if configured) */
|
|
388
|
+
gameKey?: string;
|
|
389
|
+
/** Dataset key (required) */
|
|
390
|
+
datasetKey: string;
|
|
391
|
+
/**
|
|
392
|
+
* Filter conditions - can be an object or a builder function
|
|
393
|
+
*
|
|
394
|
+
* @example Object literal
|
|
395
|
+
* filter: { hp: { gte: 100 }, type: 'Pokemon' }
|
|
396
|
+
*
|
|
397
|
+
* @example Builder function
|
|
398
|
+
* filter: f => f
|
|
399
|
+
* .where('hp', gte(100))
|
|
400
|
+
* .where('type', 'Pokemon')
|
|
401
|
+
* .any(or => or
|
|
402
|
+
* .where('rarity', 'rare')
|
|
403
|
+
* .where('rarity', 'mythic')
|
|
404
|
+
* )
|
|
405
|
+
*/
|
|
406
|
+
filter?: FilterInput;
|
|
407
|
+
/** Full-text search across searchable fields */
|
|
408
|
+
search?: string;
|
|
409
|
+
/**
|
|
410
|
+
* Order by field with direction
|
|
411
|
+
* @example 'name:asc', 'hp:desc', 'createdAt:desc'
|
|
412
|
+
*/
|
|
413
|
+
orderBy?: string;
|
|
414
|
+
/**
|
|
415
|
+
* Link fields to resolve (returns linked record data)
|
|
416
|
+
* @example ['set_id', 'artist_id']
|
|
417
|
+
*/
|
|
418
|
+
resolveLinks?: string[];
|
|
419
|
+
/** Maximum number of results per page (default: 20, max: 100) */
|
|
420
|
+
first?: number;
|
|
421
|
+
/** Cursor for pagination */
|
|
422
|
+
after?: string;
|
|
423
|
+
/** Whether to validate filter against schema (default: true) */
|
|
424
|
+
validateSchema?: boolean;
|
|
425
|
+
/** Whether to use cache (defaults to client config) */
|
|
426
|
+
cache?: boolean;
|
|
427
|
+
}
|
|
428
|
+
interface GetRecordOptions {
|
|
429
|
+
/** Whether to use cache (defaults to client config) */
|
|
430
|
+
cache?: boolean;
|
|
431
|
+
}
|
|
432
|
+
interface GetRecordByIdentifierOptions {
|
|
433
|
+
/** Publisher slug (uses default if configured) */
|
|
434
|
+
publisherSlug?: string;
|
|
435
|
+
/** Game key (uses default if configured) */
|
|
436
|
+
gameKey?: string;
|
|
437
|
+
/** Dataset key (required) */
|
|
438
|
+
datasetKey: string;
|
|
439
|
+
/** The identifier value to look up */
|
|
440
|
+
identifier: string;
|
|
441
|
+
/** Whether to use cache (defaults to client config) */
|
|
442
|
+
cache?: boolean;
|
|
443
|
+
}
|
|
444
|
+
interface GetRecordsByIdentifierOptions {
|
|
445
|
+
/** Publisher slug (uses default if configured) */
|
|
446
|
+
publisherSlug?: string;
|
|
447
|
+
/** Game key (uses default if configured) */
|
|
448
|
+
gameKey?: string;
|
|
449
|
+
/** Dataset key (required) */
|
|
450
|
+
datasetKey: string;
|
|
451
|
+
/** Identifier values to look up */
|
|
452
|
+
identifiers: string[];
|
|
453
|
+
/** Whether to use cache (defaults to client config) */
|
|
454
|
+
cache?: boolean;
|
|
455
|
+
}
|
|
456
|
+
declare class RecordsResource extends BaseResource {
|
|
457
|
+
constructor(connection: Connection, config: Configuration);
|
|
458
|
+
/**
|
|
459
|
+
* Search for records in a dataset with filtering, search, and pagination
|
|
460
|
+
*
|
|
461
|
+
* @example Basic search
|
|
462
|
+
* const records = await client.records.search({
|
|
463
|
+
* publisherSlug: 'pokemon',
|
|
464
|
+
* gameKey: 'tcg',
|
|
465
|
+
* datasetKey: 'cards',
|
|
466
|
+
* })
|
|
467
|
+
*
|
|
468
|
+
* @example With defaults configured
|
|
469
|
+
* // If client has defaultPublisher: 'pokemon', defaultGame: 'tcg'
|
|
470
|
+
* const records = await client.records.search({ datasetKey: 'cards' })
|
|
471
|
+
*
|
|
472
|
+
* @example With filtering (object literal)
|
|
473
|
+
* const records = await client.records.search({
|
|
474
|
+
* datasetKey: 'cards',
|
|
475
|
+
* filter: {
|
|
476
|
+
* hp: { gte: 100 },
|
|
477
|
+
* types: { contains: 'Fire' }
|
|
478
|
+
* }
|
|
479
|
+
* })
|
|
480
|
+
*
|
|
481
|
+
* @example With filtering (builder function)
|
|
482
|
+
* const records = await client.records.search({
|
|
483
|
+
* datasetKey: 'cards',
|
|
484
|
+
* filter: f => f
|
|
485
|
+
* .where('hp', gte(100))
|
|
486
|
+
* .where('types', contains('Fire'))
|
|
487
|
+
* .any(or => or
|
|
488
|
+
* .where('rarity', 'Rare')
|
|
489
|
+
* .where('rarity', 'Rare Holo')
|
|
490
|
+
* )
|
|
491
|
+
* })
|
|
492
|
+
*
|
|
493
|
+
* @example With link resolution
|
|
494
|
+
* const records = await client.records.search({
|
|
495
|
+
* datasetKey: 'cards',
|
|
496
|
+
* resolveLinks: ['set_id'],
|
|
497
|
+
* filter: f => f.whereLink('set_id', { code: 'BASE' })
|
|
498
|
+
* })
|
|
499
|
+
*
|
|
500
|
+
* @example Iterate through all results
|
|
501
|
+
* const records = await client.records.search({ datasetKey: 'cards' })
|
|
502
|
+
* for await (const record of records) {
|
|
503
|
+
* console.log(record.data.name)
|
|
504
|
+
* }
|
|
505
|
+
*/
|
|
506
|
+
search(options: SearchRecordsOptions): Promise<Collection<DatasetRecord>>;
|
|
507
|
+
/**
|
|
508
|
+
* Get a single record by ID
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* const record = await client.records.get('550e8400-e29b-41d4-a716-446655440000')
|
|
512
|
+
*/
|
|
513
|
+
get(id: string, options?: GetRecordOptions): Promise<DatasetRecord | null>;
|
|
514
|
+
/**
|
|
515
|
+
* Get a record by its identifier field value
|
|
516
|
+
*
|
|
517
|
+
* The identifier field is defined in the dataset schema (the field marked as isIdentifier)
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* const record = await client.records.getByIdentifier({
|
|
521
|
+
* publisherSlug: 'pokemon',
|
|
522
|
+
* gameKey: 'tcg',
|
|
523
|
+
* datasetKey: 'cards',
|
|
524
|
+
* identifier: 'base1-4'
|
|
525
|
+
* })
|
|
526
|
+
*
|
|
527
|
+
* @example With defaults configured
|
|
528
|
+
* const record = await client.records.getByIdentifier({
|
|
529
|
+
* datasetKey: 'cards',
|
|
530
|
+
* identifier: 'base1-4'
|
|
531
|
+
* })
|
|
532
|
+
*/
|
|
533
|
+
getByIdentifier(options: GetRecordByIdentifierOptions): Promise<DatasetRecord | null>;
|
|
534
|
+
/**
|
|
535
|
+
* Get multiple records by their identifier field values
|
|
536
|
+
*
|
|
537
|
+
* Missing identifiers are omitted from the result.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* const records = await client.records.getManyByIdentifier({
|
|
541
|
+
* publisherSlug: 'pokemon',
|
|
542
|
+
* gameKey: 'tcg',
|
|
543
|
+
* datasetKey: 'cards',
|
|
544
|
+
* identifiers: ['base1-4', 'base1-5']
|
|
545
|
+
* })
|
|
546
|
+
*
|
|
547
|
+
* @example With defaults configured
|
|
548
|
+
* const records = await client.records.getManyByIdentifier({
|
|
549
|
+
* datasetKey: 'cards',
|
|
550
|
+
* identifiers: ['base1-4', 'base1-5']
|
|
551
|
+
* })
|
|
552
|
+
*/
|
|
553
|
+
getManyByIdentifier(options: GetRecordsByIdentifierOptions): Promise<DatasetRecord[]>;
|
|
554
|
+
/**
|
|
555
|
+
* Get multiple records by ID
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* const records = await client.records.getMany(['id1', 'id2', 'id3'])
|
|
559
|
+
*/
|
|
560
|
+
getMany(ids: string[], options?: GetRecordOptions): Promise<DatasetRecord[]>;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Rules resource for CardDB API
|
|
565
|
+
*/
|
|
566
|
+
|
|
567
|
+
interface ListRuleDatasetsOptions {
|
|
568
|
+
/** Publisher slug (uses default if configured) */
|
|
569
|
+
publisherSlug?: string;
|
|
570
|
+
/** Game key (uses default if configured) */
|
|
571
|
+
gameKey?: string;
|
|
572
|
+
/** Search term to filter rule datasets by name */
|
|
573
|
+
search?: string;
|
|
574
|
+
/** Maximum number of results per page (default: 20, max: 100) */
|
|
575
|
+
first?: number;
|
|
576
|
+
/** Cursor for pagination */
|
|
577
|
+
after?: string;
|
|
578
|
+
/** Whether to use cache (defaults to client config) */
|
|
579
|
+
cache?: boolean;
|
|
580
|
+
}
|
|
581
|
+
interface ListRulesOptions {
|
|
582
|
+
/** Publisher slug (uses default if configured) */
|
|
583
|
+
publisherSlug?: string;
|
|
584
|
+
/** Game key (uses default if configured) */
|
|
585
|
+
gameKey?: string;
|
|
586
|
+
/** Rules dataset key (defaults to "rules") */
|
|
587
|
+
datasetKey?: string;
|
|
588
|
+
/** Filter conditions */
|
|
589
|
+
filter?: FilterInput;
|
|
590
|
+
/** Full-text search across searchable fields */
|
|
591
|
+
search?: string;
|
|
592
|
+
/** Order by field with direction, e.g. "name:asc" */
|
|
593
|
+
orderBy?: string;
|
|
594
|
+
/** Link fields to resolve */
|
|
595
|
+
resolveLinks?: string[];
|
|
596
|
+
/** Maximum number of results per page (default: 20, max: 100) */
|
|
597
|
+
first?: number;
|
|
598
|
+
/** Cursor for pagination */
|
|
599
|
+
after?: string;
|
|
600
|
+
/** Whether to validate filter against schema (default: true) */
|
|
601
|
+
validateSchema?: boolean;
|
|
602
|
+
/** Whether to use cache (defaults to client config) */
|
|
603
|
+
cache?: boolean;
|
|
604
|
+
}
|
|
605
|
+
interface ListFormatsOptions extends Omit<ListRulesOptions, 'datasetKey'> {
|
|
606
|
+
/** Formats dataset key (defaults to "formats") */
|
|
607
|
+
datasetKey?: string;
|
|
608
|
+
}
|
|
609
|
+
declare class RulesResource extends BaseResource {
|
|
610
|
+
constructor(connection: Connection, config: Configuration);
|
|
611
|
+
/**
|
|
612
|
+
* List rule-related datasets for a game.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* const datasets = await client.rules.datasets({ publisherSlug: 'wotc', gameKey: 'magic' })
|
|
616
|
+
*/
|
|
617
|
+
datasets(options?: ListRuleDatasetsOptions): Promise<Collection<Dataset>>;
|
|
618
|
+
/**
|
|
619
|
+
* List rules from the game's rules dataset.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* const rules = await client.rules.list({ first: 100 })
|
|
623
|
+
*/
|
|
624
|
+
list(options?: ListRulesOptions): Promise<Collection<DatasetRecord>>;
|
|
625
|
+
/**
|
|
626
|
+
* List deck/game formats from the game's formats dataset.
|
|
627
|
+
*
|
|
628
|
+
* @example
|
|
629
|
+
* const formats = await client.rules.formats({ first: 100 })
|
|
630
|
+
* const names = formats.items.map(format => format.data.name)
|
|
631
|
+
*/
|
|
632
|
+
formats(options?: ListFormatsOptions): Promise<Collection<DatasetRecord>>;
|
|
633
|
+
private searchRuleRecords;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* CardDB API Client
|
|
638
|
+
*
|
|
639
|
+
* @example Basic usage
|
|
640
|
+
* ```typescript
|
|
641
|
+
* import { CardDBClient } from '@carddb/node'
|
|
642
|
+
*
|
|
643
|
+
* const client = new CardDBClient({
|
|
644
|
+
* apiKey: 'carddb_xxx...'
|
|
645
|
+
* })
|
|
646
|
+
*
|
|
647
|
+
* // Search for publishers
|
|
648
|
+
* const publishers = await client.publishers.search()
|
|
649
|
+
*
|
|
650
|
+
* // Get records with filtering
|
|
651
|
+
* const cards = await client.records.search({
|
|
652
|
+
* publisherSlug: 'pokemon',
|
|
653
|
+
* gameKey: 'tcg',
|
|
654
|
+
* datasetKey: 'cards',
|
|
655
|
+
* filter: { hp: { gte: 100 } }
|
|
656
|
+
* })
|
|
657
|
+
* ```
|
|
658
|
+
*
|
|
659
|
+
* @example With defaults configured
|
|
660
|
+
* ```typescript
|
|
661
|
+
* const client = new CardDBClient({
|
|
662
|
+
* apiKey: 'carddb_xxx...',
|
|
663
|
+
* defaultPublisher: 'pokemon',
|
|
664
|
+
* defaultGame: 'tcg'
|
|
665
|
+
* })
|
|
666
|
+
*
|
|
667
|
+
* // Now you can omit publisherSlug and gameKey
|
|
668
|
+
* const cards = await client.records.search({
|
|
669
|
+
* datasetKey: 'cards'
|
|
670
|
+
* })
|
|
671
|
+
* ```
|
|
672
|
+
*
|
|
673
|
+
* @example With caching
|
|
674
|
+
* ```typescript
|
|
675
|
+
* import { CardDBClient, MemoryCache } from '@carddb/node'
|
|
676
|
+
*
|
|
677
|
+
* const client = new CardDBClient({
|
|
678
|
+
* apiKey: 'carddb_xxx...',
|
|
679
|
+
* cache: new MemoryCache(),
|
|
680
|
+
* cacheTtl: 300 // 5 minutes
|
|
681
|
+
* })
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
declare class CardDBClient {
|
|
685
|
+
private config;
|
|
686
|
+
private connection;
|
|
687
|
+
/** Publishers resource for searching and fetching publishers */
|
|
688
|
+
readonly publishers: PublishersResource;
|
|
689
|
+
/** Games resource for searching and fetching games */
|
|
690
|
+
readonly games: GamesResource;
|
|
691
|
+
/** Datasets resource for searching and fetching datasets */
|
|
692
|
+
readonly datasets: DatasetsResource;
|
|
693
|
+
/** Records resource for searching and fetching records */
|
|
694
|
+
readonly records: RecordsResource;
|
|
695
|
+
/** Decks resource for hosted decks and external deck hydration */
|
|
696
|
+
readonly decks: DecksResource;
|
|
697
|
+
/** Rules resource for game rules and deck formats */
|
|
698
|
+
readonly rules: RulesResource;
|
|
699
|
+
/**
|
|
700
|
+
* Create a new CardDB client
|
|
701
|
+
*
|
|
702
|
+
* @param config - Client configuration options
|
|
703
|
+
*/
|
|
704
|
+
constructor(config?: CardDBConfig);
|
|
705
|
+
/**
|
|
706
|
+
* Get information about the current API key
|
|
707
|
+
*
|
|
708
|
+
* Returns null if no API key is configured or the key is invalid.
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* const info = await client.me()
|
|
712
|
+
* if (info) {
|
|
713
|
+
* console.log(`Logged in as: ${info.account.displayName}`)
|
|
714
|
+
* console.log(`Application: ${info.application.name}`)
|
|
715
|
+
* }
|
|
716
|
+
*/
|
|
717
|
+
me(): Promise<APIKeyInfo | null>;
|
|
718
|
+
/**
|
|
719
|
+
* Get rate limit information from the last request
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* await client.publishers.search()
|
|
723
|
+
* const rateLimit = client.getRateLimitInfo()
|
|
724
|
+
* console.log(`Remaining: ${rateLimit?.remaining}/${rateLimit?.limit}`)
|
|
725
|
+
*/
|
|
726
|
+
getRateLimitInfo(): _carddb_core.RateLimitInfo | null;
|
|
727
|
+
/**
|
|
728
|
+
* Create a new client with configuration overrides
|
|
729
|
+
*
|
|
730
|
+
* Useful for creating scoped clients with different defaults.
|
|
731
|
+
*
|
|
732
|
+
* @example
|
|
733
|
+
* const pokemonClient = client.withConfig({
|
|
734
|
+
* defaultPublisher: 'pokemon',
|
|
735
|
+
* defaultGame: 'tcg'
|
|
736
|
+
* })
|
|
737
|
+
*
|
|
738
|
+
* // Now all queries use these defaults
|
|
739
|
+
* const cards = await pokemonClient.records.search({ datasetKey: 'cards' })
|
|
740
|
+
*/
|
|
741
|
+
withConfig(overrides: Partial<CardDBConfig>): CardDBClient;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* User-Agent string generation for analytics tracking
|
|
746
|
+
*
|
|
747
|
+
* Format: CardDB-SDK/js/{version} ({runtime}/{runtime_version})
|
|
748
|
+
* Examples:
|
|
749
|
+
* - CardDB-SDK/js/0.1.0 (node/20.10.0)
|
|
750
|
+
* - CardDB-SDK/js/0.1.0 (bun/1.0.0)
|
|
751
|
+
* - CardDB-SDK/js/0.1.0 (chrome/120.0.0.0)
|
|
752
|
+
* - CardDB-SDK/js/0.1.0 (firefox/121.0)
|
|
753
|
+
*/
|
|
754
|
+
/**
|
|
755
|
+
* Generate the User-Agent string for CardDB SDK
|
|
756
|
+
*/
|
|
757
|
+
declare function getUserAgent(): string;
|
|
758
|
+
/**
|
|
759
|
+
* Get the SDK version
|
|
760
|
+
*/
|
|
761
|
+
declare function getSDKVersion(): string;
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Cache utilities for CardDB client
|
|
765
|
+
*/
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Generate a cache key from components
|
|
769
|
+
*/
|
|
770
|
+
declare function cacheKey(resource: string, method: string, params: Record<string, unknown>): string;
|
|
771
|
+
/**
|
|
772
|
+
* Read from cache (handles both sync and async caches)
|
|
773
|
+
*/
|
|
774
|
+
declare function readCache<T>(cache: Cache, key: string): Promise<T | null>;
|
|
775
|
+
/**
|
|
776
|
+
* Write to cache (handles both sync and async caches)
|
|
777
|
+
*/
|
|
778
|
+
declare function writeCache<T>(cache: Cache, key: string, value: T, ttl: number): Promise<void>;
|
|
779
|
+
|
|
780
|
+
export { BaseResource, CardDBClient, Configuration, Connection, DEFAULT_CACHE_TTL, DEFAULT_ENDPOINT, DEFAULT_MAX_NETWORK_RETRIES, DEFAULT_MAX_RETRIES, DEFAULT_OPEN_TIMEOUT, DEFAULT_RETRY_BASE_DELAY, DEFAULT_RETRY_MAX_DELAY, DEFAULT_TIMEOUT, DatasetsResource, DecksResource, type FetchDeckByExternalRefOptions, type FetchDeckOptions, GamesResource, type GetDatasetOptions, type GetGameOptions, type GetPublisherOptions, type GetRecordByIdentifierOptions, type GetRecordOptions, type GetRecordsByIdentifierOptions, type GraphQLResponse, type HydrateDeckEntriesOptions, type ListDecksOptions, type ListFormatsOptions, type ListRuleDatasetsOptions, type ListRulesOptions, PublishersResource, RecordsResource, RulesResource, type SearchDatasetsOptions, type SearchGamesOptions, type SearchPublishersOptions, type SearchRecordsOptions, cacheKey, getRateLimitInfo, getSDKVersion, getUserAgent, readCache, writeCache };
|