vidnavigator 1.0.3 → 1.0.5

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,3 +1,5 @@
1
+ import { UsageBlock } from './Usage';
2
+
1
3
  export interface TikTokProfileScrapeRequest {
2
4
  profile_url: string;
3
5
  max_posts?: number;
@@ -9,6 +11,20 @@ export interface TikTokProfileScrapeRequest {
9
11
  max_likes?: number;
10
12
  }
11
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
+
12
28
  function toInteger(value: number | null | undefined): number | null | undefined {
13
29
  if (value === null || value === undefined) return value;
14
30
  return Math.trunc(value);
@@ -36,6 +52,20 @@ function normalizeFilters(filters: TikTokProfileFilters | undefined): TikTokProf
36
52
  };
37
53
  }
38
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
+
39
69
  function normalizeStats(stats: TikTokProfileStats | undefined): TikTokProfileStats | undefined {
40
70
  if (!stats) return undefined;
41
71
  return {
@@ -45,6 +75,15 @@ function normalizeStats(stats: TikTokProfileStats | undefined): TikTokProfileSta
45
75
  };
46
76
  }
47
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
+
48
87
  function normalizePagination(
49
88
  pagination: TikTokProfilePagination | undefined
50
89
  ): TikTokProfilePagination | undefined {
@@ -91,6 +130,46 @@ export class TikTokProfileScrapeSubmission {
91
130
  }
92
131
  }
93
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
+
94
173
  export interface TikTokVideoJSON {
95
174
  id?: string;
96
175
  track?: string | null;
@@ -170,6 +249,102 @@ export interface TikTokProfilePagination {
170
249
  prev_cursor?: string | null;
171
250
  }
172
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
+
173
348
  export interface TikTokProfileTaskJSON {
174
349
  task_id: string;
175
350
  task_status: 'processing' | 'completed' | 'failed';
@@ -200,6 +375,8 @@ export class TikTokProfileTask {
200
375
  created_at?: string | null;
201
376
  completed_at?: string | null;
202
377
  expires_at?: string | null;
378
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
379
+ usage?: UsageBlock;
203
380
 
204
381
  constructor(data: TikTokProfileTaskJSON) {
205
382
  this.task_id = data.task_id;
@@ -221,3 +398,57 @@ export class TikTokProfileTask {
221
398
  return new TikTokProfileTask(json);
222
399
  }
223
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,5 +1,132 @@
1
1
  export type UnlimitedOrNumber = number | 'unlimited';
2
2
 
3
+ /** Meters that can appear in a per-call {@link UsageBlock}. */
4
+ export type UsageServiceType =
5
+ | 'standard_request'
6
+ | 'residential_request'
7
+ | 'transcription_hour'
8
+ | 'analysis_request'
9
+ | 'search_request'
10
+ | 'scene_analysis_hour';
11
+
12
+ export interface UsageTokens {
13
+ prompt_tokens?: number;
14
+ completion_tokens?: number;
15
+ total_tokens?: number;
16
+ }
17
+
18
+ export interface UsageChargeJSON {
19
+ service_type: UsageServiceType;
20
+ quantity: number;
21
+ credits: number;
22
+ waived?: boolean;
23
+ credits_saved?: number;
24
+ tokens?: UsageTokens;
25
+ }
26
+
27
+ /** A single consolidated meter charge within a per-call usage block. */
28
+ export class UsageCharge {
29
+ service_type: UsageServiceType;
30
+ quantity: number;
31
+ credits: number;
32
+ waived?: boolean;
33
+ credits_saved?: number;
34
+ tokens?: UsageTokens;
35
+
36
+ constructor(data: UsageChargeJSON) {
37
+ this.service_type = data.service_type;
38
+ this.quantity = data.quantity;
39
+ this.credits = data.credits;
40
+ this.waived = data.waived;
41
+ this.credits_saved = data.credits_saved;
42
+ this.tokens = data.tokens;
43
+ }
44
+
45
+ static fromJSON(json: UsageChargeJSON): UsageCharge {
46
+ return new UsageCharge(json);
47
+ }
48
+ }
49
+
50
+ export interface UsageBlockJSON {
51
+ charges?: UsageChargeJSON[];
52
+ total_credits?: number;
53
+ credits_remaining_after?: number;
54
+ waived?: { credits_saved: number };
55
+ /** Legacy flat token fields. Some /extract/* responses may still echo these. */
56
+ prompt_tokens?: number;
57
+ completion_tokens?: number;
58
+ total_tokens?: number;
59
+ }
60
+
61
+ /**
62
+ * Per-call usage disclosure returned when a request is made with `include_usage=true`.
63
+ * Lists every meter charged during the request plus the credits actually deducted.
64
+ *
65
+ * LLM token counts live nested inside the `analysis_request` charge; use the
66
+ * {@link UsageBlock.analysis_tokens} accessor to read them (it falls back to the
67
+ * legacy flat token fields when present).
68
+ */
69
+ export class UsageBlock {
70
+ charges: UsageCharge[];
71
+ total_credits?: number;
72
+ credits_remaining_after?: number;
73
+ waived?: { credits_saved: number };
74
+ /** Legacy flat token fields, only present on some /extract/* responses. */
75
+ prompt_tokens?: number;
76
+ completion_tokens?: number;
77
+ total_tokens?: number;
78
+
79
+ constructor(data: UsageBlockJSON) {
80
+ this.charges = (data.charges ?? []).map(UsageCharge.fromJSON);
81
+ this.total_credits = data.total_credits;
82
+ this.credits_remaining_after = data.credits_remaining_after;
83
+ this.waived = data.waived;
84
+ this.prompt_tokens = data.prompt_tokens;
85
+ this.completion_tokens = data.completion_tokens;
86
+ this.total_tokens = data.total_tokens;
87
+ }
88
+
89
+ /** Return the consolidated charge entry for a given meter, if present. */
90
+ charge_for(service_type: UsageServiceType): UsageCharge | undefined {
91
+ return this.charges.find((c) => c.service_type === service_type);
92
+ }
93
+
94
+ /** camelCase alias for {@link UsageBlock.charge_for}. */
95
+ chargeFor(service_type: UsageServiceType): UsageCharge | undefined {
96
+ return this.charge_for(service_type);
97
+ }
98
+
99
+ /**
100
+ * LLM token tally for this request. Reads the `tokens` object from the
101
+ * `analysis_request` charge, falling back to legacy flat token fields.
102
+ */
103
+ get analysis_tokens(): UsageTokens | undefined {
104
+ const analysis = this.charge_for('analysis_request');
105
+ if (analysis?.tokens) return analysis.tokens;
106
+ if (
107
+ this.prompt_tokens !== undefined ||
108
+ this.completion_tokens !== undefined ||
109
+ this.total_tokens !== undefined
110
+ ) {
111
+ return {
112
+ prompt_tokens: this.prompt_tokens,
113
+ completion_tokens: this.completion_tokens,
114
+ total_tokens: this.total_tokens,
115
+ };
116
+ }
117
+ return undefined;
118
+ }
119
+
120
+ /** camelCase alias for {@link UsageBlock.analysis_tokens}. */
121
+ get analysisTokens(): UsageTokens | undefined {
122
+ return this.analysis_tokens;
123
+ }
124
+
125
+ static fromJSON(json: UsageBlockJSON): UsageBlock {
126
+ return new UsageBlock(json);
127
+ }
128
+ }
129
+
3
130
  export interface CreditsInfoJSON {
4
131
  monthly_total: UnlimitedOrNumber;
5
132
  monthly_remaining: UnlimitedOrNumber;