vidnavigator 1.0.5 → 2.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.
@@ -1,454 +1,521 @@
1
- import { UsageBlock } from './Usage';
2
-
3
- export interface TikTokProfileScrapeRequest {
4
- profile_url: string;
5
- max_posts?: number;
6
- /** Format: YYYY-MM-DD or ISO datetime with timezone */
7
- after_datetime?: string;
8
- /** Format: YYYY-MM-DD or ISO datetime with timezone */
9
- before_datetime?: string;
10
- min_likes?: number;
11
- max_likes?: number;
12
- }
13
-
14
- export interface TikTokSearchRequest {
15
- query: string;
16
- max_results?: number;
17
- parallel_search_slices?: number;
18
- /** Format: YYYY-MM-DD or ISO datetime with timezone */
19
- after_datetime?: string;
20
- /** Format: YYYY-MM-DD or ISO datetime with timezone */
21
- before_datetime?: string;
22
- min_likes?: number;
23
- max_likes?: number;
24
- min_views?: number;
25
- max_views?: number;
26
- }
27
-
28
- function toInteger(value: number | null | undefined): number | null | undefined {
29
- if (value === null || value === undefined) return value;
30
- return Math.trunc(value);
31
- }
32
-
33
- function toOptionalInteger(value: number | undefined): number | undefined {
34
- if (value === undefined) return undefined;
35
- return Math.trunc(value);
36
- }
37
-
38
- function toNullableDate(value: string | null | undefined): Date | null | undefined {
39
- if (value === null || value === undefined) return value;
40
- const date = new Date(value);
41
- return Number.isNaN(date.getTime()) ? undefined : date;
42
- }
43
-
44
- function normalizeFilters(filters: TikTokProfileFilters | undefined): TikTokProfileFilters | undefined {
45
- if (!filters) return undefined;
46
- return {
47
- max_posts: toInteger(filters.max_posts),
48
- after_datetime: filters.after_datetime,
49
- before_datetime: filters.before_datetime,
50
- min_likes: toInteger(filters.min_likes),
51
- max_likes: toInteger(filters.max_likes),
52
- };
53
- }
54
-
55
- function normalizeSearchFilters(
56
- filters: TikTokSearchFilters | undefined
57
- ): TikTokSearchFilters | undefined {
58
- if (!filters) return undefined;
59
- return {
60
- after_datetime: filters.after_datetime,
61
- before_datetime: filters.before_datetime,
62
- min_likes: toInteger(filters.min_likes),
63
- max_likes: toInteger(filters.max_likes),
64
- min_views: toInteger(filters.min_views),
65
- max_views: toInteger(filters.max_views),
66
- };
67
- }
68
-
69
- function normalizeStats(stats: TikTokProfileStats | undefined): TikTokProfileStats | undefined {
70
- if (!stats) return undefined;
71
- return {
72
- videos_scanned: toOptionalInteger(stats.videos_scanned),
73
- videos_matched: toOptionalInteger(stats.videos_matched),
74
- pages_consumed: toOptionalInteger(stats.pages_consumed),
75
- };
76
- }
77
-
78
- function normalizeSearchStats(stats: TikTokSearchStats | undefined): TikTokSearchStats | undefined {
79
- if (!stats) return undefined;
80
- return {
81
- pages_fetched: toOptionalInteger(stats.pages_fetched),
82
- results_count: toOptionalInteger(stats.results_count),
83
- next_search_cursor: toInteger(stats.next_search_cursor),
84
- };
85
- }
86
-
87
- function normalizePagination(
88
- pagination: TikTokProfilePagination | undefined
89
- ): TikTokProfilePagination | undefined {
90
- if (!pagination) return undefined;
91
- return {
92
- limit: toOptionalInteger(pagination.limit),
93
- offset: toOptionalInteger(pagination.offset),
94
- total_items: toOptionalInteger(pagination.total_items),
95
- has_next: pagination.has_next,
96
- has_prev: pagination.has_prev,
97
- next_cursor: pagination.next_cursor,
98
- prev_cursor: pagination.prev_cursor,
99
- };
100
- }
101
-
102
- export interface TikTokProfileScrapeSubmissionJSON {
103
- task_id: string;
104
- task_status: 'processing';
105
- profile_url: string;
106
- expires_at?: string;
107
- check_status_url?: string;
108
- message?: string;
109
- }
110
-
111
- export class TikTokProfileScrapeSubmission {
112
- task_id: string;
113
- task_status: 'processing';
114
- profile_url: string;
115
- expires_at?: string;
116
- check_status_url?: string;
117
- message?: string;
118
-
119
- constructor(data: TikTokProfileScrapeSubmissionJSON) {
120
- this.task_id = data.task_id;
121
- this.task_status = data.task_status;
122
- this.profile_url = data.profile_url;
123
- this.expires_at = data.expires_at;
124
- this.check_status_url = data.check_status_url;
125
- this.message = data.message;
126
- }
127
-
128
- static fromJSON(json: TikTokProfileScrapeSubmissionJSON): TikTokProfileScrapeSubmission {
129
- return new TikTokProfileScrapeSubmission(json);
130
- }
131
- }
132
-
133
- export interface TikTokSearchSubmissionJSON {
134
- task_id: string;
135
- task_status: 'processing';
136
- query: string;
137
- max_results?: number;
138
- parallel_search_slices?: number;
139
- filters?: Record<string, unknown>;
140
- expires_at?: string;
141
- check_status_url?: string;
142
- message?: string;
143
- }
144
-
145
- export class TikTokSearchSubmission {
146
- task_id: string;
147
- task_status: 'processing';
148
- query: string;
149
- max_results?: number;
150
- parallel_search_slices?: number;
151
- filters?: Record<string, unknown>;
152
- expires_at?: string;
153
- check_status_url?: string;
154
- message?: string;
155
-
156
- constructor(data: TikTokSearchSubmissionJSON) {
157
- this.task_id = data.task_id;
158
- this.task_status = data.task_status;
159
- this.query = data.query;
160
- this.max_results = toOptionalInteger(data.max_results);
161
- this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
162
- this.filters = data.filters;
163
- this.expires_at = data.expires_at;
164
- this.check_status_url = data.check_status_url;
165
- this.message = data.message;
166
- }
167
-
168
- static fromJSON(json: TikTokSearchSubmissionJSON): TikTokSearchSubmission {
169
- return new TikTokSearchSubmission(json);
170
- }
171
- }
172
-
173
- export interface TikTokVideoJSON {
174
- id?: string;
175
- track?: string | null;
176
- artists?: string[];
177
- duration?: number | null;
178
- title?: string | null;
179
- description?: string | null;
180
- timestamp?: number | null;
181
- published_at?: string | null;
182
- views?: number | null;
183
- likes?: number | null;
184
- reposts?: number | null;
185
- comments?: number | null;
186
- thumbnails?: Array<Record<string, unknown>>;
187
- url?: string;
188
- }
189
-
190
- export class TikTokVideo {
191
- id?: string;
192
- track?: string | null;
193
- artists?: string[];
194
- duration?: number | null;
195
- title?: string | null;
196
- description?: string | null;
197
- timestamp?: number | null;
198
- published_at?: Date | null;
199
- views?: number | null;
200
- likes?: number | null;
201
- reposts?: number | null;
202
- comments?: number | null;
203
- thumbnails?: Array<Record<string, unknown>>;
204
- url?: string;
205
-
206
- constructor(data: TikTokVideoJSON) {
207
- this.id = data.id;
208
- this.track = data.track;
209
- this.artists = data.artists;
210
- this.duration = toInteger(data.duration);
211
- this.title = data.title;
212
- this.description = data.description;
213
- this.timestamp = toInteger(data.timestamp);
214
- this.published_at = toNullableDate(data.published_at);
215
- this.views = toInteger(data.views);
216
- this.likes = toInteger(data.likes);
217
- this.reposts = toInteger(data.reposts);
218
- this.comments = toInteger(data.comments);
219
- this.thumbnails = data.thumbnails;
220
- this.url = data.url;
221
- }
222
-
223
- static fromJSON(json: TikTokVideoJSON): TikTokVideo {
224
- return new TikTokVideo(json);
225
- }
226
- }
227
-
228
- export interface TikTokProfileFilters {
229
- max_posts?: number | null;
230
- after_datetime?: string | null;
231
- before_datetime?: string | null;
232
- min_likes?: number | null;
233
- max_likes?: number | null;
234
- }
235
-
236
- export interface TikTokProfileStats {
237
- videos_scanned?: number;
238
- videos_matched?: number;
239
- pages_consumed?: number;
240
- }
241
-
242
- export interface TikTokProfilePagination {
243
- limit?: number;
244
- offset?: number;
245
- total_items?: number;
246
- has_next?: boolean;
247
- has_prev?: boolean;
248
- next_cursor?: string | null;
249
- prev_cursor?: string | null;
250
- }
251
-
252
- export interface TikTokSearchAuthor {
253
- id?: string | null;
254
- unique_id?: string | null;
255
- nickname?: string | null;
256
- sec_uid?: string | null;
257
- }
258
-
259
- export interface TikTokSearchResultStats {
260
- views?: number | null;
261
- likes?: number | null;
262
- comments?: number | null;
263
- shares?: number | null;
264
- collects?: number | null;
265
- }
266
-
267
- export interface TikTokSearchMusic {
268
- id?: string | null;
269
- title?: string | null;
270
- author_name?: string | null;
271
- duration?: number | null;
272
- }
273
-
274
- export interface TikTokSearchResultJSON {
275
- id?: string | null;
276
- item_type?: number | null;
277
- description?: string | null;
278
- timestamp?: number | null;
279
- published_at?: string | null;
280
- author?: TikTokSearchAuthor;
281
- stats?: TikTokSearchResultStats;
282
- music?: TikTokSearchMusic;
283
- duration?: number | null;
284
- hashtags?: string[];
285
- url?: string | null;
286
- }
287
-
288
- export class TikTokSearchResult {
289
- id?: string | null;
290
- item_type?: number | null;
291
- description?: string | null;
292
- timestamp?: number | null;
293
- published_at?: Date | null;
294
- author?: TikTokSearchAuthor;
295
- stats?: TikTokSearchResultStats;
296
- music?: TikTokSearchMusic;
297
- duration?: number | null;
298
- hashtags?: string[];
299
- url?: string | null;
300
-
301
- constructor(data: TikTokSearchResultJSON) {
302
- this.id = data.id;
303
- this.item_type = toInteger(data.item_type);
304
- this.description = data.description;
305
- this.timestamp = toInteger(data.timestamp);
306
- this.published_at = toNullableDate(data.published_at);
307
- this.author = data.author;
308
- this.stats = data.stats
309
- ? {
310
- views: toInteger(data.stats.views),
311
- likes: toInteger(data.stats.likes),
312
- comments: toInteger(data.stats.comments),
313
- shares: toInteger(data.stats.shares),
314
- collects: toInteger(data.stats.collects),
315
- }
316
- : undefined;
317
- this.music = data.music
318
- ? {
319
- ...data.music,
320
- duration: toInteger(data.music.duration),
321
- }
322
- : undefined;
323
- this.duration = toInteger(data.duration);
324
- this.hashtags = data.hashtags;
325
- this.url = data.url;
326
- }
327
-
328
- static fromJSON(json: TikTokSearchResultJSON): TikTokSearchResult {
329
- return new TikTokSearchResult(json);
330
- }
331
- }
332
-
333
- export interface TikTokSearchFilters {
334
- after_datetime?: string | null;
335
- before_datetime?: string | null;
336
- min_likes?: number | null;
337
- max_likes?: number | null;
338
- min_views?: number | null;
339
- max_views?: number | null;
340
- }
341
-
342
- export interface TikTokSearchStats {
343
- pages_fetched?: number;
344
- results_count?: number;
345
- next_search_cursor?: number | null;
346
- }
347
-
348
- export interface TikTokProfileTaskJSON {
349
- task_id: string;
350
- task_status: 'processing' | 'completed' | 'failed';
351
- profile_url?: string;
352
- profile?: Record<string, unknown> | null;
353
- filters?: TikTokProfileFilters;
354
- stats?: TikTokProfileStats;
355
- videos?: TikTokVideoJSON[];
356
- pagination?: TikTokProfilePagination;
357
- download_url?: string | null;
358
- error_message?: string | null;
359
- created_at?: string | null;
360
- completed_at?: string | null;
361
- expires_at?: string | null;
362
- }
363
-
364
- export class TikTokProfileTask {
365
- task_id: string;
366
- task_status: 'processing' | 'completed' | 'failed';
367
- profile_url?: string;
368
- profile?: Record<string, unknown> | null;
369
- filters?: TikTokProfileFilters;
370
- stats?: TikTokProfileStats;
371
- videos: TikTokVideo[];
372
- pagination?: TikTokProfilePagination;
373
- download_url?: string | null;
374
- error_message?: string | null;
375
- created_at?: string | null;
376
- completed_at?: string | null;
377
- expires_at?: string | null;
378
- /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
379
- usage?: UsageBlock;
380
-
381
- constructor(data: TikTokProfileTaskJSON) {
382
- this.task_id = data.task_id;
383
- this.task_status = data.task_status;
384
- this.profile_url = data.profile_url;
385
- this.profile = data.profile;
386
- this.filters = normalizeFilters(data.filters);
387
- this.stats = normalizeStats(data.stats);
388
- this.videos = data.videos?.map(TikTokVideo.fromJSON) ?? [];
389
- this.pagination = normalizePagination(data.pagination);
390
- this.download_url = data.download_url;
391
- this.error_message = data.error_message;
392
- this.created_at = data.created_at;
393
- this.completed_at = data.completed_at;
394
- this.expires_at = data.expires_at;
395
- }
396
-
397
- static fromJSON(json: TikTokProfileTaskJSON): TikTokProfileTask {
398
- return new TikTokProfileTask(json);
399
- }
400
- }
401
-
402
- export interface TikTokSearchTaskJSON {
403
- task_id: string;
404
- task_status: 'processing' | 'completed' | 'failed';
405
- query?: string;
406
- parallel_search_slices?: number;
407
- filters?: TikTokSearchFilters;
408
- stats?: TikTokSearchStats;
409
- results?: TikTokSearchResultJSON[];
410
- pagination?: TikTokProfilePagination;
411
- download_url?: string | null;
412
- error_message?: string | null;
413
- created_at?: string | null;
414
- completed_at?: string | null;
415
- expires_at?: string | null;
416
- }
417
-
418
- export class TikTokSearchTask {
419
- task_id: string;
420
- task_status: 'processing' | 'completed' | 'failed';
421
- query?: string;
422
- parallel_search_slices?: number;
423
- filters?: TikTokSearchFilters;
424
- stats?: TikTokSearchStats;
425
- results: TikTokSearchResult[];
426
- pagination?: TikTokProfilePagination;
427
- download_url?: string | null;
428
- error_message?: string | null;
429
- created_at?: string | null;
430
- completed_at?: string | null;
431
- expires_at?: string | null;
432
- /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
433
- usage?: UsageBlock;
434
-
435
- constructor(data: TikTokSearchTaskJSON) {
436
- this.task_id = data.task_id;
437
- this.task_status = data.task_status;
438
- this.query = data.query;
439
- this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
440
- this.filters = normalizeSearchFilters(data.filters);
441
- this.stats = normalizeSearchStats(data.stats);
442
- this.results = data.results?.map(TikTokSearchResult.fromJSON) ?? [];
443
- this.pagination = normalizePagination(data.pagination);
444
- this.download_url = data.download_url;
445
- this.error_message = data.error_message;
446
- this.created_at = data.created_at;
447
- this.completed_at = data.completed_at;
448
- this.expires_at = data.expires_at;
449
- }
450
-
451
- static fromJSON(json: TikTokSearchTaskJSON): TikTokSearchTask {
452
- return new TikTokSearchTask(json);
453
- }
454
- }
1
+ import { UsageBlock } from './Usage';
2
+ import { AsyncJobError, AsyncJobWebhookStatus } from './AsyncJob';
3
+
4
+ /** Sort order applied by TikTok itself for keyword searches. */
5
+ export type TikTokSearchSortBy = 'relevance' | 'most_liked' | 'newest';
6
+
7
+ /** Rolling publication window applied by TikTok itself (`this_week` = the last 7 days). */
8
+ export type TikTokPublishedWithin =
9
+ | 'all'
10
+ | 'past_24_hours'
11
+ | 'this_week'
12
+ | 'this_month'
13
+ | 'last_3_months'
14
+ | 'last_6_months';
15
+
16
+ export interface TikTokProfileScrapeRequest {
17
+ profile_url: string;
18
+ max_posts?: number;
19
+ /** Format: YYYY-MM-DD or ISO datetime with timezone */
20
+ after_datetime?: string;
21
+ /** Format: YYYY-MM-DD or ISO datetime with timezone */
22
+ before_datetime?: string;
23
+ min_likes?: number;
24
+ max_likes?: number;
25
+ /**
26
+ * Where to POST a notification when the task finishes. Overrides the account-level default
27
+ * configured in Studio → API; pass an empty string to opt this task out of that default.
28
+ * Must be a publicly reachable https URL. The event's `data.result` is a summary (`stats`, `download_url_available`),
29
+ * not the videos (a scrape can hold thousands); read those with `vn.tiktokProfile.resume(task_id).result()`.
30
+ */
31
+ webhook_url?: string;
32
+ }
33
+
34
+ export interface TikTokSearchRequest {
35
+ query: string;
36
+ max_results?: number;
37
+ parallel_search_slices?: number;
38
+ /** Sort order applied by TikTok. When omitted, results are returned newest first. */
39
+ sort_by?: TikTokSearchSortBy;
40
+ /** Publication window applied by TikTok. Auto-selected from `after_datetime` when omitted. */
41
+ published_within?: TikTokPublishedWithin;
42
+ /** Format: YYYY-MM-DD or ISO datetime with timezone */
43
+ after_datetime?: string;
44
+ /** Format: YYYY-MM-DD or ISO datetime with timezone */
45
+ before_datetime?: string;
46
+ min_likes?: number;
47
+ max_likes?: number;
48
+ min_views?: number;
49
+ max_views?: number;
50
+ /**
51
+ * Where to POST a notification when the task finishes. Overrides the account-level default
52
+ * configured in Studio → API; pass an empty string to opt this task out of that default.
53
+ * Must be a publicly reachable https URL. The event's `data.result` is a summary (`stats`, `download_url_available`);
54
+ * read the results with `vn.tiktokSearch.resume(task_id).result()`.
55
+ */
56
+ webhook_url?: string;
57
+ }
58
+
59
+ function toInteger(value: number | null | undefined): number | null | undefined {
60
+ if (value === null || value === undefined) return value;
61
+ return Math.trunc(value);
62
+ }
63
+
64
+ function toOptionalInteger(value: number | undefined): number | undefined {
65
+ if (value === undefined) return undefined;
66
+ return Math.trunc(value);
67
+ }
68
+
69
+ function toNullableDate(value: string | null | undefined): Date | null | undefined {
70
+ if (value === null || value === undefined) return value;
71
+ const date = new Date(value);
72
+ return Number.isNaN(date.getTime()) ? undefined : date;
73
+ }
74
+
75
+ function normalizeFilters(filters: TikTokProfileFilters | undefined): TikTokProfileFilters | undefined {
76
+ if (!filters) return undefined;
77
+ return {
78
+ max_posts: toInteger(filters.max_posts),
79
+ after_datetime: filters.after_datetime,
80
+ before_datetime: filters.before_datetime,
81
+ min_likes: toInteger(filters.min_likes),
82
+ max_likes: toInteger(filters.max_likes),
83
+ };
84
+ }
85
+
86
+ function normalizeSearchFilters(
87
+ filters: TikTokSearchFilters | undefined
88
+ ): TikTokSearchFilters | undefined {
89
+ if (!filters) return undefined;
90
+ return {
91
+ sort_by: filters.sort_by,
92
+ published_within: filters.published_within,
93
+ after_datetime: filters.after_datetime,
94
+ before_datetime: filters.before_datetime,
95
+ min_likes: toInteger(filters.min_likes),
96
+ max_likes: toInteger(filters.max_likes),
97
+ min_views: toInteger(filters.min_views),
98
+ max_views: toInteger(filters.max_views),
99
+ };
100
+ }
101
+
102
+ function normalizeStats(stats: TikTokProfileStats | undefined): TikTokProfileStats | undefined {
103
+ if (!stats) return undefined;
104
+ return {
105
+ videos_scanned: toOptionalInteger(stats.videos_scanned),
106
+ videos_matched: toOptionalInteger(stats.videos_matched),
107
+ pages_consumed: toOptionalInteger(stats.pages_consumed),
108
+ };
109
+ }
110
+
111
+ function normalizeSearchStats(stats: TikTokSearchStats | undefined): TikTokSearchStats | undefined {
112
+ if (!stats) return undefined;
113
+ return {
114
+ pages_fetched: toOptionalInteger(stats.pages_fetched),
115
+ results_count: toOptionalInteger(stats.results_count),
116
+ next_search_cursor: toInteger(stats.next_search_cursor),
117
+ sort_by: stats.sort_by,
118
+ published_within: stats.published_within,
119
+ };
120
+ }
121
+
122
+ function normalizePagination(
123
+ pagination: TikTokProfilePagination | undefined
124
+ ): TikTokProfilePagination | undefined {
125
+ if (!pagination) return undefined;
126
+ return {
127
+ limit: toOptionalInteger(pagination.limit),
128
+ offset: toOptionalInteger(pagination.offset),
129
+ total_items: toOptionalInteger(pagination.total_items),
130
+ has_next: pagination.has_next,
131
+ has_prev: pagination.has_prev,
132
+ next_cursor: pagination.next_cursor,
133
+ prev_cursor: pagination.prev_cursor,
134
+ };
135
+ }
136
+
137
+ export interface TikTokProfileScrapeSubmissionJSON {
138
+ task_id: string;
139
+ task_status: 'processing';
140
+ profile_url: string;
141
+ expires_at?: string;
142
+ check_status_url?: string;
143
+ message?: string;
144
+ webhook_url?: string | null;
145
+ }
146
+
147
+ export class TikTokProfileScrapeSubmission {
148
+ task_id: string;
149
+ task_status: 'processing';
150
+ profile_url: string;
151
+ expires_at?: string;
152
+ check_status_url?: string;
153
+ message?: string;
154
+ /** The URL this task's result notification will be POSTed to, or `null`. */
155
+ webhook_url?: string | null;
156
+
157
+ constructor(data: TikTokProfileScrapeSubmissionJSON) {
158
+ this.task_id = data.task_id;
159
+ this.task_status = data.task_status;
160
+ this.profile_url = data.profile_url;
161
+ this.expires_at = data.expires_at;
162
+ this.check_status_url = data.check_status_url;
163
+ this.message = data.message;
164
+ this.webhook_url = data.webhook_url;
165
+ }
166
+
167
+ static fromJSON(json: TikTokProfileScrapeSubmissionJSON): TikTokProfileScrapeSubmission {
168
+ return new TikTokProfileScrapeSubmission(json);
169
+ }
170
+ }
171
+
172
+ export interface TikTokSearchSubmissionJSON {
173
+ task_id: string;
174
+ task_status: 'processing';
175
+ query: string;
176
+ max_results?: number;
177
+ parallel_search_slices?: number;
178
+ filters?: Record<string, unknown>;
179
+ expires_at?: string;
180
+ check_status_url?: string;
181
+ message?: string;
182
+ webhook_url?: string | null;
183
+ }
184
+
185
+ export class TikTokSearchSubmission {
186
+ task_id: string;
187
+ task_status: 'processing';
188
+ query: string;
189
+ max_results?: number;
190
+ parallel_search_slices?: number;
191
+ filters?: Record<string, unknown>;
192
+ expires_at?: string;
193
+ check_status_url?: string;
194
+ message?: string;
195
+ /** The URL this task's result notification will be POSTed to, or `null`. */
196
+ webhook_url?: string | null;
197
+
198
+ constructor(data: TikTokSearchSubmissionJSON) {
199
+ this.task_id = data.task_id;
200
+ this.task_status = data.task_status;
201
+ this.query = data.query;
202
+ this.max_results = toOptionalInteger(data.max_results);
203
+ this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
204
+ this.filters = data.filters;
205
+ this.expires_at = data.expires_at;
206
+ this.check_status_url = data.check_status_url;
207
+ this.message = data.message;
208
+ this.webhook_url = data.webhook_url;
209
+ }
210
+
211
+ static fromJSON(json: TikTokSearchSubmissionJSON): TikTokSearchSubmission {
212
+ return new TikTokSearchSubmission(json);
213
+ }
214
+ }
215
+
216
+ export interface TikTokVideoJSON {
217
+ id?: string;
218
+ track?: string | null;
219
+ artists?: string[];
220
+ duration?: number | null;
221
+ title?: string | null;
222
+ description?: string | null;
223
+ timestamp?: number | null;
224
+ published_at?: string | null;
225
+ views?: number | null;
226
+ likes?: number | null;
227
+ reposts?: number | null;
228
+ comments?: number | null;
229
+ thumbnails?: Array<Record<string, unknown>>;
230
+ url?: string;
231
+ }
232
+
233
+ export class TikTokVideo {
234
+ id?: string;
235
+ track?: string | null;
236
+ artists?: string[];
237
+ duration?: number | null;
238
+ title?: string | null;
239
+ description?: string | null;
240
+ timestamp?: number | null;
241
+ published_at?: Date | null;
242
+ views?: number | null;
243
+ likes?: number | null;
244
+ reposts?: number | null;
245
+ comments?: number | null;
246
+ thumbnails?: Array<Record<string, unknown>>;
247
+ url?: string;
248
+
249
+ constructor(data: TikTokVideoJSON) {
250
+ this.id = data.id;
251
+ this.track = data.track;
252
+ this.artists = data.artists;
253
+ this.duration = toInteger(data.duration);
254
+ this.title = data.title;
255
+ this.description = data.description;
256
+ this.timestamp = toInteger(data.timestamp);
257
+ this.published_at = toNullableDate(data.published_at);
258
+ this.views = toInteger(data.views);
259
+ this.likes = toInteger(data.likes);
260
+ this.reposts = toInteger(data.reposts);
261
+ this.comments = toInteger(data.comments);
262
+ this.thumbnails = data.thumbnails;
263
+ this.url = data.url;
264
+ }
265
+
266
+ static fromJSON(json: TikTokVideoJSON): TikTokVideo {
267
+ return new TikTokVideo(json);
268
+ }
269
+ }
270
+
271
+ export interface TikTokProfileFilters {
272
+ max_posts?: number | null;
273
+ after_datetime?: string | null;
274
+ before_datetime?: string | null;
275
+ min_likes?: number | null;
276
+ max_likes?: number | null;
277
+ }
278
+
279
+ export interface TikTokProfileStats {
280
+ videos_scanned?: number;
281
+ videos_matched?: number;
282
+ pages_consumed?: number;
283
+ }
284
+
285
+ export interface TikTokProfilePagination {
286
+ limit?: number;
287
+ offset?: number;
288
+ total_items?: number;
289
+ has_next?: boolean;
290
+ has_prev?: boolean;
291
+ next_cursor?: string | null;
292
+ prev_cursor?: string | null;
293
+ }
294
+
295
+ export interface TikTokSearchAuthor {
296
+ id?: string | null;
297
+ unique_id?: string | null;
298
+ nickname?: string | null;
299
+ sec_uid?: string | null;
300
+ }
301
+
302
+ export interface TikTokSearchResultStats {
303
+ views?: number | null;
304
+ likes?: number | null;
305
+ comments?: number | null;
306
+ shares?: number | null;
307
+ collects?: number | null;
308
+ }
309
+
310
+ export interface TikTokSearchMusic {
311
+ id?: string | null;
312
+ title?: string | null;
313
+ author_name?: string | null;
314
+ duration?: number | null;
315
+ }
316
+
317
+ export interface TikTokSearchResultJSON {
318
+ id?: string | null;
319
+ item_type?: number | null;
320
+ description?: string | null;
321
+ timestamp?: number | null;
322
+ published_at?: string | null;
323
+ author?: TikTokSearchAuthor;
324
+ stats?: TikTokSearchResultStats;
325
+ music?: TikTokSearchMusic;
326
+ duration?: number | null;
327
+ hashtags?: string[];
328
+ url?: string | null;
329
+ }
330
+
331
+ export class TikTokSearchResult {
332
+ id?: string | null;
333
+ item_type?: number | null;
334
+ description?: string | null;
335
+ timestamp?: number | null;
336
+ published_at?: Date | null;
337
+ author?: TikTokSearchAuthor;
338
+ stats?: TikTokSearchResultStats;
339
+ music?: TikTokSearchMusic;
340
+ duration?: number | null;
341
+ hashtags?: string[];
342
+ url?: string | null;
343
+
344
+ constructor(data: TikTokSearchResultJSON) {
345
+ this.id = data.id;
346
+ this.item_type = toInteger(data.item_type);
347
+ this.description = data.description;
348
+ this.timestamp = toInteger(data.timestamp);
349
+ this.published_at = toNullableDate(data.published_at);
350
+ this.author = data.author;
351
+ this.stats = data.stats
352
+ ? {
353
+ views: toInteger(data.stats.views),
354
+ likes: toInteger(data.stats.likes),
355
+ comments: toInteger(data.stats.comments),
356
+ shares: toInteger(data.stats.shares),
357
+ collects: toInteger(data.stats.collects),
358
+ }
359
+ : undefined;
360
+ this.music = data.music
361
+ ? {
362
+ ...data.music,
363
+ duration: toInteger(data.music.duration),
364
+ }
365
+ : undefined;
366
+ this.duration = toInteger(data.duration);
367
+ this.hashtags = data.hashtags;
368
+ this.url = data.url;
369
+ }
370
+
371
+ static fromJSON(json: TikTokSearchResultJSON): TikTokSearchResult {
372
+ return new TikTokSearchResult(json);
373
+ }
374
+ }
375
+
376
+ export interface TikTokSearchFilters {
377
+ sort_by?: TikTokSearchSortBy | null;
378
+ published_within?: TikTokPublishedWithin | null;
379
+ after_datetime?: string | null;
380
+ before_datetime?: string | null;
381
+ min_likes?: number | null;
382
+ max_likes?: number | null;
383
+ min_views?: number | null;
384
+ max_views?: number | null;
385
+ }
386
+
387
+ export interface TikTokSearchStats {
388
+ pages_fetched?: number;
389
+ results_count?: number;
390
+ next_search_cursor?: number | null;
391
+ /** Sort order the search ran with (`relevance` when `sort_by` was omitted). */
392
+ sort_by?: TikTokSearchSortBy;
393
+ /** Date window the search ran with; `all` means no window. */
394
+ published_within?: TikTokPublishedWithin;
395
+ }
396
+
397
+ export interface TikTokProfileTaskJSON {
398
+ task_id: string;
399
+ task_status: 'processing' | 'completed' | 'failed';
400
+ profile_url?: string;
401
+ profile?: Record<string, unknown> | null;
402
+ filters?: TikTokProfileFilters;
403
+ stats?: TikTokProfileStats;
404
+ videos?: TikTokVideoJSON[];
405
+ pagination?: TikTokProfilePagination;
406
+ download_url?: string | null;
407
+ error_message?: string | null;
408
+ created_at?: string | null;
409
+ completed_at?: string | null;
410
+ expires_at?: string | null;
411
+ error?: AsyncJobError | null;
412
+ webhook?: AsyncJobWebhookStatus | null;
413
+ }
414
+
415
+ export class TikTokProfileTask {
416
+ task_id: string;
417
+ task_status: 'processing' | 'completed' | 'failed';
418
+ profile_url?: string;
419
+ profile?: Record<string, unknown> | null;
420
+ filters?: TikTokProfileFilters;
421
+ stats?: TikTokProfileStats;
422
+ videos: TikTokVideo[];
423
+ pagination?: TikTokProfilePagination;
424
+ download_url?: string | null;
425
+ /** @deprecated Use `error`, which carries a machine-readable code. */
426
+ error_message?: string | null;
427
+ created_at?: string | null;
428
+ completed_at?: string | null;
429
+ expires_at?: string | null;
430
+ /** Present when `task_status === 'failed'`: error code, message and HTTP status. */
431
+ error: AsyncJobError | null;
432
+ /** Webhook delivery state, or `null` when no webhook was configured. */
433
+ webhook?: AsyncJobWebhookStatus | null;
434
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
435
+ usage?: UsageBlock;
436
+
437
+ constructor(data: TikTokProfileTaskJSON) {
438
+ this.task_id = data.task_id;
439
+ this.task_status = data.task_status;
440
+ this.profile_url = data.profile_url;
441
+ this.profile = data.profile;
442
+ this.filters = normalizeFilters(data.filters);
443
+ this.stats = normalizeStats(data.stats);
444
+ this.videos = data.videos?.map(TikTokVideo.fromJSON) ?? [];
445
+ this.pagination = normalizePagination(data.pagination);
446
+ this.download_url = data.download_url;
447
+ this.error_message = data.error_message;
448
+ this.created_at = data.created_at;
449
+ this.completed_at = data.completed_at;
450
+ this.expires_at = data.expires_at;
451
+ this.error = data.error ?? null;
452
+ this.webhook = data.webhook;
453
+ }
454
+
455
+ static fromJSON(json: TikTokProfileTaskJSON): TikTokProfileTask {
456
+ return new TikTokProfileTask(json);
457
+ }
458
+ }
459
+
460
+ export interface TikTokSearchTaskJSON {
461
+ task_id: string;
462
+ task_status: 'processing' | 'completed' | 'failed';
463
+ query?: string;
464
+ parallel_search_slices?: number;
465
+ filters?: TikTokSearchFilters;
466
+ stats?: TikTokSearchStats;
467
+ results?: TikTokSearchResultJSON[];
468
+ pagination?: TikTokProfilePagination;
469
+ download_url?: string | null;
470
+ error_message?: string | null;
471
+ created_at?: string | null;
472
+ completed_at?: string | null;
473
+ expires_at?: string | null;
474
+ error?: AsyncJobError | null;
475
+ webhook?: AsyncJobWebhookStatus | null;
476
+ }
477
+
478
+ export class TikTokSearchTask {
479
+ task_id: string;
480
+ task_status: 'processing' | 'completed' | 'failed';
481
+ query?: string;
482
+ parallel_search_slices?: number;
483
+ filters?: TikTokSearchFilters;
484
+ stats?: TikTokSearchStats;
485
+ results: TikTokSearchResult[];
486
+ pagination?: TikTokProfilePagination;
487
+ download_url?: string | null;
488
+ /** @deprecated Use `error`, which carries a machine-readable code. */
489
+ error_message?: string | null;
490
+ created_at?: string | null;
491
+ completed_at?: string | null;
492
+ expires_at?: string | null;
493
+ /** Present when `task_status === 'failed'`: error code, message and HTTP status. */
494
+ error: AsyncJobError | null;
495
+ /** Webhook delivery state, or `null` when no webhook was configured. */
496
+ webhook?: AsyncJobWebhookStatus | null;
497
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
498
+ usage?: UsageBlock;
499
+
500
+ constructor(data: TikTokSearchTaskJSON) {
501
+ this.task_id = data.task_id;
502
+ this.task_status = data.task_status;
503
+ this.query = data.query;
504
+ this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
505
+ this.filters = normalizeSearchFilters(data.filters);
506
+ this.stats = normalizeSearchStats(data.stats);
507
+ this.results = data.results?.map(TikTokSearchResult.fromJSON) ?? [];
508
+ this.pagination = normalizePagination(data.pagination);
509
+ this.download_url = data.download_url;
510
+ this.error_message = data.error_message;
511
+ this.created_at = data.created_at;
512
+ this.completed_at = data.completed_at;
513
+ this.expires_at = data.expires_at;
514
+ this.error = data.error ?? null;
515
+ this.webhook = data.webhook;
516
+ }
517
+
518
+ static fromJSON(json: TikTokSearchTaskJSON): TikTokSearchTask {
519
+ return new TikTokSearchTask(json);
520
+ }
521
+ }