@ddysiodev/js-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.
@@ -0,0 +1,465 @@
1
+ export const DEFAULT_BASE_URL: 'https://ddys.io/api/v1';
2
+
3
+ export type MovieTypeCode = 'movie' | 'series' | 'variety' | 'anime';
4
+ export type MovieSort = 'latest' | 'rating' | 'popular';
5
+ export type SearchType = 'movie' | 'share' | 'request';
6
+ export type ActivityType = 'share' | 'request';
7
+ export type CommentTargetType = 'movie' | 'share' | 'request';
8
+ export type FollowAction = 'follow' | 'unfollow';
9
+
10
+ export interface RetryOptions {
11
+ retries?: number;
12
+ delayMs?: number;
13
+ statuses?: number[];
14
+ }
15
+
16
+ export interface DdysFetchResponse {
17
+ ok: boolean;
18
+ status: number;
19
+ text(): Promise<string>;
20
+ }
21
+
22
+ export type FetchLike = (url: string | URL, init?: {
23
+ method?: string;
24
+ headers?: Record<string, string>;
25
+ body?: string;
26
+ signal?: AbortSignal;
27
+ }) => Promise<DdysFetchResponse>;
28
+
29
+ export interface DdysClientOptions {
30
+ baseUrl?: string;
31
+ apiKey?: string;
32
+ timeoutMs?: number;
33
+ fetch?: FetchLike;
34
+ headers?: Record<string, string>;
35
+ userAgent?: string;
36
+ retry?: RetryOptions | boolean;
37
+ }
38
+
39
+ export interface RequestOptions {
40
+ method?: 'GET' | 'POST' | 'DELETE' | string;
41
+ query?: Record<string, QueryValue>;
42
+ body?: unknown;
43
+ headers?: Record<string, string>;
44
+ auth?: boolean;
45
+ signal?: AbortSignal;
46
+ timeoutMs?: number;
47
+ retry?: RetryOptions | boolean;
48
+ }
49
+
50
+ export type QueryValue = string | number | boolean | null | undefined | Array<string | number | boolean | null | undefined>;
51
+
52
+ export interface ApiSuccess<T> {
53
+ success: true;
54
+ data: T;
55
+ meta?: PaginationMeta;
56
+ }
57
+
58
+ export interface ApiErrorResponse {
59
+ success: false;
60
+ message: string;
61
+ }
62
+
63
+ export interface PaginationParams {
64
+ page?: number;
65
+ per_page?: number;
66
+ perPage?: number;
67
+ }
68
+
69
+ export interface PaginationMeta {
70
+ total: number;
71
+ page: number;
72
+ per_page: number;
73
+ total_pages: number;
74
+ }
75
+
76
+ export interface PaginatedResult<T> {
77
+ data: T[];
78
+ meta: PaginationMeta;
79
+ }
80
+
81
+ export interface DictionaryItem {
82
+ id?: number;
83
+ name: string;
84
+ code: string;
85
+ }
86
+
87
+ export interface MovieListParams extends PaginationParams {
88
+ type?: MovieTypeCode;
89
+ genre?: string;
90
+ region?: string;
91
+ year?: number;
92
+ sort?: MovieSort;
93
+ }
94
+
95
+ export interface MovieListItem {
96
+ id: number;
97
+ title: string;
98
+ title_en?: string | null;
99
+ slug: string;
100
+ year: number;
101
+ poster?: string | null;
102
+ rating?: number | null;
103
+ douban_id?: string | null;
104
+ imdb_id?: string | null;
105
+ is_completed?: boolean;
106
+ type?: string | null;
107
+ type_code?: string | null;
108
+ region?: string | null;
109
+ region_code?: string | null;
110
+ genres?: DictionaryItem[];
111
+ created_at?: string;
112
+ updated_at?: string;
113
+ url: string;
114
+ }
115
+
116
+ export interface MovieDetail extends MovieListItem {
117
+ intro?: string | null;
118
+ director: string[];
119
+ actors: string[];
120
+ warning_tags: string[];
121
+ online_sources_count: number;
122
+ download_sources_count: number;
123
+ comments_count: number;
124
+ }
125
+
126
+ export interface OnlineResource {
127
+ id: number;
128
+ name: string;
129
+ url: string;
130
+ quality?: string | null;
131
+ format?: string | null;
132
+ }
133
+
134
+ export interface DownloadResource {
135
+ id: number;
136
+ name: string;
137
+ url: string;
138
+ quality?: string | null;
139
+ download_type?: string | null;
140
+ size?: string | null;
141
+ extract_code?: string | null;
142
+ }
143
+
144
+ export interface MovieSources {
145
+ online: OnlineResource[];
146
+ download: DownloadResource[];
147
+ }
148
+
149
+ export interface MovieRelated {
150
+ series: MovieListItem[];
151
+ related: MovieListItem[];
152
+ }
153
+
154
+ export interface Comment {
155
+ id: number;
156
+ content: string;
157
+ username: string;
158
+ avatar?: string | null;
159
+ created_at: string;
160
+ }
161
+
162
+ export interface SearchParams extends PaginationParams {
163
+ q: string;
164
+ type?: SearchType;
165
+ }
166
+
167
+ export interface SearchSuggestion {
168
+ id: number;
169
+ title: string;
170
+ title_en?: string | null;
171
+ slug: string;
172
+ year?: number | null;
173
+ poster?: string | null;
174
+ rating?: number | null;
175
+ url: string;
176
+ }
177
+
178
+ export interface HotMovie extends MovieListItem {
179
+ online_sources?: number;
180
+ download_sources?: number;
181
+ }
182
+
183
+ export interface LatestParams {
184
+ limit?: number;
185
+ }
186
+
187
+ export interface CalendarParams {
188
+ year?: number;
189
+ month?: number;
190
+ }
191
+
192
+ export interface CalendarMovie {
193
+ id?: number;
194
+ title: string;
195
+ title_en?: string | null;
196
+ slug?: string;
197
+ year?: number | null;
198
+ poster?: string | null;
199
+ rating?: number | null;
200
+ date?: string;
201
+ release_date?: string;
202
+ url?: string;
203
+ [key: string]: unknown;
204
+ }
205
+
206
+ export interface CalendarData {
207
+ year?: number;
208
+ month?: number;
209
+ days?: Record<string, CalendarMovie[]>;
210
+ movies?: CalendarMovie[];
211
+ [key: string]: unknown;
212
+ }
213
+
214
+ export interface Collection {
215
+ id: number;
216
+ title: string;
217
+ slug: string;
218
+ description?: string | null;
219
+ poster?: string | null;
220
+ movie_count?: number;
221
+ movies_count?: number;
222
+ created_at?: string;
223
+ updated_at?: string;
224
+ url?: string;
225
+ }
226
+
227
+ export interface CollectionDetail extends Collection {
228
+ movies: MovieListItem[];
229
+ meta?: PaginationMeta;
230
+ }
231
+
232
+ export interface Share {
233
+ id: number;
234
+ title: string;
235
+ resource_type?: string | null;
236
+ resource_types?: string[];
237
+ quality?: string | null;
238
+ note?: string | null;
239
+ username: string;
240
+ avatar?: string | null;
241
+ share_tag?: string | null;
242
+ created_at: string;
243
+ updated_at?: string;
244
+ url?: string;
245
+ }
246
+
247
+ export interface ShareResource {
248
+ id: number;
249
+ type: string;
250
+ url: string;
251
+ extract_code?: string | null;
252
+ }
253
+
254
+ export interface ShareDetail extends Share {
255
+ resources: ShareResource[];
256
+ comments_count: number;
257
+ }
258
+
259
+ export interface UserRequest {
260
+ id: number;
261
+ title: string;
262
+ year?: number | null;
263
+ type?: string | null;
264
+ description?: string | null;
265
+ status: string;
266
+ username: string;
267
+ avatar?: string | null;
268
+ created_at: string;
269
+ url: string;
270
+ }
271
+
272
+ export interface CreateRequestInput {
273
+ title: string;
274
+ year?: number | null;
275
+ type?: MovieTypeCode | '';
276
+ description?: string;
277
+ douban_id?: string;
278
+ }
279
+
280
+ export interface CreateRequestResult {
281
+ id: number;
282
+ title: string;
283
+ year?: number | null;
284
+ type?: string | null;
285
+ status: string;
286
+ reward?: number;
287
+ username: string;
288
+ created_at: string;
289
+ url: string;
290
+ }
291
+
292
+ export interface ActivityParams extends PaginationParams {
293
+ type?: ActivityType;
294
+ }
295
+
296
+ export interface Activity {
297
+ type: ActivityType;
298
+ id: number;
299
+ title: string;
300
+ username: string;
301
+ avatar?: string | null;
302
+ created_at: string;
303
+ url: string;
304
+ }
305
+
306
+ export interface PublicUserProfile {
307
+ id?: number;
308
+ username: string;
309
+ avatar?: string | null;
310
+ bio?: string | null;
311
+ share_tag?: string | null;
312
+ shares_count: number;
313
+ followers_count: number;
314
+ following_count: number;
315
+ joined_at: string;
316
+ url?: string;
317
+ }
318
+
319
+ export interface CurrentUserProfile extends PublicUserProfile {
320
+ id: number;
321
+ email: string;
322
+ }
323
+
324
+ export interface CreateCommentInput {
325
+ target_type: CommentTargetType;
326
+ target_id: number;
327
+ content: string;
328
+ }
329
+
330
+ export interface CommentCreateResult {
331
+ id: number;
332
+ content: string;
333
+ target_type: CommentTargetType;
334
+ target_id: number;
335
+ username: string;
336
+ created_at: string;
337
+ }
338
+
339
+ export interface CommentDeleteResult {
340
+ id: number;
341
+ deleted: boolean;
342
+ }
343
+
344
+ export interface ReportInvalidResourceInput {
345
+ resource_id: number;
346
+ movie_id: number;
347
+ }
348
+
349
+ export interface ReportResult {
350
+ reported: boolean;
351
+ }
352
+
353
+ export interface FollowInput {
354
+ username: string;
355
+ action: FollowAction;
356
+ }
357
+
358
+ export interface FollowResult {
359
+ action: 'followed' | 'unfollowed';
360
+ username: string;
361
+ }
362
+
363
+ export interface MovieEndpoints {
364
+ list(params?: MovieListParams): Promise<PaginatedResult<MovieListItem>>;
365
+ detail(slug: string): Promise<MovieDetail>;
366
+ sources(slug: string): Promise<MovieSources>;
367
+ related(slug: string): Promise<MovieRelated>;
368
+ comments(slug: string, params?: PaginationParams): Promise<PaginatedResult<Comment>>;
369
+ }
370
+
371
+ export interface DictionaryEndpoints {
372
+ types(): Promise<DictionaryItem[]>;
373
+ genres(): Promise<DictionaryItem[]>;
374
+ regions(): Promise<DictionaryItem[]>;
375
+ }
376
+
377
+ export interface CollectionEndpoints {
378
+ list(params?: PaginationParams): Promise<PaginatedResult<Collection>>;
379
+ detail(slug: string, params?: PaginationParams): Promise<CollectionDetail>;
380
+ }
381
+
382
+ export interface ShareEndpoints {
383
+ list(params?: PaginationParams): Promise<PaginatedResult<Share>>;
384
+ detail(id: number): Promise<ShareDetail>;
385
+ }
386
+
387
+ export interface RequestEndpoints {
388
+ list(params?: PaginationParams): Promise<PaginatedResult<UserRequest>>;
389
+ create(input: CreateRequestInput): Promise<CreateRequestResult>;
390
+ }
391
+
392
+ export interface ActivityEndpoints {
393
+ list(params?: ActivityParams): Promise<PaginatedResult<Activity>>;
394
+ }
395
+
396
+ export interface UserEndpoints {
397
+ profile(username: string): Promise<PublicUserProfile>;
398
+ }
399
+
400
+ export interface CommentEndpoints {
401
+ create(input: CreateCommentInput): Promise<CommentCreateResult>;
402
+ delete(id: number): Promise<CommentDeleteResult>;
403
+ }
404
+
405
+ export interface ReportEndpoints {
406
+ invalidResource(input: ReportInvalidResourceInput): Promise<ReportResult>;
407
+ }
408
+
409
+ export interface FollowEndpoints {
410
+ set(input: FollowInput): Promise<FollowResult>;
411
+ follow(username: string): Promise<FollowResult>;
412
+ unfollow(username: string): Promise<FollowResult>;
413
+ }
414
+
415
+ export class DdysApiError extends Error {
416
+ readonly name: string;
417
+ readonly status?: number;
418
+ readonly method: string;
419
+ readonly endpoint: string;
420
+ readonly response?: unknown;
421
+ readonly cause?: unknown;
422
+ constructor(message: string, options?: {
423
+ status?: number;
424
+ method?: string;
425
+ endpoint?: string;
426
+ response?: unknown;
427
+ cause?: unknown;
428
+ });
429
+ }
430
+
431
+ export class DdysTimeoutError extends DdysApiError {}
432
+ export class DdysNetworkError extends DdysApiError {}
433
+ export class DdysParseError extends DdysApiError {}
434
+
435
+ export class DdysClient {
436
+ readonly baseUrl: string;
437
+ readonly apiKey: string;
438
+ readonly timeoutMs: number;
439
+ readonly movies: MovieEndpoints;
440
+ readonly dictionaries: DictionaryEndpoints;
441
+ readonly collections: CollectionEndpoints;
442
+ readonly shares: ShareEndpoints;
443
+ readonly requests: RequestEndpoints;
444
+ readonly activities: ActivityEndpoints;
445
+ readonly users: UserEndpoints;
446
+ readonly comments: CommentEndpoints;
447
+ readonly reports: ReportEndpoints;
448
+ readonly follow: FollowEndpoints;
449
+
450
+ constructor(options?: DdysClientOptions);
451
+ request<T = unknown>(path: string, options?: RequestOptions): Promise<ApiSuccess<T>>;
452
+ get<T = unknown>(path: string, query?: Record<string, QueryValue>, options?: Omit<RequestOptions, 'method' | 'query'>): Promise<ApiSuccess<T>>;
453
+ post<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiSuccess<T>>;
454
+ delete<T = unknown>(path: string, options?: Omit<RequestOptions, 'method'>): Promise<ApiSuccess<T>>;
455
+ search(params: SearchParams): Promise<PaginatedResult<MovieListItem | Share | UserRequest>>;
456
+ suggest(q: string): Promise<SearchSuggestion[]>;
457
+ hot(): Promise<HotMovie[]>;
458
+ latest(params?: LatestParams): Promise<MovieListItem[]>;
459
+ calendar(params?: CalendarParams): Promise<CalendarData>;
460
+ me(): Promise<CurrentUserProfile>;
461
+ }
462
+
463
+ export function createDdysClient(options?: DdysClientOptions): DdysClient;
464
+
465
+ export default createDdysClient;