vidnavigator 3.0.0 → 3.0.2

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 CHANGED
@@ -563,7 +563,7 @@ for (const room of task.results) {
563
563
  - Each room has the same `id`, `url`, `author` and `stats` fields as a keyword search result, plus `started_at` (a `Date`), `stats.viewers` / `stats.total_viewers`, `hashtags` (the `#tags` of the title), `category` (the LIVE's category on TikTok, e.g. `'Gaming'`) and `game_tags`.
564
564
  - `stream_urls` holds `flv` and `hls` URLs keyed by quality (`origin`, `uhd`, `hd`, `sd`, `ld`), `default_quality`, an `audio_only` stream and `expires_at`. The URLs play while the LIVE is on. They are returned by default; pass `include_stream_urls: false` to leave them out. Not every LIVE offers HLS, so `hls` can be empty.
565
565
  - `country` defaults to `'us'`. Results keep TikTok's ranking; a keyword with no LIVE room in that country at that moment completes with zero results.
566
- - Billing: 1 `residential_request` per 30 rooms returned (`task.stats.results_count`), minimum 1 per search.
566
+ - Billing: 1 `residential_request` per 30 rooms returned (`task.stats.results_count`), minimum 1 per search and 1 per 5 TikTok pages read (`task.stats.pages_fetched`).
567
567
 
568
568
  ### 6c. TikTok LIVE room (sync)
569
569
 
@@ -907,10 +907,15 @@ const usage = await vn.getUsage();
907
907
  console.log(`Credits remaining: ${usage.credits.monthly_remaining}`);
908
908
  console.log(`Transcription hours used: ${usage.usage.transcriptionHour?.used}`);
909
909
  console.log(`Standard requests used: ${usage.usage.standardRequest?.used}`);
910
+ console.log(`Frames analyzed: ${usage.usage.frameAnalysis?.used}`);
911
+ console.log(`Scene analysis hours: ${usage.usage.sceneAnalysisHour?.used}`);
910
912
  console.log(`Storage: ${usage.storage.usedFormatted} / ${usage.storage.limitFormatted}`);
911
913
  console.log(`Channels indexed: ${usage.channelsIndexed.used} / ${usage.channelsIndexed.limit}`);
914
+ console.log(`Period ends: ${usage.billingPeriod.end?.toISOString() ?? 'no subscription period'}`);
912
915
  ```
913
916
 
917
+ `usage.usage` has one counter per meter: `standardRequest`, `residentialRequest`, `searchRequest`, `analysisRequest`, `sceneAnalysisHour`, `transcriptionHour` and `frameAnalysis`. The older `videoTranscripts`, `youtubeTranscripts`, `videoSearches`, `videoAnalyses`, `videoSceneAnalyses` and `videoUploads` are deprecated: the API no longer sends them. `usagePeriod` and `billingPeriod` have `start` and `end` as `Date`s, or `undefined` when the account has no subscription period.
918
+
914
919
  ### Per-call usage
915
920
 
916
921
  Pass `include_usage: true` to most endpoints (`getTranscript`, `transcribeVideo`, `watchVideo`, `extractVideoData`, `extractFileData`, `searchYouTube`, `searchFiles`) to receive a `usage` block describing exactly what the request cost. For background jobs (`vn.transcribe`, `vn.watch`, `vn.extractVideo`, ...), pass it in the options: `vn.transcribe(url, { include_usage: true })`, `vn.transcribe.submit(url, { include_usage: true })`, or `vn.transcribe.resume(taskId, { include_usage: true })`. The result's `usage` is filled in once the job completes. A failed job has all its charges reverted, so it has no usage.
@@ -925,7 +930,7 @@ const { usage } = await vn.getTranscript({
925
930
 
926
931
  if (usage) {
927
932
  console.log(usage.total_credits); // net credits deducted by this request
928
- console.log(usage.credits_remaining_after); // balance after the request (when provided)
933
+ console.log(usage.credits_remaining_after); // credits left after the request (undefined without a credit limit)
929
934
 
930
935
  // Every meter that fired, consolidated to one entry per service_type:
931
936
  for (const charge of usage.charges) {
@@ -939,7 +944,9 @@ if (usage) {
939
944
  }
940
945
  ```
941
946
 
942
- `service_type` is one of: `standard_request`, `residential_request`, `transcription_hour`, `frame_analysis`, `analysis_request`, `search_request`, `scene_analysis_hour`. LLM token counts (for `/extract/*` and `/youtube/search`) are nested inside the `analysis_request` charge — read them via the `analysis_tokens` accessor rather than expecting flat `total_tokens`. When a charge is waived via a cache-hit sponsorship, the entry carries `waived: true` + `credits_saved`, and the block carries a top-level `waived.credits_saved`.
947
+ `credits_remaining_after` is the number of credits left on the account (monthly + purchased) after this request's charges. It is `undefined` on plans without a credit limit, where the API leaves it out.
948
+
949
+ `service_type` is one of: `standard_request`, `residential_request`, `transcription_hour`, `frame_analysis`, `analysis_request`, `search_request`, `scene_analysis_hour`. LLM token counts (for `/extract/*` and `/youtube/search`) are nested inside the `analysis_request` charge — read them via the `analysis_tokens` accessor rather than expecting flat `total_tokens`. When a charge is waived, the entry carries `waived: true` + `credits_saved`, and the block carries a top-level `waived.credits_saved`.
943
950
 
944
951
  ---
945
952
 
@@ -1061,7 +1068,7 @@ With `include_scenes: true`, the `TweetStatement` also has `frames_analyzed`, an
1061
1068
  | `searchVideos(payload)` | **Deprecated** — forwards to `searchYouTube()` |
1062
1069
  | `searchFiles(payload)` | Semantic search across uploaded files, with optional `namespace_ids` scope |
1063
1070
 
1064
- **`searchYouTube` options:** `query` (required), `use_enhanced_search` (default `true`), `start_year` / `end_year` (only videos published in or after / in or before that year), `focus` (what comes first among the matches: `'relevance'` (default) \| `'recency'` \| `'popularity'` \| `'brevity'`), `duration` (maximum length in seconds; longer videos are left out), `max_results` (caps candidates analysed & cost; defaults to your plan ceiling), `include_usage`.
1071
+ **`searchYouTube` options:** `query` (required), `use_enhanced_search` (default `false`: the slower enhanced search runs only when you pass `true`), `start_year` / `end_year` (only videos published in or after / in or before that year), `focus` (what comes first among the matches: `'relevance'` (default) \| `'recency'` \| `'popularity'` \| `'brevity'`), `duration` (maximum length in seconds; longer videos are left out), `max_results` (caps candidates analysed & cost; defaults to your plan ceiling), `include_usage`.
1065
1072
 
1066
1073
  Results include `relevance_score`, `transcript_summary`, `people`, `places`, `key_subjects`, `query_answer`, `timestamps`, and `relevant_text`. If credits run out mid-search the API returns a partial result: `searchYouTube` surfaces it as `{ status: 'partial', error_code: 'insufficient_credits_video_search', results, usage? }` instead of throwing.
1067
1074
 
@@ -1105,7 +1112,7 @@ try {
1105
1112
  | `AccessDeniedError` | 403 | Insufficient permissions |
1106
1113
  | `NotFoundError` | 404 | Resource does not exist, or a job's `task_id` is unknown or expired (`task_not_found`) |
1107
1114
  | `ScenesNotAvailableError` | 409 | `include_scenes` was asked on an uploaded file that has no scenes to read (`scenes_not_available`). Has `scenes_status` (`'none'`, `'processing'` or `'failed'`) and, when failed, `scenes_error` |
1108
- | `StorageQuotaExceededError` | 413 | Storage quota exceeded |
1115
+ | `StorageQuotaExceededError` | 402 | The storage of the plan is full (`storage_quota_exceeded`, on upload). A `PaymentRequiredError`, from 3.0.2 |
1109
1116
  | `RateLimitExceededError` | 429 | Too many requests |
1110
1117
  | `TooManyActiveJobsError` | 429 | A job could not start: too many of your jobs are already running (`too_many_active_jobs`). Extends `RateLimitExceededError` |
1111
1118
  | `GeoRestrictedError` | 451 | Content unavailable in your region |
@@ -1146,11 +1153,20 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
1146
1153
  | `TikTokSearchTask` | TikTok keyword search task with status, results, pagination, `download_url`, `error`, `webhook`; `stats` shows the `sort_by` / `published_within` the search ran with |
1147
1154
  | `TikTokSearchResult` | Normalized TikTok keyword result, including `published_at` as a `Date` and integer counters |
1148
1155
  | `TikTokLiveSearchSubmission` | Async TikTok LIVE search submission: `task_id`, query, country, `include_stream_urls`, expiry, `webhook_url` |
1149
- | `TikTokLiveSearchTask` | TikTok LIVE search task with status, rooms, pagination, `download_url`, `error`, `webhook`; `stats.rooms_fetched` is what is billed |
1156
+ | `TikTokLiveSearchTask` | TikTok LIVE search task with status, rooms, pagination, `download_url`, `error`, `webhook`; billing follows `stats.results_count` and `stats.pages_fetched` |
1150
1157
  | `TikTokLiveRoom` | A LIVE room: author, `stats.viewers`, `hashtags`, `category`, `game_tags`, `started_at` as a `Date`, and `stream_urls` (FLV / HLS by quality, audio only) |
1151
1158
  | `TikTokLiveRoomDetail` | A `TikTokLiveRoom` from `getTikTokLiveRoom`: `status` / `isLive`, `ended_at`, `stats.new_followers`, `author.bio`, `share_url`, `chat_enabled`, `subscribers_only`, `products` |
1152
1159
  | `TweetStatement` | Structured X/Twitter claim analysis, topics, entities, tone, intent, and source text; with `include_scenes`, `frames_analyzed` and `scenes_error` |
1153
1160
 
1161
+ ## What's new in 3.0.2
1162
+
1163
+ - **`getUsage()` keeps every counter:** `usage.frameAnalysis` and `usage.sceneAnalysisHour` were dropped; they are now there with the other counters. The legacy `videoTranscripts`, `youtubeTranscripts`, `videoSearches`, `videoAnalyses`, `videoSceneAnalyses` and `videoUploads` counters, which the API no longer sends, are marked deprecated.
1164
+ - **`getUsage()` on an account without a subscription period:** the API sends `null` dates then, which became January 1, 1970. `usagePeriod.start`, `usagePeriod.end`, `billingPeriod.start` and `billingPeriod.end` are now `undefined` instead.
1165
+
1166
+ ## What's new in 3.0.1
1167
+
1168
+ - **`people`, `places` and `key_subjects` of search results can be read with `.name`.** The API sends them as lists of names (`["Sam Altman"]`), while the types promised objects, so `result.people[0].name` was `undefined`. `VideoSearchResult` and `FileSearchResult` now turn each name into `{ name }`, as the Python SDK does.
1169
+
1154
1170
  ## What's new in 3.0.0
1155
1171
 
1156
1172
  **Breaking:** the analysis methods are removed, with the API endpoints they called. Ask the same questions with extraction, `extractVideoData()` / `vn.extractVideo()` for an online video and `extractFileData()` for an uploaded file, with `what_to_extract` in plain words and/or a JSON Schema. `include_scenes` works there too, and each value comes with the moments of the video it was taken from (`evidence`).
package/dist/errors.d.ts CHANGED
@@ -62,9 +62,11 @@ export declare class ServerError extends VidNavigatorError {
62
62
  constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
63
63
  }
64
64
  /**
65
- * Raised when storage quota is exceeded (HTTP 413).
65
+ * Raised when the storage of the plan is full: HTTP 402 `storage_quota_exceeded`
66
+ * on `uploadFile` (413 is still mapped here too). A `PaymentRequiredError`, so
67
+ * code that catches that one keeps working.
66
68
  */
67
- export declare class StorageQuotaExceededError extends VidNavigatorError {
69
+ export declare class StorageQuotaExceededError extends PaymentRequiredError {
68
70
  constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
69
71
  }
70
72
  /**
package/dist/errors.js CHANGED
@@ -95,9 +95,11 @@ class ServerError extends VidNavigatorError {
95
95
  }
96
96
  exports.ServerError = ServerError;
97
97
  /**
98
- * Raised when storage quota is exceeded (HTTP 413).
98
+ * Raised when the storage of the plan is full: HTTP 402 `storage_quota_exceeded`
99
+ * on `uploadFile` (413 is still mapped here too). A `PaymentRequiredError`, so
100
+ * code that catches that one keeps working.
99
101
  */
100
- class StorageQuotaExceededError extends VidNavigatorError {
102
+ class StorageQuotaExceededError extends PaymentRequiredError {
101
103
  constructor(message, status_code, error_code, error_message, details) {
102
104
  super(message, status_code, error_code, error_message, details);
103
105
  this.name = 'StorageQuotaExceededError';
package/dist/http.js CHANGED
@@ -23,6 +23,9 @@ function buildApiError(status, data, fallbackMessage) {
23
23
  case 401:
24
24
  return new errors_1.AuthenticationError(message, status, errorCode, errorMessage, details);
25
25
  case 402:
26
+ if (errorCode === 'storage_quota_exceeded') {
27
+ return new errors_1.StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
28
+ }
26
29
  if (errorCode === 'limit_exceeded') {
27
30
  return new errors_1.InsufficientCreditsError(message, status, errorCode, errorMessage, details);
28
31
  }
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export * from './webhooks';
7
7
  export { Job } from './jobs';
8
8
  export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
9
9
  /** SDK version (keep in sync with package.json) */
10
- export declare const SDK_VERSION = "3.0.0";
10
+ export declare const SDK_VERSION = "3.0.2";
11
11
  export interface SDKConfig {
12
12
  apiKey: string;
13
13
  baseURL?: string;
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ __exportStar(require("./webhooks"), exports);
31
31
  var jobs_2 = require("./jobs");
32
32
  Object.defineProperty(exports, "Job", { enumerable: true, get: function () { return jobs_2.Job; } });
33
33
  /** SDK version (keep in sync with package.json) */
34
- exports.SDK_VERSION = '3.0.0';
34
+ exports.SDK_VERSION = '3.0.2';
35
35
  /**
36
36
  * A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
37
37
  * minutes at worst. A shorter configured axios timeout is raised to this for that call only.
@@ -1,6 +1,6 @@
1
1
  import { FileInfo, FileInfoJSON } from './FileInfo';
2
2
  import { VideoInfo, VideoInfoJSON } from './VideoInfo';
3
- /** A person or a place a search result mentions, with the context it appears in. */
3
+ /** A person or a place a search result mentions. */
4
4
  export interface NamedEntity {
5
5
  name?: string;
6
6
  context?: string;
@@ -14,18 +14,20 @@ export interface BaseSearchResult {
14
14
  transcript_summary?: string;
15
15
  }
16
16
  export interface VideoSearchResultJSON extends VideoInfoJSON, BaseSearchResult {
17
- people?: NamedEntity[];
18
- places?: NamedEntity[];
19
- key_subjects?: SearchKeySubject[];
17
+ /** Names, as the API sends them. */
18
+ people?: Array<string | NamedEntity>;
19
+ places?: Array<string | NamedEntity>;
20
+ key_subjects?: Array<string | SearchKeySubject>;
20
21
  timestamp?: number;
21
22
  relevant_text?: string;
22
23
  query_relevance?: string;
23
24
  }
24
25
  export interface FileSearchResultJSON extends FileInfoJSON, BaseSearchResult {
25
26
  file_url?: string;
26
- people?: NamedEntity[];
27
- places?: NamedEntity[];
28
- key_subjects?: SearchKeySubject[];
27
+ /** Names, as the API sends them. */
28
+ people?: Array<string | NamedEntity>;
29
+ places?: Array<string | NamedEntity>;
30
+ key_subjects?: Array<string | SearchKeySubject>;
29
31
  timestamps?: number[];
30
32
  relevant_text?: string;
31
33
  query_answer?: string;
@@ -3,6 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileSearchResult = exports.VideoSearchResult = void 0;
4
4
  const FileInfo_1 = require("./FileInfo");
5
5
  const VideoInfo_1 = require("./VideoInfo");
6
+ /**
7
+ * The API sends `people`, `places` and `key_subjects` as lists of names
8
+ * (`["Sam Altman"]`). Each name is turned into `{ name }`, so `.name` reads the
9
+ * same whatever the API sent; an entry that is already an object is kept.
10
+ */
11
+ function toNamed(values) {
12
+ if (!Array.isArray(values))
13
+ return undefined;
14
+ return values.map((value) => (typeof value === 'string' ? { name: value } : value));
15
+ }
6
16
  /**
7
17
  * Represents a single video result from a search query.
8
18
  */
@@ -11,9 +21,9 @@ class VideoSearchResult extends VideoInfo_1.VideoInfo {
11
21
  super(data);
12
22
  this.relevance_score = data.relevance_score;
13
23
  this.transcript_summary = data.transcript_summary;
14
- this.people = data.people;
15
- this.places = data.places;
16
- this.key_subjects = data.key_subjects;
24
+ this.people = toNamed(data.people);
25
+ this.places = toNamed(data.places);
26
+ this.key_subjects = toNamed(data.key_subjects);
17
27
  this.timestamp = data.timestamp;
18
28
  this.relevant_text = data.relevant_text;
19
29
  this.query_relevance = data.query_relevance;
@@ -32,9 +42,9 @@ class FileSearchResult extends FileInfo_1.FileInfo {
32
42
  this.relevance_score = data.relevance_score;
33
43
  this.transcript_summary = data.transcript_summary;
34
44
  this.file_url = data.file_url;
35
- this.people = data.people;
36
- this.places = data.places;
37
- this.key_subjects = data.key_subjects;
45
+ this.people = toNamed(data.people);
46
+ this.places = toNamed(data.places);
47
+ this.key_subjects = toNamed(data.key_subjects);
38
48
  this.timestamps = data.timestamps;
39
49
  this.relevant_text = data.relevant_text;
40
50
  this.query_answer = data.query_answer;
@@ -563,7 +563,8 @@ export interface TikTokLiveSearchStats {
563
563
  pages_fetched?: number;
564
564
  /**
565
565
  * Distinct rooms TikTok returned, including any past `max_results`. For information:
566
- * billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search).
566
+ * billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
567
+ * and `pages_fetched` (at least 1 per 5).
567
568
  */
568
569
  rooms_fetched?: number;
569
570
  results_count?: number;
@@ -28,6 +28,7 @@ export declare class UsageCharge {
28
28
  export interface UsageBlockJSON {
29
29
  charges?: UsageChargeJSON[];
30
30
  total_credits?: number;
31
+ /** Credits left on the account (monthly + purchased) after this request's charges. Absent on plans without a credit limit. */
31
32
  credits_remaining_after?: number;
32
33
  waived?: {
33
34
  credits_saved: number;
@@ -48,6 +49,10 @@ export interface UsageBlockJSON {
48
49
  export declare class UsageBlock {
49
50
  charges: UsageCharge[];
50
51
  total_credits?: number;
52
+ /**
53
+ * Credits left on the account (monthly + purchased) after this request's charges.
54
+ * `undefined` on plans without a credit limit, where the API leaves it out.
55
+ */
51
56
  credits_remaining_after?: number;
52
57
  waived?: {
53
58
  credits_saved: number;
@@ -128,13 +133,14 @@ export declare class StorageUsage {
128
133
  }
129
134
  export type PlanInterval = 'month' | 'year';
130
135
  export interface UsageDataJSON {
136
+ /** `start` and `end` are null when the account has no subscription period. */
131
137
  usage_period: {
132
- start: string;
133
- end: string;
138
+ start: string | null;
139
+ end: string | null;
134
140
  };
135
141
  billing_period: {
136
- start: string;
137
- end: string;
142
+ start: string | null;
143
+ end: string | null;
138
144
  interval: PlanInterval;
139
145
  };
140
146
  subscription: {
@@ -150,12 +156,22 @@ export interface UsageDataJSON {
150
156
  residential_request?: ActivityCountJSON;
151
157
  search_request?: ActivityCountJSON;
152
158
  analysis_request?: ActivityCountJSON;
159
+ /** Hours of video whose scenes were analyzed (`unit: 'hours'`). */
160
+ scene_analysis_hour?: ActivityCountJSON;
153
161
  transcription_hour?: ActivityCountJSON;
162
+ /** Frames analyzed by `watch` and by `include_scenes` (`unit: 'frames'`). */
163
+ frame_analysis?: ActivityCountJSON;
164
+ /** @deprecated Legacy counters below: the API no longer sends them. */
154
165
  video_scene_analyses?: ActivityCountJSON;
166
+ /** @deprecated */
155
167
  video_transcripts?: ActivityCountJSON;
168
+ /** @deprecated */
156
169
  youtube_transcripts?: ActivityCountJSON;
170
+ /** @deprecated */
157
171
  video_searches?: ActivityCountJSON;
172
+ /** @deprecated */
158
173
  video_analyses?: ActivityCountJSON;
174
+ /** @deprecated */
159
175
  video_uploads?: ActivityCountJSON;
160
176
  };
161
177
  channels_indexed: CapacityMetricJSON;
@@ -163,13 +179,15 @@ export interface UsageDataJSON {
163
179
  generated_at: string;
164
180
  }
165
181
  export declare class UsageData {
182
+ /** `start` and `end` are `undefined` when the account has no subscription period. */
166
183
  usagePeriod: {
167
- start: Date;
168
- end: Date;
184
+ start: Date | undefined;
185
+ end: Date | undefined;
169
186
  };
187
+ /** `start` and `end` are `undefined` when the account has no subscription period. */
170
188
  billingPeriod: {
171
- start: Date;
172
- end: Date;
189
+ start: Date | undefined;
190
+ end: Date | undefined;
173
191
  interval: PlanInterval;
174
192
  };
175
193
  subscription: {
@@ -185,12 +203,22 @@ export declare class UsageData {
185
203
  residentialRequest?: ActivityCount;
186
204
  searchRequest?: ActivityCount;
187
205
  analysisRequest?: ActivityCount;
206
+ /** Hours of video whose scenes were analyzed. */
207
+ sceneAnalysisHour?: ActivityCount;
188
208
  transcriptionHour?: ActivityCount;
209
+ /** Frames analyzed by `watch` and by `include_scenes`. */
210
+ frameAnalysis?: ActivityCount;
211
+ /** @deprecated Legacy counters below: the API no longer sends them, so they stay undefined. */
189
212
  videoSceneAnalyses?: ActivityCount;
213
+ /** @deprecated */
190
214
  videoTranscripts?: ActivityCount;
215
+ /** @deprecated */
191
216
  youtubeTranscripts?: ActivityCount;
217
+ /** @deprecated */
192
218
  videoSearches?: ActivityCount;
219
+ /** @deprecated */
193
220
  videoAnalyses?: ActivityCount;
221
+ /** @deprecated */
194
222
  videoUploads?: ActivityCount;
195
223
  };
196
224
  channelsIndexed: CapacityMetric;
@@ -118,16 +118,20 @@ class StorageUsage {
118
118
  }
119
119
  }
120
120
  exports.StorageUsage = StorageUsage;
121
+ /** A date of the API, or `undefined` when it sent null (never `new Date(null)`, which is 1970). */
122
+ function optionalDate(value) {
123
+ return value ? new Date(value) : undefined;
124
+ }
121
125
  class UsageData {
122
126
  constructor(data) {
123
127
  this.usagePeriod = {
124
- start: new Date(data.usage_period.start),
125
- end: new Date(data.usage_period.end),
128
+ start: optionalDate(data.usage_period?.start),
129
+ end: optionalDate(data.usage_period?.end),
126
130
  };
127
131
  this.billingPeriod = {
128
- start: new Date(data.billing_period.start),
129
- end: new Date(data.billing_period.end),
130
- interval: data.billing_period.interval,
132
+ start: optionalDate(data.billing_period?.start),
133
+ end: optionalDate(data.billing_period?.end),
134
+ interval: data.billing_period?.interval,
131
135
  };
132
136
  this.subscription = {
133
137
  planId: data.subscription.plan_id,
@@ -142,7 +146,9 @@ class UsageData {
142
146
  residentialRequest: data.usage.residential_request ? ActivityCount.fromJSON(data.usage.residential_request) : undefined,
143
147
  searchRequest: data.usage.search_request ? ActivityCount.fromJSON(data.usage.search_request) : undefined,
144
148
  analysisRequest: data.usage.analysis_request ? ActivityCount.fromJSON(data.usage.analysis_request) : undefined,
149
+ sceneAnalysisHour: data.usage.scene_analysis_hour ? ActivityCount.fromJSON(data.usage.scene_analysis_hour) : undefined,
145
150
  transcriptionHour: data.usage.transcription_hour ? ActivityCount.fromJSON(data.usage.transcription_hour) : undefined,
151
+ frameAnalysis: data.usage.frame_analysis ? ActivityCount.fromJSON(data.usage.frame_analysis) : undefined,
146
152
  videoSceneAnalyses: data.usage.video_scene_analyses ? ActivityCount.fromJSON(data.usage.video_scene_analyses) : undefined,
147
153
  videoTranscripts: data.usage.video_transcripts ? ActivityCount.fromJSON(data.usage.video_transcripts) : undefined,
148
154
  youtubeTranscripts: data.usage.youtube_transcripts ? ActivityCount.fromJSON(data.usage.youtube_transcripts) : undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidnavigator",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Official JavaScript SDK for the VidNavigator Developer API",
5
5
  "author": "VidNavigator",
6
6
  "license": "Apache-2.0",
package/src/errors.ts CHANGED
@@ -114,9 +114,11 @@ export class ServerError extends VidNavigatorError {
114
114
  }
115
115
 
116
116
  /**
117
- * Raised when storage quota is exceeded (HTTP 413).
117
+ * Raised when the storage of the plan is full: HTTP 402 `storage_quota_exceeded`
118
+ * on `uploadFile` (413 is still mapped here too). A `PaymentRequiredError`, so
119
+ * code that catches that one keeps working.
118
120
  */
119
- export class StorageQuotaExceededError extends VidNavigatorError {
121
+ export class StorageQuotaExceededError extends PaymentRequiredError {
120
122
  constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any) {
121
123
  super(message, status_code, error_code, error_message, details);
122
124
  this.name = 'StorageQuotaExceededError';
package/src/http.ts CHANGED
@@ -43,6 +43,9 @@ export function buildApiError(status: number, data: any, fallbackMessage?: strin
43
43
  case 401:
44
44
  return new AuthenticationError(message, status, errorCode, errorMessage, details);
45
45
  case 402:
46
+ if (errorCode === 'storage_quota_exceeded') {
47
+ return new StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
48
+ }
46
49
  if (errorCode === 'limit_exceeded') {
47
50
  return new InsufficientCreditsError(message, status, errorCode, errorMessage, details);
48
51
  }
package/src/index.ts CHANGED
@@ -71,7 +71,7 @@ export { Job } from './jobs';
71
71
  export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
72
72
 
73
73
  /** SDK version (keep in sync with package.json) */
74
- export const SDK_VERSION = '3.0.0';
74
+ export const SDK_VERSION = '3.0.2';
75
75
 
76
76
  /**
77
77
  * A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
@@ -1,7 +1,7 @@
1
1
  import { FileInfo, FileInfoJSON } from './FileInfo';
2
2
  import { VideoInfo, VideoInfoJSON } from './VideoInfo';
3
3
 
4
- /** A person or a place a search result mentions, with the context it appears in. */
4
+ /** A person or a place a search result mentions. */
5
5
  export interface NamedEntity {
6
6
  name?: string;
7
7
  context?: string;
@@ -17,10 +17,21 @@ export interface BaseSearchResult {
17
17
  transcript_summary?: string;
18
18
  }
19
19
 
20
+ /**
21
+ * The API sends `people`, `places` and `key_subjects` as lists of names
22
+ * (`["Sam Altman"]`). Each name is turned into `{ name }`, so `.name` reads the
23
+ * same whatever the API sent; an entry that is already an object is kept.
24
+ */
25
+ function toNamed<T extends { name?: string }>(values?: Array<T | string> | null): T[] | undefined {
26
+ if (!Array.isArray(values)) return undefined;
27
+ return values.map((value) => (typeof value === 'string' ? ({ name: value } as T) : value));
28
+ }
29
+
20
30
  export interface VideoSearchResultJSON extends VideoInfoJSON, BaseSearchResult {
21
- people?: NamedEntity[];
22
- places?: NamedEntity[];
23
- key_subjects?: SearchKeySubject[];
31
+ /** Names, as the API sends them. */
32
+ people?: Array<string | NamedEntity>;
33
+ places?: Array<string | NamedEntity>;
34
+ key_subjects?: Array<string | SearchKeySubject>;
24
35
  timestamp?: number;
25
36
  relevant_text?: string;
26
37
  query_relevance?: string;
@@ -28,9 +39,10 @@ export interface VideoSearchResultJSON extends VideoInfoJSON, BaseSearchResult {
28
39
 
29
40
  export interface FileSearchResultJSON extends FileInfoJSON, BaseSearchResult {
30
41
  file_url?: string;
31
- people?: NamedEntity[];
32
- places?: NamedEntity[];
33
- key_subjects?: SearchKeySubject[];
42
+ /** Names, as the API sends them. */
43
+ people?: Array<string | NamedEntity>;
44
+ places?: Array<string | NamedEntity>;
45
+ key_subjects?: Array<string | SearchKeySubject>;
34
46
  timestamps?: number[];
35
47
  relevant_text?: string;
36
48
  query_answer?: string;
@@ -53,9 +65,9 @@ export class VideoSearchResult extends VideoInfo implements BaseSearchResult {
53
65
  super(data);
54
66
  this.relevance_score = data.relevance_score;
55
67
  this.transcript_summary = data.transcript_summary;
56
- this.people = data.people;
57
- this.places = data.places;
58
- this.key_subjects = data.key_subjects;
68
+ this.people = toNamed<NamedEntity>(data.people);
69
+ this.places = toNamed<NamedEntity>(data.places);
70
+ this.key_subjects = toNamed<SearchKeySubject>(data.key_subjects);
59
71
  this.timestamp = data.timestamp;
60
72
  this.relevant_text = data.relevant_text;
61
73
  this.query_relevance = data.query_relevance;
@@ -85,9 +97,9 @@ export class FileSearchResult extends FileInfo implements BaseSearchResult {
85
97
  this.relevance_score = data.relevance_score;
86
98
  this.transcript_summary = data.transcript_summary;
87
99
  this.file_url = data.file_url;
88
- this.people = data.people;
89
- this.places = data.places;
90
- this.key_subjects = data.key_subjects;
100
+ this.people = toNamed<NamedEntity>(data.people);
101
+ this.places = toNamed<NamedEntity>(data.places);
102
+ this.key_subjects = toNamed<SearchKeySubject>(data.key_subjects);
91
103
  this.timestamps = data.timestamps;
92
104
  this.relevant_text = data.relevant_text;
93
105
  this.query_answer = data.query_answer;
@@ -96,4 +108,4 @@ export class FileSearchResult extends FileInfo implements BaseSearchResult {
96
108
  static fromJSON(json: FileSearchResultJSON): FileSearchResult {
97
109
  return new FileSearchResult(json);
98
110
  }
99
- }
111
+ }
@@ -923,7 +923,8 @@ export interface TikTokLiveSearchStats {
923
923
  pages_fetched?: number;
924
924
  /**
925
925
  * Distinct rooms TikTok returned, including any past `max_results`. For information:
926
- * billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search).
926
+ * billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
927
+ * and `pages_fetched` (at least 1 per 5).
927
928
  */
928
929
  rooms_fetched?: number;
929
930
  results_count?: number;
@@ -51,6 +51,7 @@ export class UsageCharge {
51
51
  export interface UsageBlockJSON {
52
52
  charges?: UsageChargeJSON[];
53
53
  total_credits?: number;
54
+ /** Credits left on the account (monthly + purchased) after this request's charges. Absent on plans without a credit limit. */
54
55
  credits_remaining_after?: number;
55
56
  waived?: { credits_saved: number };
56
57
  /** Legacy flat token fields. Some /extract/* responses may still echo these. */
@@ -70,6 +71,10 @@ export interface UsageBlockJSON {
70
71
  export class UsageBlock {
71
72
  charges: UsageCharge[];
72
73
  total_credits?: number;
74
+ /**
75
+ * Credits left on the account (monthly + purchased) after this request's charges.
76
+ * `undefined` on plans without a credit limit, where the API leaves it out.
77
+ */
73
78
  credits_remaining_after?: number;
74
79
  waived?: { credits_saved: number };
75
80
  /** Legacy flat token fields, only present on some /extract/* responses. */
@@ -231,13 +236,14 @@ export class StorageUsage {
231
236
  export type PlanInterval = 'month' | 'year';
232
237
 
233
238
  export interface UsageDataJSON {
239
+ /** `start` and `end` are null when the account has no subscription period. */
234
240
  usage_period: {
235
- start: string;
236
- end: string;
241
+ start: string | null;
242
+ end: string | null;
237
243
  };
238
244
  billing_period: {
239
- start: string;
240
- end: string;
245
+ start: string | null;
246
+ end: string | null;
241
247
  interval: PlanInterval;
242
248
  };
243
249
  subscription: {
@@ -253,12 +259,22 @@ export interface UsageDataJSON {
253
259
  residential_request?: ActivityCountJSON;
254
260
  search_request?: ActivityCountJSON;
255
261
  analysis_request?: ActivityCountJSON;
262
+ /** Hours of video whose scenes were analyzed (`unit: 'hours'`). */
263
+ scene_analysis_hour?: ActivityCountJSON;
256
264
  transcription_hour?: ActivityCountJSON;
265
+ /** Frames analyzed by `watch` and by `include_scenes` (`unit: 'frames'`). */
266
+ frame_analysis?: ActivityCountJSON;
267
+ /** @deprecated Legacy counters below: the API no longer sends them. */
257
268
  video_scene_analyses?: ActivityCountJSON;
269
+ /** @deprecated */
258
270
  video_transcripts?: ActivityCountJSON;
271
+ /** @deprecated */
259
272
  youtube_transcripts?: ActivityCountJSON;
273
+ /** @deprecated */
260
274
  video_searches?: ActivityCountJSON;
275
+ /** @deprecated */
261
276
  video_analyses?: ActivityCountJSON;
277
+ /** @deprecated */
262
278
  video_uploads?: ActivityCountJSON;
263
279
  };
264
280
  channels_indexed: CapacityMetricJSON;
@@ -266,14 +282,21 @@ export interface UsageDataJSON {
266
282
  generated_at: string;
267
283
  }
268
284
 
285
+ /** A date of the API, or `undefined` when it sent null (never `new Date(null)`, which is 1970). */
286
+ function optionalDate(value: string | null | undefined): Date | undefined {
287
+ return value ? new Date(value) : undefined;
288
+ }
289
+
269
290
  export class UsageData {
291
+ /** `start` and `end` are `undefined` when the account has no subscription period. */
270
292
  public usagePeriod: {
271
- start: Date;
272
- end: Date;
293
+ start: Date | undefined;
294
+ end: Date | undefined;
273
295
  };
296
+ /** `start` and `end` are `undefined` when the account has no subscription period. */
274
297
  public billingPeriod: {
275
- start: Date;
276
- end: Date;
298
+ start: Date | undefined;
299
+ end: Date | undefined;
277
300
  interval: PlanInterval;
278
301
  };
279
302
  public subscription: {
@@ -289,12 +312,22 @@ export class UsageData {
289
312
  residentialRequest?: ActivityCount;
290
313
  searchRequest?: ActivityCount;
291
314
  analysisRequest?: ActivityCount;
315
+ /** Hours of video whose scenes were analyzed. */
316
+ sceneAnalysisHour?: ActivityCount;
292
317
  transcriptionHour?: ActivityCount;
318
+ /** Frames analyzed by `watch` and by `include_scenes`. */
319
+ frameAnalysis?: ActivityCount;
320
+ /** @deprecated Legacy counters below: the API no longer sends them, so they stay undefined. */
293
321
  videoSceneAnalyses?: ActivityCount;
322
+ /** @deprecated */
294
323
  videoTranscripts?: ActivityCount;
324
+ /** @deprecated */
295
325
  youtubeTranscripts?: ActivityCount;
326
+ /** @deprecated */
296
327
  videoSearches?: ActivityCount;
328
+ /** @deprecated */
297
329
  videoAnalyses?: ActivityCount;
330
+ /** @deprecated */
298
331
  videoUploads?: ActivityCount;
299
332
  };
300
333
  public channelsIndexed: CapacityMetric;
@@ -303,13 +336,13 @@ export class UsageData {
303
336
 
304
337
  constructor(data: UsageDataJSON) {
305
338
  this.usagePeriod = {
306
- start: new Date(data.usage_period.start),
307
- end: new Date(data.usage_period.end),
339
+ start: optionalDate(data.usage_period?.start),
340
+ end: optionalDate(data.usage_period?.end),
308
341
  };
309
342
  this.billingPeriod = {
310
- start: new Date(data.billing_period.start),
311
- end: new Date(data.billing_period.end),
312
- interval: data.billing_period.interval,
343
+ start: optionalDate(data.billing_period?.start),
344
+ end: optionalDate(data.billing_period?.end),
345
+ interval: data.billing_period?.interval,
313
346
  };
314
347
  this.subscription = {
315
348
  planId: data.subscription.plan_id,
@@ -324,7 +357,9 @@ export class UsageData {
324
357
  residentialRequest: data.usage.residential_request ? ActivityCount.fromJSON(data.usage.residential_request) : undefined,
325
358
  searchRequest: data.usage.search_request ? ActivityCount.fromJSON(data.usage.search_request) : undefined,
326
359
  analysisRequest: data.usage.analysis_request ? ActivityCount.fromJSON(data.usage.analysis_request) : undefined,
360
+ sceneAnalysisHour: data.usage.scene_analysis_hour ? ActivityCount.fromJSON(data.usage.scene_analysis_hour) : undefined,
327
361
  transcriptionHour: data.usage.transcription_hour ? ActivityCount.fromJSON(data.usage.transcription_hour) : undefined,
362
+ frameAnalysis: data.usage.frame_analysis ? ActivityCount.fromJSON(data.usage.frame_analysis) : undefined,
328
363
  videoSceneAnalyses: data.usage.video_scene_analyses ? ActivityCount.fromJSON(data.usage.video_scene_analyses) : undefined,
329
364
  videoTranscripts: data.usage.video_transcripts ? ActivityCount.fromJSON(data.usage.video_transcripts) : undefined,
330
365
  youtubeTranscripts: data.usage.youtube_transcripts ? ActivityCount.fromJSON(data.usage.youtube_transcripts) : undefined,