vidnavigator 2.1.0 → 2.3.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 +65 -8
- package/dist/index.d.ts +28 -3
- package/dist/index.js +62 -3
- package/dist/models/TikTok.d.ts +315 -0
- package/dist/models/TikTok.js +157 -2
- package/dist/webhooks.d.ts +2 -2
- package/package.json +1 -1
- package/src/index.ts +111 -3
- package/src/models/TikTok.ts +481 -1
- package/src/webhooks.ts +4 -2
package/src/models/TikTok.ts
CHANGED
|
@@ -47,6 +47,11 @@ export interface TikTokSearchRequest {
|
|
|
47
47
|
max_likes?: number;
|
|
48
48
|
min_views?: number;
|
|
49
49
|
max_views?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Two-letter country code (`'fr'`, `'de'`, `'jp'`, ...) whose TikTok results you get. Default `'gb'`.
|
|
52
|
+
* `'us'` is refused: TikTok asks US visitors to log in. The API lists the accepted codes.
|
|
53
|
+
*/
|
|
54
|
+
country?: string;
|
|
50
55
|
/**
|
|
51
56
|
* Where to POST a notification when the task finishes. Overrides the account-level default
|
|
52
57
|
* configured in Studio → API; pass an empty string to opt this task out of that default.
|
|
@@ -110,13 +115,24 @@ function normalizeStats(stats: TikTokProfileStats | undefined): TikTokProfileSta
|
|
|
110
115
|
|
|
111
116
|
function normalizeSearchStats(stats: TikTokSearchStats | undefined): TikTokSearchStats | undefined {
|
|
112
117
|
if (!stats) return undefined;
|
|
113
|
-
|
|
118
|
+
const normalized: TikTokSearchStats = {
|
|
114
119
|
pages_fetched: toOptionalInteger(stats.pages_fetched),
|
|
120
|
+
videos_fetched: toOptionalInteger(stats.videos_fetched),
|
|
115
121
|
results_count: toOptionalInteger(stats.results_count),
|
|
116
122
|
next_search_cursor: toInteger(stats.next_search_cursor),
|
|
123
|
+
parallel_search_slices: toOptionalInteger(stats.parallel_search_slices),
|
|
117
124
|
sort_by: stats.sort_by,
|
|
118
125
|
published_within: stats.published_within,
|
|
126
|
+
country: stats.country,
|
|
127
|
+
items_examined: toOptionalInteger(stats.items_examined),
|
|
128
|
+
items_filtered_out: toOptionalInteger(stats.items_filtered_out),
|
|
129
|
+
items_deduplicated: toOptionalInteger(stats.items_deduplicated),
|
|
119
130
|
};
|
|
131
|
+
// Leave out what the API did not send (the items_* counters are conditional).
|
|
132
|
+
for (const key of Object.keys(normalized) as Array<keyof TikTokSearchStats>) {
|
|
133
|
+
if (normalized[key] === undefined) delete normalized[key];
|
|
134
|
+
}
|
|
135
|
+
return normalized;
|
|
120
136
|
}
|
|
121
137
|
|
|
122
138
|
function normalizePagination(
|
|
@@ -173,6 +189,7 @@ export interface TikTokSearchSubmissionJSON {
|
|
|
173
189
|
task_id: string;
|
|
174
190
|
task_status: 'processing';
|
|
175
191
|
query: string;
|
|
192
|
+
country?: string;
|
|
176
193
|
max_results?: number;
|
|
177
194
|
parallel_search_slices?: number;
|
|
178
195
|
filters?: Record<string, unknown>;
|
|
@@ -186,6 +203,8 @@ export class TikTokSearchSubmission {
|
|
|
186
203
|
task_id: string;
|
|
187
204
|
task_status: 'processing';
|
|
188
205
|
query: string;
|
|
206
|
+
/** Country whose TikTok results the search returns. */
|
|
207
|
+
country?: string;
|
|
189
208
|
max_results?: number;
|
|
190
209
|
parallel_search_slices?: number;
|
|
191
210
|
filters?: Record<string, unknown>;
|
|
@@ -199,6 +218,7 @@ export class TikTokSearchSubmission {
|
|
|
199
218
|
this.task_id = data.task_id;
|
|
200
219
|
this.task_status = data.task_status;
|
|
201
220
|
this.query = data.query;
|
|
221
|
+
this.country = data.country;
|
|
202
222
|
this.max_results = toOptionalInteger(data.max_results);
|
|
203
223
|
this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
|
|
204
224
|
this.filters = data.filters;
|
|
@@ -386,12 +406,27 @@ export interface TikTokSearchFilters {
|
|
|
386
406
|
|
|
387
407
|
export interface TikTokSearchStats {
|
|
388
408
|
pages_fetched?: number;
|
|
409
|
+
/**
|
|
410
|
+
* Distinct videos TikTok returned, including those your filters dropped. Billed at
|
|
411
|
+
* 1 `residential_request` per 30, minimum 1 per search.
|
|
412
|
+
*/
|
|
413
|
+
videos_fetched?: number;
|
|
389
414
|
results_count?: number;
|
|
390
415
|
next_search_cursor?: number | null;
|
|
416
|
+
/** Slice count the search actually ran with. */
|
|
417
|
+
parallel_search_slices?: number;
|
|
391
418
|
/** Sort order the search ran with (`relevance` when `sort_by` was omitted). */
|
|
392
419
|
sort_by?: TikTokSearchSortBy;
|
|
393
420
|
/** Date window the search ran with; `all` means no window. */
|
|
394
421
|
published_within?: TikTokPublishedWithin;
|
|
422
|
+
/** Country whose TikTok results the search returned. */
|
|
423
|
+
country?: string;
|
|
424
|
+
/** Only when filters were set: videos checked against them. */
|
|
425
|
+
items_examined?: number;
|
|
426
|
+
/** Only when filters were set: videos they dropped. */
|
|
427
|
+
items_filtered_out?: number;
|
|
428
|
+
/** Only with `parallel_search_slices` > 1: videos several slices returned, counted once. */
|
|
429
|
+
items_deduplicated?: number;
|
|
395
430
|
}
|
|
396
431
|
|
|
397
432
|
export interface TikTokProfileTaskJSON {
|
|
@@ -461,6 +496,7 @@ export interface TikTokSearchTaskJSON {
|
|
|
461
496
|
task_id: string;
|
|
462
497
|
task_status: 'processing' | 'completed' | 'failed';
|
|
463
498
|
query?: string;
|
|
499
|
+
country?: string;
|
|
464
500
|
parallel_search_slices?: number;
|
|
465
501
|
filters?: TikTokSearchFilters;
|
|
466
502
|
stats?: TikTokSearchStats;
|
|
@@ -479,6 +515,8 @@ export class TikTokSearchTask {
|
|
|
479
515
|
task_id: string;
|
|
480
516
|
task_status: 'processing' | 'completed' | 'failed';
|
|
481
517
|
query?: string;
|
|
518
|
+
/** Country whose TikTok results the search returned (`gb` by default). */
|
|
519
|
+
country?: string;
|
|
482
520
|
parallel_search_slices?: number;
|
|
483
521
|
filters?: TikTokSearchFilters;
|
|
484
522
|
stats?: TikTokSearchStats;
|
|
@@ -501,6 +539,7 @@ export class TikTokSearchTask {
|
|
|
501
539
|
this.task_id = data.task_id;
|
|
502
540
|
this.task_status = data.task_status;
|
|
503
541
|
this.query = data.query;
|
|
542
|
+
this.country = data.country;
|
|
504
543
|
this.parallel_search_slices = toOptionalInteger(data.parallel_search_slices);
|
|
505
544
|
this.filters = normalizeSearchFilters(data.filters);
|
|
506
545
|
this.stats = normalizeSearchStats(data.stats);
|
|
@@ -519,3 +558,444 @@ export class TikTokSearchTask {
|
|
|
519
558
|
return new TikTokSearchTask(json);
|
|
520
559
|
}
|
|
521
560
|
}
|
|
561
|
+
|
|
562
|
+
// --- LIVE search ---
|
|
563
|
+
|
|
564
|
+
export interface TikTokLiveSearchRequest {
|
|
565
|
+
query: string;
|
|
566
|
+
/** Cap on rooms. `0` or omitted means as many as TikTok serves, about 50 per keyword. */
|
|
567
|
+
max_results?: number;
|
|
568
|
+
/** Two-letter country code whose LIVE rooms you get. Default `'us'`. The API lists the accepted codes. */
|
|
569
|
+
country?: string;
|
|
570
|
+
/**
|
|
571
|
+
* The API returns each room's playback URLs by default (FLV and HLS by quality, plus an
|
|
572
|
+
* audio-only stream). Pass `false` to leave them out.
|
|
573
|
+
*/
|
|
574
|
+
include_stream_urls?: boolean;
|
|
575
|
+
/**
|
|
576
|
+
* Where to POST a notification when the task finishes. Overrides the account-level default
|
|
577
|
+
* configured in Studio → API; pass an empty string to opt this task out of that default.
|
|
578
|
+
* The event's `data.result` is a summary; read the rooms with `vn.tiktokLiveSearch.resume(task_id).result()`.
|
|
579
|
+
*/
|
|
580
|
+
webhook_url?: string;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export interface TikTokLiveSearchSubmissionJSON {
|
|
584
|
+
task_id: string;
|
|
585
|
+
task_status: 'processing';
|
|
586
|
+
query: string;
|
|
587
|
+
country?: string;
|
|
588
|
+
max_results?: number;
|
|
589
|
+
include_stream_urls?: boolean;
|
|
590
|
+
expires_at?: string;
|
|
591
|
+
check_status_url?: string;
|
|
592
|
+
message?: string;
|
|
593
|
+
webhook_url?: string | null;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export class TikTokLiveSearchSubmission {
|
|
597
|
+
task_id: string;
|
|
598
|
+
task_status: 'processing';
|
|
599
|
+
query: string;
|
|
600
|
+
country?: string;
|
|
601
|
+
max_results?: number;
|
|
602
|
+
include_stream_urls?: boolean;
|
|
603
|
+
expires_at?: string;
|
|
604
|
+
check_status_url?: string;
|
|
605
|
+
message?: string;
|
|
606
|
+
/** The URL this task's result notification will be POSTed to, or `null`. */
|
|
607
|
+
webhook_url?: string | null;
|
|
608
|
+
|
|
609
|
+
constructor(data: TikTokLiveSearchSubmissionJSON) {
|
|
610
|
+
this.task_id = data.task_id;
|
|
611
|
+
this.task_status = data.task_status;
|
|
612
|
+
this.query = data.query;
|
|
613
|
+
this.country = data.country;
|
|
614
|
+
this.max_results = toOptionalInteger(data.max_results);
|
|
615
|
+
this.include_stream_urls = data.include_stream_urls;
|
|
616
|
+
this.expires_at = data.expires_at;
|
|
617
|
+
this.check_status_url = data.check_status_url;
|
|
618
|
+
this.message = data.message;
|
|
619
|
+
this.webhook_url = data.webhook_url;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
static fromJSON(json: TikTokLiveSearchSubmissionJSON): TikTokLiveSearchSubmission {
|
|
623
|
+
return new TikTokLiveSearchSubmission(json);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export interface TikTokLiveAuthor {
|
|
628
|
+
id?: string | null;
|
|
629
|
+
/** Username, without @. */
|
|
630
|
+
unique_id?: string | null;
|
|
631
|
+
nickname?: string | null;
|
|
632
|
+
sec_uid?: string | null;
|
|
633
|
+
followers?: number | null;
|
|
634
|
+
avatar_url?: string | null;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export interface TikTokLiveStats {
|
|
638
|
+
/** Watching when the search ran. */
|
|
639
|
+
viewers?: number | null;
|
|
640
|
+
/** Since the LIVE started. */
|
|
641
|
+
total_viewers?: number | null;
|
|
642
|
+
likes?: number | null;
|
|
643
|
+
comments?: number | null;
|
|
644
|
+
shares?: number | null;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** Quality keys of the playback URLs: those the LIVE offers, best first. */
|
|
648
|
+
export type TikTokLiveQuality = 'origin' | 'uhd' | 'hd' | 'sd' | 'ld' | (string & {});
|
|
649
|
+
|
|
650
|
+
export interface TikTokLiveStreamUrlsJSON {
|
|
651
|
+
default_quality?: TikTokLiveQuality | null;
|
|
652
|
+
flv?: Record<string, string>;
|
|
653
|
+
hls?: Record<string, string>;
|
|
654
|
+
audio_only?: string | null;
|
|
655
|
+
expires_at?: string | null;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/** Playback URLs of a LIVE room. They stop working when the LIVE ends. */
|
|
659
|
+
export interface TikTokLiveStreamUrls {
|
|
660
|
+
/** The quality TikTok plays by default (a key of `flv`). */
|
|
661
|
+
default_quality: TikTokLiveQuality | null;
|
|
662
|
+
/** HTTP-FLV URLs keyed by quality. */
|
|
663
|
+
flv: Record<string, string>;
|
|
664
|
+
/** HLS (`.m3u8`) URLs keyed by quality, when TikTok provides them. Can be empty. */
|
|
665
|
+
hls: Record<string, string>;
|
|
666
|
+
/** HTTP-FLV URL of the audio-only stream. */
|
|
667
|
+
audio_only: string | null;
|
|
668
|
+
/** Expiry of the URL signatures. */
|
|
669
|
+
expires_at: Date | null;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
export interface TikTokLiveRoomJSON {
|
|
673
|
+
id?: string | null;
|
|
674
|
+
title?: string | null;
|
|
675
|
+
url?: string | null;
|
|
676
|
+
started_at?: string | null;
|
|
677
|
+
author?: TikTokLiveAuthor;
|
|
678
|
+
stats?: TikTokLiveStats;
|
|
679
|
+
hashtags?: string[];
|
|
680
|
+
category?: string | null;
|
|
681
|
+
game_tags?: string[];
|
|
682
|
+
cover_url?: string | null;
|
|
683
|
+
stream_urls?: TikTokLiveStreamUrlsJSON;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/** A TikTok LIVE room that was broadcasting when the search ran. */
|
|
687
|
+
export class TikTokLiveRoom {
|
|
688
|
+
id?: string | null;
|
|
689
|
+
title?: string | null;
|
|
690
|
+
/** `https://www.tiktok.com/@username/live` */
|
|
691
|
+
url?: string | null;
|
|
692
|
+
started_at?: Date | null;
|
|
693
|
+
author?: TikTokLiveAuthor;
|
|
694
|
+
stats?: TikTokLiveStats;
|
|
695
|
+
/** `#tags` written in the title, without `#`. */
|
|
696
|
+
hashtags: string[];
|
|
697
|
+
/** The LIVE's category on TikTok, e.g. `'Gaming'`. */
|
|
698
|
+
category?: string | null;
|
|
699
|
+
game_tags: string[];
|
|
700
|
+
cover_url?: string | null;
|
|
701
|
+
/** Absent when the search was submitted with `include_stream_urls: false`. */
|
|
702
|
+
stream_urls?: TikTokLiveStreamUrls;
|
|
703
|
+
|
|
704
|
+
constructor(data: TikTokLiveRoomJSON) {
|
|
705
|
+
this.id = data.id;
|
|
706
|
+
this.title = data.title;
|
|
707
|
+
this.url = data.url;
|
|
708
|
+
this.started_at = toNullableDate(data.started_at);
|
|
709
|
+
this.author = data.author
|
|
710
|
+
? { ...data.author, followers: toInteger(data.author.followers) }
|
|
711
|
+
: undefined;
|
|
712
|
+
this.stats = data.stats
|
|
713
|
+
? {
|
|
714
|
+
viewers: toInteger(data.stats.viewers),
|
|
715
|
+
total_viewers: toInteger(data.stats.total_viewers),
|
|
716
|
+
likes: toInteger(data.stats.likes),
|
|
717
|
+
comments: toInteger(data.stats.comments),
|
|
718
|
+
shares: toInteger(data.stats.shares),
|
|
719
|
+
}
|
|
720
|
+
: undefined;
|
|
721
|
+
this.hashtags = data.hashtags ?? [];
|
|
722
|
+
this.category = data.category;
|
|
723
|
+
this.game_tags = data.game_tags ?? [];
|
|
724
|
+
this.cover_url = data.cover_url;
|
|
725
|
+
if (data.stream_urls) {
|
|
726
|
+
this.stream_urls = {
|
|
727
|
+
default_quality: data.stream_urls.default_quality ?? null,
|
|
728
|
+
flv: data.stream_urls.flv ?? {},
|
|
729
|
+
hls: data.stream_urls.hls ?? {},
|
|
730
|
+
audio_only: data.stream_urls.audio_only ?? null,
|
|
731
|
+
expires_at: toNullableDate(data.stream_urls.expires_at) ?? null,
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
static fromJSON(json: TikTokLiveRoomJSON): TikTokLiveRoom {
|
|
737
|
+
return new TikTokLiveRoom(json);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// --- LIVE room ---
|
|
742
|
+
|
|
743
|
+
/** Exactly one of `room_id`, `username` or `url`. */
|
|
744
|
+
export interface TikTokLiveRoomRequest {
|
|
745
|
+
/**
|
|
746
|
+
* A LIVE room ID, e.g. the `id` of a LIVE search room. Pass it as a string: room IDs have more
|
|
747
|
+
* digits than a JavaScript number holds.
|
|
748
|
+
*/
|
|
749
|
+
room_id?: string;
|
|
750
|
+
/** The streamer, with or without `@`: their current LIVE, or their last one when they are offline. */
|
|
751
|
+
username?: string;
|
|
752
|
+
/** `https://www.tiktok.com/@username/live`, the profile URL, or a room's `share_url`. */
|
|
753
|
+
url?: string;
|
|
754
|
+
/**
|
|
755
|
+
* Also return the latest comments (up to 50, newest first), the pinned comment, the intro and the
|
|
756
|
+
* top viewers. Bills 2 `residential_request` instead of 1. Default `false`.
|
|
757
|
+
*/
|
|
758
|
+
include_comments?: boolean;
|
|
759
|
+
/** At most this many comments, 1-50 (default 50). */
|
|
760
|
+
comments_limit?: number;
|
|
761
|
+
/** Playback URLs are returned by default; pass `false` to leave them out. */
|
|
762
|
+
include_stream_urls?: boolean;
|
|
763
|
+
/** Add the `usage` block to the result. */
|
|
764
|
+
include_usage?: boolean;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export interface TikTokLiveRoomAuthor extends TikTokLiveAuthor {
|
|
768
|
+
bio?: string | null;
|
|
769
|
+
/** Accounts the streamer follows. */
|
|
770
|
+
following?: number | null;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/** A single room's counters. Likes, comments and shares come with LIVE search only. */
|
|
774
|
+
export interface TikTokLiveRoomStats {
|
|
775
|
+
/** Watching now (0 once the LIVE has ended). */
|
|
776
|
+
viewers?: number | null;
|
|
777
|
+
/** Since the LIVE started. */
|
|
778
|
+
total_viewers?: number | null;
|
|
779
|
+
/** Followers the streamer gained during this LIVE. */
|
|
780
|
+
new_followers?: number | null;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
export interface TikTokLiveRoomDetailJSON extends TikTokLiveRoomJSON {
|
|
784
|
+
author?: TikTokLiveRoomAuthor;
|
|
785
|
+
stats?: TikTokLiveRoomStats;
|
|
786
|
+
status?: 'live' | 'ended' | 'unknown';
|
|
787
|
+
ended_at?: string | null;
|
|
788
|
+
share_url?: string | null;
|
|
789
|
+
age_restricted?: boolean;
|
|
790
|
+
subscribers_only?: boolean;
|
|
791
|
+
chat_enabled?: boolean;
|
|
792
|
+
products?: number;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/** One LIVE room, as `getTikTokLiveRoom` returns it. */
|
|
796
|
+
export class TikTokLiveRoomDetail extends TikTokLiveRoom {
|
|
797
|
+
declare author?: TikTokLiveRoomAuthor;
|
|
798
|
+
declare stats?: TikTokLiveRoomStats;
|
|
799
|
+
/** `'live'` while broadcasting, `'ended'` once finished. */
|
|
800
|
+
status?: 'live' | 'ended' | 'unknown';
|
|
801
|
+
ended_at?: Date | null;
|
|
802
|
+
/** The room's share link; it can be passed back as `url`. */
|
|
803
|
+
share_url?: string | null;
|
|
804
|
+
age_restricted?: boolean;
|
|
805
|
+
/** Only the streamer's paying subscribers can watch. */
|
|
806
|
+
subscribers_only?: boolean;
|
|
807
|
+
chat_enabled?: boolean;
|
|
808
|
+
/** Products on sale in the LIVE. */
|
|
809
|
+
products?: number;
|
|
810
|
+
|
|
811
|
+
constructor(data: TikTokLiveRoomDetailJSON) {
|
|
812
|
+
super(data);
|
|
813
|
+
this.author = data.author
|
|
814
|
+
? { ...data.author, followers: toInteger(data.author.followers), following: toInteger(data.author.following) }
|
|
815
|
+
: undefined;
|
|
816
|
+
this.stats = data.stats
|
|
817
|
+
? {
|
|
818
|
+
viewers: toInteger(data.stats.viewers),
|
|
819
|
+
total_viewers: toInteger(data.stats.total_viewers),
|
|
820
|
+
new_followers: toInteger(data.stats.new_followers),
|
|
821
|
+
}
|
|
822
|
+
: undefined;
|
|
823
|
+
this.status = data.status;
|
|
824
|
+
this.ended_at = toNullableDate(data.ended_at);
|
|
825
|
+
this.share_url = data.share_url;
|
|
826
|
+
this.age_restricted = data.age_restricted;
|
|
827
|
+
this.subscribers_only = data.subscribers_only;
|
|
828
|
+
this.chat_enabled = data.chat_enabled;
|
|
829
|
+
this.products = toOptionalInteger(data.products);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
get isLive(): boolean {
|
|
833
|
+
return this.status === 'live';
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
static fromJSON(json: TikTokLiveRoomDetailJSON): TikTokLiveRoomDetail {
|
|
837
|
+
return new TikTokLiveRoomDetail(json);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
export interface TikTokLiveCommentJSON {
|
|
842
|
+
id?: string | null;
|
|
843
|
+
text?: string | null;
|
|
844
|
+
language?: string | null;
|
|
845
|
+
created_at?: string | null;
|
|
846
|
+
author?: TikTokLiveAuthor;
|
|
847
|
+
author_is_follower?: boolean;
|
|
848
|
+
author_is_moderator?: boolean;
|
|
849
|
+
author_is_subscriber?: boolean;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/** A comment posted in a LIVE's chat. */
|
|
853
|
+
export interface TikTokLiveComment {
|
|
854
|
+
id?: string | null;
|
|
855
|
+
text?: string | null;
|
|
856
|
+
/** ISO 639-1 code TikTok detected, or `null`. */
|
|
857
|
+
language?: string | null;
|
|
858
|
+
created_at?: Date | null;
|
|
859
|
+
author?: TikTokLiveAuthor;
|
|
860
|
+
author_is_follower?: boolean;
|
|
861
|
+
author_is_moderator?: boolean;
|
|
862
|
+
/** A paying subscriber of the streamer. */
|
|
863
|
+
author_is_subscriber?: boolean;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** One of a LIVE's top viewers, ranked by the gifts they sent. */
|
|
867
|
+
export interface TikTokLiveTopViewer {
|
|
868
|
+
rank?: number | null;
|
|
869
|
+
score?: number | null;
|
|
870
|
+
user?: TikTokLiveAuthor;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
export interface TikTokLiveRoomResultJSON {
|
|
874
|
+
room: TikTokLiveRoomDetailJSON;
|
|
875
|
+
comments?: TikTokLiveCommentJSON[];
|
|
876
|
+
pinned_comment?: TikTokLiveCommentJSON | null;
|
|
877
|
+
intro?: string | null;
|
|
878
|
+
top_viewers?: TikTokLiveTopViewer[];
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
export interface TikTokLiveRoomResult {
|
|
882
|
+
room: TikTokLiveRoomDetail;
|
|
883
|
+
/** Latest comments, newest first (TikTok keeps about the last 50). Only with `include_comments`. */
|
|
884
|
+
comments?: TikTokLiveComment[];
|
|
885
|
+
/** The comment the streamer pinned. Only with `include_comments`. */
|
|
886
|
+
pinned_comment?: TikTokLiveComment | null;
|
|
887
|
+
/** The LIVE's intro text. Only with `include_comments`. */
|
|
888
|
+
intro?: string | null;
|
|
889
|
+
/** Top viewers by gifts sent. Only with `include_comments`. */
|
|
890
|
+
top_viewers?: TikTokLiveTopViewer[];
|
|
891
|
+
/** Present when called with `include_usage: true`. */
|
|
892
|
+
usage?: UsageBlock;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function liveCommentFromJSON(json: TikTokLiveCommentJSON): TikTokLiveComment {
|
|
896
|
+
return {
|
|
897
|
+
...json,
|
|
898
|
+
created_at: toNullableDate(json.created_at),
|
|
899
|
+
author: json.author ? { ...json.author, followers: toInteger(json.author.followers) } : undefined,
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
export function tiktokLiveRoomResultFromJSON(json: TikTokLiveRoomResultJSON): TikTokLiveRoomResult {
|
|
904
|
+
const result: TikTokLiveRoomResult = { room: TikTokLiveRoomDetail.fromJSON(json.room) };
|
|
905
|
+
if (json.comments !== undefined) result.comments = (json.comments ?? []).map(liveCommentFromJSON);
|
|
906
|
+
if (json.pinned_comment !== undefined) {
|
|
907
|
+
result.pinned_comment = json.pinned_comment ? liveCommentFromJSON(json.pinned_comment) : null;
|
|
908
|
+
}
|
|
909
|
+
if (json.intro !== undefined) result.intro = json.intro;
|
|
910
|
+
if (json.top_viewers !== undefined) {
|
|
911
|
+
result.top_viewers = (json.top_viewers ?? []).map((v) => ({
|
|
912
|
+
...v,
|
|
913
|
+
rank: toInteger(v.rank),
|
|
914
|
+
score: toInteger(v.score),
|
|
915
|
+
}));
|
|
916
|
+
}
|
|
917
|
+
return result;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
export interface TikTokLiveSearchStats {
|
|
921
|
+
/** TikTok pages fetched (up to 50 rooms each). */
|
|
922
|
+
pages_fetched?: number;
|
|
923
|
+
/**
|
|
924
|
+
* Distinct rooms TikTok returned, including any past `max_results`. Billed at
|
|
925
|
+
* 1 `residential_request` per 30, minimum 1 per search.
|
|
926
|
+
*/
|
|
927
|
+
rooms_fetched?: number;
|
|
928
|
+
results_count?: number;
|
|
929
|
+
/** Whether TikTok had more rooms when the search stopped. */
|
|
930
|
+
has_more?: boolean;
|
|
931
|
+
country?: string;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
export interface TikTokLiveSearchTaskJSON {
|
|
935
|
+
task_id: string;
|
|
936
|
+
task_status: 'processing' | 'completed' | 'failed';
|
|
937
|
+
query?: string;
|
|
938
|
+
country?: string;
|
|
939
|
+
stats?: TikTokLiveSearchStats;
|
|
940
|
+
results?: TikTokLiveRoomJSON[];
|
|
941
|
+
pagination?: TikTokProfilePagination;
|
|
942
|
+
download_url?: string | null;
|
|
943
|
+
error_message?: string | null;
|
|
944
|
+
created_at?: string | null;
|
|
945
|
+
completed_at?: string | null;
|
|
946
|
+
expires_at?: string | null;
|
|
947
|
+
error?: AsyncJobError | null;
|
|
948
|
+
webhook?: AsyncJobWebhookStatus | null;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
export class TikTokLiveSearchTask {
|
|
952
|
+
task_id: string;
|
|
953
|
+
task_status: 'processing' | 'completed' | 'failed';
|
|
954
|
+
query?: string;
|
|
955
|
+
/** Country whose LIVE rooms the search returned (`us` by default). */
|
|
956
|
+
country?: string;
|
|
957
|
+
stats?: TikTokLiveSearchStats;
|
|
958
|
+
/** Rooms in TikTok's ranking. */
|
|
959
|
+
results: TikTokLiveRoom[];
|
|
960
|
+
pagination?: TikTokProfilePagination;
|
|
961
|
+
download_url?: string | null;
|
|
962
|
+
/** @deprecated Use `error`, which carries a machine-readable code. */
|
|
963
|
+
error_message?: string | null;
|
|
964
|
+
created_at?: string | null;
|
|
965
|
+
completed_at?: string | null;
|
|
966
|
+
expires_at?: string | null;
|
|
967
|
+
/** Present when `task_status === 'failed'`: error code, message and HTTP status. */
|
|
968
|
+
error: AsyncJobError | null;
|
|
969
|
+
/** Webhook delivery state, or `null` when no webhook was configured. */
|
|
970
|
+
webhook?: AsyncJobWebhookStatus | null;
|
|
971
|
+
/** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
|
|
972
|
+
usage?: UsageBlock;
|
|
973
|
+
|
|
974
|
+
constructor(data: TikTokLiveSearchTaskJSON) {
|
|
975
|
+
this.task_id = data.task_id;
|
|
976
|
+
this.task_status = data.task_status;
|
|
977
|
+
this.query = data.query;
|
|
978
|
+
this.country = data.country;
|
|
979
|
+
this.stats = data.stats
|
|
980
|
+
? {
|
|
981
|
+
...data.stats,
|
|
982
|
+
pages_fetched: toOptionalInteger(data.stats.pages_fetched),
|
|
983
|
+
rooms_fetched: toOptionalInteger(data.stats.rooms_fetched),
|
|
984
|
+
results_count: toOptionalInteger(data.stats.results_count),
|
|
985
|
+
}
|
|
986
|
+
: undefined;
|
|
987
|
+
this.results = data.results?.map(TikTokLiveRoom.fromJSON) ?? [];
|
|
988
|
+
this.pagination = normalizePagination(data.pagination);
|
|
989
|
+
this.download_url = data.download_url;
|
|
990
|
+
this.error_message = data.error_message;
|
|
991
|
+
this.created_at = data.created_at;
|
|
992
|
+
this.completed_at = data.completed_at;
|
|
993
|
+
this.expires_at = data.expires_at;
|
|
994
|
+
this.error = data.error ?? null;
|
|
995
|
+
this.webhook = data.webhook;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
static fromJSON(json: TikTokLiveSearchTaskJSON): TikTokLiveSearchTask {
|
|
999
|
+
return new TikTokLiveSearchTask(json);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
package/src/webhooks.ts
CHANGED
|
@@ -13,9 +13,11 @@ export type WebhookEventType =
|
|
|
13
13
|
| 'tiktok_profile.completed'
|
|
14
14
|
| 'tiktok_profile.failed'
|
|
15
15
|
| 'tiktok_search.completed'
|
|
16
|
-
| 'tiktok_search.failed'
|
|
16
|
+
| 'tiktok_search.failed'
|
|
17
|
+
| 'tiktok_live_search.completed'
|
|
18
|
+
| 'tiktok_live_search.failed';
|
|
17
19
|
|
|
18
|
-
/** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` event: a summary, not the
|
|
20
|
+
/** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` / `tiktok_live_search.*` event: a summary, not the items. */
|
|
19
21
|
export interface TikTokWebhookResult {
|
|
20
22
|
/** Same fields as the task's `stats` (e.g. `videos_matched`, or `results_count` / `sort_by` for searches). */
|
|
21
23
|
stats?: Record<string, unknown>;
|