itchlib 0.0.0-stage → 1.0.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.
@@ -0,0 +1,420 @@
1
+ export type ItchFeedName = "new" | "featured" | "sales";
2
+ export type ItchErrorCode =
3
+ | "ITCH_ERROR"
4
+ | "ITCH_HTTP_ERROR"
5
+ | "ITCH_INVALID_RESPONSE"
6
+ | "ITCH_INVALID_URL"
7
+ | "ITCH_ACCESS_ERROR"
8
+ | "ITCH_AUTH_REQUIRED"
9
+ | "ITCH_API_ERROR"
10
+ | "ITCH_ABORTED"
11
+ | "ITCH_NETWORK_ERROR";
12
+
13
+ export interface ItchLink {
14
+ url: string;
15
+ text: string;
16
+ title?: string;
17
+ }
18
+
19
+ export interface ItchAuthor {
20
+ url: string | null;
21
+ text: string;
22
+ }
23
+
24
+ export interface ItchUpload {
25
+ id: string | null;
26
+ name: string;
27
+ filename: string;
28
+ size: number;
29
+ version: string | null;
30
+ /** itch.io's own upload labels; itchlib does not infer platform categories. */
31
+ platforms: string[];
32
+ }
33
+
34
+ export interface ItchComment {
35
+ id: string | null;
36
+ userId: number | null;
37
+ isReply: boolean;
38
+ author: string | null;
39
+ authorUrl: string | null;
40
+ createdAt: string | null;
41
+ text: string;
42
+ html: string | null;
43
+ url: string | null;
44
+ }
45
+
46
+ export interface ItchDetail {
47
+ label: string;
48
+ text: string;
49
+ links: ItchLink[];
50
+ }
51
+
52
+ export interface ItchGame {
53
+ id: number | null;
54
+ slug: string | null;
55
+ url: string;
56
+ title: string;
57
+ author: string | null;
58
+ authorUrl: string | null;
59
+ authors: ItchAuthor[];
60
+ description: string;
61
+ descriptionHtml: string | null;
62
+ cover: string | null;
63
+ images: string[];
64
+ screenshots: string[];
65
+ videos: string[];
66
+ embeds: string[];
67
+ links: ItchLink[];
68
+ price: string | null;
69
+ purchase: { url: string | null; label: string } | null;
70
+ details: ItchDetail[];
71
+ status: string | null;
72
+ pagePlatforms: ItchLink[];
73
+ genres: ItchLink[];
74
+ tags: ItchLink[];
75
+ madeWith: ItchLink[];
76
+ languages: ItchLink[];
77
+ inputs: ItchLink[];
78
+ accessibility: ItchLink[];
79
+ developmentLogs: ItchLink[];
80
+ comments: ItchComment[];
81
+ uploads: ItchUpload[];
82
+ }
83
+
84
+ export interface ItchGameCard {
85
+ id: number | null;
86
+ title: string;
87
+ url: string;
88
+ cover: string | null;
89
+ description: string | null;
90
+ author: string | null;
91
+ genre: string | null;
92
+ platforms: string | null;
93
+ }
94
+
95
+ export interface ItchProfile {
96
+ id: number | null;
97
+ username: string | null;
98
+ displayName: string;
99
+ url: string;
100
+ avatar: string | null;
101
+ bio: string;
102
+ bioHtml: string | null;
103
+ links: ItchLink[];
104
+ games: ItchGameCard[];
105
+ }
106
+
107
+ export interface ItchBrowseOption {
108
+ label: string;
109
+ url: string | null;
110
+ value: string | null;
111
+ selected: boolean;
112
+ }
113
+
114
+ export interface ItchBrowseFilterGroup {
115
+ id: string | null;
116
+ label: string;
117
+ options: ItchBrowseOption[];
118
+ }
119
+
120
+ export interface ItchCommunityCategory {
121
+ title: string;
122
+ url: string;
123
+ description: string | null;
124
+ topicCount: number | null;
125
+ latestTopic: { title: string; url: string; author: string | null } | null;
126
+ }
127
+
128
+ export interface ItchSale {
129
+ id: string | null;
130
+ type: string | null;
131
+ title: string;
132
+ url: string;
133
+ author: ItchAuthor | null;
134
+ itemCount: number | null;
135
+ endsAt: string | null;
136
+ /** itch.io's own labels, returned without platform classification. */
137
+ platforms: string[];
138
+ covers: string[];
139
+ }
140
+
141
+ export interface ItchFilterPicker {
142
+ id: string | null;
143
+ selected: string | null;
144
+ options: ItchBrowseOption[];
145
+ }
146
+
147
+ export interface ItchSearchFacet {
148
+ label: string;
149
+ values: Array<{ label: string; count: number | null; url: string | null }>;
150
+ }
151
+
152
+ export interface ItchBrowsePage {
153
+ url: string;
154
+ title: string;
155
+ query: string | null;
156
+ resultCount: number | null;
157
+ games: ItchGameCard[];
158
+ jams: Array<{ title: string; url: string; joinedCount: number | null }>;
159
+ categories: ItchCommunityCategory[];
160
+ tags: Array<{
161
+ title: string;
162
+ url: string;
163
+ cover: string | null;
164
+ count: string | null;
165
+ description: string | null;
166
+ }>;
167
+ bundles: Array<ItchSale | ItchLink>;
168
+ sales: ItchSale[];
169
+ devlogs: Array<{ title: string; url: string }>;
170
+ blogPosts: Array<{ title: string; url: string; summary: string | null }>;
171
+ topics: Array<{ title: string; url: string }>;
172
+ filters: ItchBrowseFilterGroup[];
173
+ filterPickers: ItchFilterPicker[];
174
+ facets: ItchSearchFacet[];
175
+ sortOptions: Array<ItchLink & { selected: boolean }>;
176
+ activeSort: string | null;
177
+ relatedTags: ItchLink[];
178
+ nextPageUrl: string | null;
179
+ }
180
+
181
+ export interface ItchSuggestion {
182
+ id?: number | string;
183
+ url?: string;
184
+ name?: string;
185
+ title?: string;
186
+ cover?: string;
187
+ [key: string]: unknown;
188
+ }
189
+
190
+ export interface ItchSuggestions {
191
+ query: string;
192
+ games: ItchSuggestion[];
193
+ tags: ItchSuggestion[];
194
+ jams: ItchSuggestion[];
195
+ bundles: ItchSuggestion[];
196
+ [key: string]: unknown;
197
+ }
198
+
199
+ export interface ItchFeedItem {
200
+ title: string;
201
+ url: string;
202
+ description: string;
203
+ publishedAt: string;
204
+ author: string | null;
205
+ }
206
+
207
+ export interface ItchFeed {
208
+ feed: ItchFeedName | string;
209
+ url: string;
210
+ items: ItchFeedItem[];
211
+ }
212
+
213
+ export type FetchLike = (input: URL | string, init?: RequestInit) => Promise<Response>;
214
+
215
+ export interface ItchClientOptions {
216
+ fetch?: FetchLike;
217
+ timeout?: number;
218
+ /** itch.io API key; retained as a convenient alias for accessToken. */
219
+ apiKey?: string;
220
+ /** API key or OAuth/JWT bearer token. */
221
+ accessToken?: string;
222
+ /** Alias for accessToken. */
223
+ token?: string;
224
+ headers?: Record<string, string>;
225
+ userAgent?: string;
226
+ maxRetryDelay?: number;
227
+ }
228
+
229
+ export interface RequestOptions {
230
+ signal?: AbortSignal;
231
+ }
232
+
233
+ export interface BrowseOptions extends RequestOptions {
234
+ query?: string;
235
+ page?: number;
236
+ params?: Record<string, string | number | boolean | Array<string | number | boolean> | null | undefined>;
237
+ }
238
+
239
+ export interface SearchOptions extends RequestOptions {
240
+ page?: number;
241
+ [parameter: string]: unknown;
242
+ }
243
+
244
+ export interface ApiRequestOptions extends RequestOptions {
245
+ query?: Record<string, string | number | boolean | Array<string | number> | null | undefined>;
246
+ method?: string;
247
+ body?: Record<string, string | number | boolean>;
248
+ headers?: Record<string, string>;
249
+ }
250
+
251
+ export class ItchError extends Error {
252
+ constructor(
253
+ message: string,
254
+ options?: { status?: number; url?: string; code?: ItchErrorCode; cause?: unknown },
255
+ );
256
+ code: ItchErrorCode;
257
+ status?: number;
258
+ url?: string;
259
+ }
260
+
261
+ export class ItchClient {
262
+ constructor(options?: ItchClientOptions);
263
+ request(url: URL | string, options?: RequestInit & { timeout?: number }): Promise<Response>;
264
+ getGame(url: string, options?: RequestOptions): Promise<ItchGame>;
265
+ getUploads(url: string, options?: RequestOptions): Promise<ItchUpload[]>;
266
+ getDownloadUploads(url: string, options?: RequestOptions): Promise<ItchUpload[]>;
267
+ getDownloadUrl(url: string, uploadId: string | number, options?: RequestOptions): Promise<string>;
268
+ getComments(url: string, options?: RequestOptions): Promise<ItchComment[]>;
269
+ getProfile(usernameOrUrl: string, options?: RequestOptions): Promise<ItchProfile>;
270
+ getBrowsePage(sectionOrUrl?: string, options?: BrowseOptions): Promise<ItchBrowsePage>;
271
+ searchGames(query: string, options?: SearchOptions): Promise<ItchBrowsePage>;
272
+ getSuggestions(query: string, options?: RequestOptions): Promise<ItchSuggestions>;
273
+ getFeed(feed?: ItchFeedName | string, options?: RequestOptions): Promise<ItchFeed>;
274
+ apiRequest<T extends Record<string, unknown> = Record<string, unknown>>(
275
+ path: string,
276
+ options?: ApiRequestOptions,
277
+ ): Promise<T>;
278
+ getApiProfile(options?: RequestOptions): Promise<Record<string, unknown>>;
279
+ getApiCredentials(options?: RequestOptions): Promise<Record<string, unknown>>;
280
+ getDeveloperGames(options?: RequestOptions): Promise<Record<string, unknown>>;
281
+ getApiUploads(gameId: string | number, options?: RequestOptions): Promise<Record<string, unknown>>;
282
+ getApiDownloadUrl(uploadId: string | number, options?: RequestOptions): Promise<Record<string, unknown>>;
283
+ getGameDownloadKey(
284
+ gameId: string | number,
285
+ options:
286
+ | ({ downloadKey: string } & RequestOptions)
287
+ | ({ userId: string | number } & RequestOptions)
288
+ | ({ email: string } & RequestOptions),
289
+ ): Promise<Record<string, unknown>>;
290
+ getGamePurchases(
291
+ gameId: string | number,
292
+ options: ({ userId: string | number } & RequestOptions) | ({ email: string } & RequestOptions),
293
+ ): Promise<Record<string, unknown>>;
294
+ getClaimedRewards(
295
+ gameId: string | number,
296
+ options?: { page?: number } & RequestOptions,
297
+ ): Promise<Record<string, unknown>>;
298
+ getAllClaimedRewards(gameId: string | number, options?: RequestOptions): Promise<unknown[]>;
299
+ checkGameOwnership(gameId: string | number, options?: RequestOptions): Promise<Record<string, unknown>>;
300
+ getCollections(options?: { gameId?: string | number } & RequestOptions): Promise<Record<string, unknown>>;
301
+ getCollection(collectionId: string | number, options?: RequestOptions): Promise<Record<string, unknown>>;
302
+ getCollectionGames(
303
+ collectionId: string | number,
304
+ options?: { page?: number; perPage?: number } & RequestOptions,
305
+ ): Promise<Record<string, unknown>>;
306
+ getAllCollectionGames(
307
+ collectionId: string | number,
308
+ options?: { perPage?: number } & RequestOptions,
309
+ ): Promise<unknown[]>;
310
+ createCollection(
311
+ collection: {
312
+ title?: string;
313
+ private?: boolean;
314
+ description?: string;
315
+ layout?: "grid" | "list";
316
+ game_id?: string | number;
317
+ blurb?: string;
318
+ },
319
+ options?: RequestOptions,
320
+ ): Promise<Record<string, unknown>>;
321
+ updateCollection(
322
+ collectionId: string | number,
323
+ collection: {
324
+ title?: string;
325
+ private?: boolean;
326
+ description?: string;
327
+ layout?: "grid" | "list";
328
+ on_profile?: boolean;
329
+ },
330
+ options?: RequestOptions,
331
+ ): Promise<Record<string, unknown>>;
332
+ deleteCollection(collectionId: string | number, options?: RequestOptions): Promise<Record<string, unknown>>;
333
+ addGameToCollection(
334
+ collectionId: string | number,
335
+ game: { gameId: string | number; blurb?: string },
336
+ options?: RequestOptions,
337
+ ): Promise<Record<string, unknown>>;
338
+ removeGameFromCollection(
339
+ collectionId: string | number,
340
+ gameId: string | number,
341
+ options?: RequestOptions,
342
+ ): Promise<Record<string, unknown>>;
343
+ updateCollectionGame(
344
+ collectionId: string | number,
345
+ gameId: string | number,
346
+ game: { blurb?: string },
347
+ options?: RequestOptions,
348
+ ): Promise<Record<string, unknown>>;
349
+ orderCollection(
350
+ collectionId: string | number,
351
+ order: { gameIds: Array<string | number>; removeGameIds?: Array<string | number> },
352
+ options?: RequestOptions,
353
+ ): Promise<Record<string, unknown>>;
354
+ getLatestVersion(
355
+ options:
356
+ | ({ channelName: string; target: string; gameId?: never } & RequestOptions)
357
+ | ({ channelName: string; gameId: string | number; target?: never } & RequestOptions),
358
+ ): Promise<Record<string, unknown>>;
359
+ getOwnedKeys(options?: {
360
+ page?: number;
361
+ perPage?: number;
362
+ gameIds?: Array<string | number>;
363
+ signal?: AbortSignal;
364
+ }): Promise<Record<string, unknown>>;
365
+ getAllOwnedKeys(options?: {
366
+ perPage?: number;
367
+ gameIds?: Array<string | number>;
368
+ signal?: AbortSignal;
369
+ }): Promise<unknown[]>;
370
+ }
371
+
372
+ export const ITCH_BROWSE_PAGES: Readonly<{
373
+ games: string;
374
+ store: string;
375
+ freeGames: string;
376
+ funGames: string;
377
+ demos: string;
378
+ onSale: string;
379
+ topRated: string;
380
+ topSellers: string;
381
+ newestGames: string;
382
+ newAndPopular: string;
383
+ tools: string;
384
+ assets: string;
385
+ soundtracks: string;
386
+ physicalGames: string;
387
+ comics: string;
388
+ books: string;
389
+ jams: string;
390
+ community: string;
391
+ devlogs: string;
392
+ tags: string;
393
+ bundles: string;
394
+ blog: string;
395
+ developers: string;
396
+ search: string;
397
+ }>;
398
+ export function createItchClient(options?: ItchClientOptions): ItchClient;
399
+ export function getGame(url: string, options?: ItchClientOptions): Promise<ItchGame>;
400
+ export function getUploads(url: string, options?: ItchClientOptions): Promise<ItchUpload[]>;
401
+ export function getDownloadUploads(url: string, options?: ItchClientOptions): Promise<ItchUpload[]>;
402
+ export function getDownloadUrl(
403
+ url: string,
404
+ uploadId: string | number,
405
+ options?: ItchClientOptions,
406
+ ): Promise<string>;
407
+ export function getComments(url: string, options?: ItchClientOptions): Promise<ItchComment[]>;
408
+ export function getProfile(usernameOrUrl: string, options?: ItchClientOptions): Promise<ItchProfile>;
409
+ export function searchGames(
410
+ query: string,
411
+ options?: SearchOptions,
412
+ clientOptions?: ItchClientOptions,
413
+ ): Promise<ItchBrowsePage>;
414
+ export function getSuggestions(query: string, options?: ItchClientOptions): Promise<ItchSuggestions>;
415
+ export function getBrowsePage(
416
+ sectionOrUrl?: string,
417
+ browseOptions?: BrowseOptions,
418
+ clientOptions?: ItchClientOptions,
419
+ ): Promise<ItchBrowsePage>;
420
+ export function getFeed(feed?: ItchFeedName | string, options?: ItchClientOptions): Promise<ItchFeed>;