vidnavigator 1.0.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/errors.d.ts CHANGED
@@ -10,6 +10,12 @@ export declare class VidNavigatorError extends Error {
10
10
  readonly error_code?: string;
11
11
  readonly error_message?: string;
12
12
  readonly details?: any;
13
+ /**
14
+ * Set on every error raised while submitting, polling, or waiting for an async job once a
15
+ * `task_id` exists. The job keeps running server-side and its result stays readable for 1 hour
16
+ * after it finishes, so keep this id to resume with `vn.<operation>.resume(task_id)`.
17
+ */
18
+ task_id?: string;
13
19
  constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
14
20
  }
15
21
  /**
@@ -73,3 +79,34 @@ export declare class SystemOverloadError extends VidNavigatorError {
73
79
  readonly retry_after_seconds?: number;
74
80
  constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any, retry_after_seconds?: number);
75
81
  }
82
+ /**
83
+ * Raised when an async job could not be submitted because the account is out of credits
84
+ * (HTTP 402, `limit_exceeded`), e.g. less than 60 seconds of transcription credit left.
85
+ * No task is created. Extends `PaymentRequiredError`.
86
+ */
87
+ export declare class InsufficientCreditsError extends PaymentRequiredError {
88
+ constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
89
+ }
90
+ /**
91
+ * Raised when an async job could not be submitted because too many jobs are already running
92
+ * for this account (HTTP 429, `too_many_active_jobs`). No task is created; retry once some
93
+ * of your running jobs finish. Extends `RateLimitExceededError`.
94
+ */
95
+ export declare class TooManyActiveJobsError extends RateLimitExceededError {
96
+ constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
97
+ }
98
+ /**
99
+ * Raised when waiting for a job exceeds `timeoutMs`. Always carries `task_id`: the job keeps
100
+ * running server-side and its result stays readable for 1 hour after it finishes, so resume it
101
+ * with `vn.<operation>.resume(err.task_id)`.
102
+ */
103
+ export declare class TaskTimeoutError extends VidNavigatorError {
104
+ constructor(message: string, task_id: string);
105
+ }
106
+ /**
107
+ * Raised by `constructWebhookEvent()` when a webhook delivery's signature is missing,
108
+ * malformed, does not match, or is older than the allowed tolerance.
109
+ */
110
+ export declare class WebhookSignatureError extends VidNavigatorError {
111
+ constructor(message: string);
112
+ }
package/dist/errors.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Custom exception classes for VidNavigator SDK.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SystemOverloadError = exports.GeoRestrictedError = exports.StorageQuotaExceededError = exports.ServerError = exports.PaymentRequiredError = exports.RateLimitExceededError = exports.NotFoundError = exports.AccessDeniedError = exports.BadRequestError = exports.AuthenticationError = exports.VidNavigatorError = void 0;
6
+ exports.WebhookSignatureError = exports.TaskTimeoutError = exports.TooManyActiveJobsError = exports.InsufficientCreditsError = exports.SystemOverloadError = exports.GeoRestrictedError = exports.StorageQuotaExceededError = exports.ServerError = exports.PaymentRequiredError = exports.RateLimitExceededError = exports.NotFoundError = exports.AccessDeniedError = exports.BadRequestError = exports.AuthenticationError = exports.VidNavigatorError = void 0;
7
7
  /**
8
8
  * Base class for all VidNavigator SDK errors.
9
9
  * Contains additional information from the API response when available.
@@ -131,3 +131,55 @@ class SystemOverloadError extends VidNavigatorError {
131
131
  }
132
132
  }
133
133
  exports.SystemOverloadError = SystemOverloadError;
134
+ /**
135
+ * Raised when an async job could not be submitted because the account is out of credits
136
+ * (HTTP 402, `limit_exceeded`), e.g. less than 60 seconds of transcription credit left.
137
+ * No task is created. Extends `PaymentRequiredError`.
138
+ */
139
+ class InsufficientCreditsError extends PaymentRequiredError {
140
+ constructor(message, status_code, error_code, error_message, details) {
141
+ super(message, status_code, error_code, error_message, details);
142
+ this.name = 'InsufficientCreditsError';
143
+ Object.setPrototypeOf(this, InsufficientCreditsError.prototype);
144
+ }
145
+ }
146
+ exports.InsufficientCreditsError = InsufficientCreditsError;
147
+ /**
148
+ * Raised when an async job could not be submitted because too many jobs are already running
149
+ * for this account (HTTP 429, `too_many_active_jobs`). No task is created; retry once some
150
+ * of your running jobs finish. Extends `RateLimitExceededError`.
151
+ */
152
+ class TooManyActiveJobsError extends RateLimitExceededError {
153
+ constructor(message, status_code, error_code, error_message, details) {
154
+ super(message, status_code, error_code, error_message, details);
155
+ this.name = 'TooManyActiveJobsError';
156
+ Object.setPrototypeOf(this, TooManyActiveJobsError.prototype);
157
+ }
158
+ }
159
+ exports.TooManyActiveJobsError = TooManyActiveJobsError;
160
+ /**
161
+ * Raised when waiting for a job exceeds `timeoutMs`. Always carries `task_id`: the job keeps
162
+ * running server-side and its result stays readable for 1 hour after it finishes, so resume it
163
+ * with `vn.<operation>.resume(err.task_id)`.
164
+ */
165
+ class TaskTimeoutError extends VidNavigatorError {
166
+ constructor(message, task_id) {
167
+ super(message);
168
+ this.name = 'TaskTimeoutError';
169
+ this.task_id = task_id;
170
+ Object.setPrototypeOf(this, TaskTimeoutError.prototype);
171
+ }
172
+ }
173
+ exports.TaskTimeoutError = TaskTimeoutError;
174
+ /**
175
+ * Raised by `constructWebhookEvent()` when a webhook delivery's signature is missing,
176
+ * malformed, does not match, or is older than the allowed tolerance.
177
+ */
178
+ class WebhookSignatureError extends VidNavigatorError {
179
+ constructor(message) {
180
+ super(message);
181
+ this.name = 'WebhookSignatureError';
182
+ Object.setPrototypeOf(this, WebhookSignatureError.prototype);
183
+ }
184
+ }
185
+ exports.WebhookSignatureError = WebhookSignatureError;
package/dist/http.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Internal: maps API error responses to SDK error classes. Not re-exported from the package.
3
+ */
4
+ import { VidNavigatorError } from './errors';
5
+ export declare function parseApiErrorPayload(data: any): {
6
+ errorCode?: string;
7
+ errorMessage?: string;
8
+ details?: any;
9
+ };
10
+ /** Map an HTTP error status + body to the matching SDK error class. */
11
+ export declare function buildApiError(status: number, data: any, fallbackMessage?: string): VidNavigatorError;
package/dist/http.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseApiErrorPayload = parseApiErrorPayload;
4
+ exports.buildApiError = buildApiError;
5
+ /**
6
+ * Internal: maps API error responses to SDK error classes. Not re-exported from the package.
7
+ */
8
+ const errors_1 = require("./errors");
9
+ function parseApiErrorPayload(data) {
10
+ const errorField = data?.error;
11
+ const errorCode = (typeof errorField === 'string' ? errorField : errorField?.code) ?? data?.error_code;
12
+ const errorMessage = data?.message ??
13
+ (typeof errorField === 'object' ? errorField?.message : undefined);
14
+ return { errorCode, errorMessage, details: data };
15
+ }
16
+ /** Map an HTTP error status + body to the matching SDK error class. */
17
+ function buildApiError(status, data, fallbackMessage) {
18
+ const { errorCode, errorMessage, details } = parseApiErrorPayload(data);
19
+ const message = `API request failed with status ${status}: ${errorMessage || fallbackMessage}`;
20
+ switch (status) {
21
+ case 400:
22
+ return new errors_1.BadRequestError(message, status, errorCode, errorMessage, details);
23
+ case 401:
24
+ return new errors_1.AuthenticationError(message, status, errorCode, errorMessage, details);
25
+ case 402:
26
+ if (errorCode === 'limit_exceeded') {
27
+ return new errors_1.InsufficientCreditsError(message, status, errorCode, errorMessage, details);
28
+ }
29
+ return new errors_1.PaymentRequiredError(message, status, errorCode, errorMessage, details);
30
+ case 403:
31
+ return new errors_1.AccessDeniedError(message, status, errorCode, errorMessage, details);
32
+ case 404:
33
+ return new errors_1.NotFoundError(message, status, errorCode, errorMessage, details);
34
+ case 413:
35
+ return new errors_1.StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
36
+ case 429:
37
+ if (errorCode === 'too_many_active_jobs') {
38
+ return new errors_1.TooManyActiveJobsError(message, status, errorCode, errorMessage, details);
39
+ }
40
+ return new errors_1.RateLimitExceededError(message, status, errorCode, errorMessage, details);
41
+ case 451:
42
+ return new errors_1.GeoRestrictedError(message, status, errorCode, errorMessage, details);
43
+ case 503:
44
+ return new errors_1.SystemOverloadError(message, status, errorCode, errorMessage, details, data?.retry_after_seconds);
45
+ default:
46
+ if (status >= 500) {
47
+ return new errors_1.ServerError(message, status, errorCode, errorMessage, details);
48
+ }
49
+ return new errors_1.VidNavigatorError(message, status, errorCode, errorMessage, details);
50
+ }
51
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
- import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionSchema, UsageBlock, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TweetStatement } from './models';
2
+ import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionSchema, UsageBlock, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TweetStatement, AsyncJob } from './models';
3
+ import { Job, JobOperation, PollOptions, RunOptions, SubmitOptions } from './jobs';
3
4
  export * from './models';
4
5
  export * from './errors';
6
+ export * from './webhooks';
7
+ export { Job } from './jobs';
8
+ export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
5
9
  /** SDK version (keep in sync with package.json) */
6
- export declare const SDK_VERSION = "1.0.5";
10
+ export declare const SDK_VERSION = "2.1.0";
7
11
  export interface SDKConfig {
8
12
  apiKey: string;
9
13
  baseURL?: string;
@@ -22,7 +26,40 @@ export type TranscribeVideoPayload = {
22
26
  transcript_text?: boolean;
23
27
  all_videos?: boolean;
24
28
  include_usage?: boolean;
29
+ } & WebhookOption;
30
+ /**
31
+ * Where to POST a notification when an async job finishes. Overrides the account-level default
32
+ * configured in Studio → API; pass an empty string to opt this job out of that default.
33
+ * Must be a publicly reachable https URL. This is a pass-through: polling always works either way.
34
+ */
35
+ export type WebhookOption = {
36
+ webhook_url?: string;
25
37
  };
38
+ /** Input for {@link VidNavigatorClient.transcribe}. A plain string is treated as `video_url`. */
39
+ export type TranscribeInput = {
40
+ video_url: string;
41
+ transcript_text?: boolean;
42
+ /** Instagram carousel posts only: transcribe every video in the post. */
43
+ all_videos?: boolean;
44
+ } & WebhookOption;
45
+ /** Input for {@link VidNavigatorClient.extractVideo}: a JSON `schema`, or a JSON/YAML `schemaFilePath`. */
46
+ export type ExtractVideoInput = ({
47
+ video_url: string;
48
+ schema: ExtractionSchema;
49
+ what_to_extract?: string;
50
+ /** Speech-to-text the audio when no platform transcript exists. Default true. */
51
+ transcribe?: boolean;
52
+ } & WebhookOption) | ({
53
+ video_url: string;
54
+ /** Path to a JSON or YAML schema file (sent as multipart form-data). */
55
+ schemaFilePath: string;
56
+ what_to_extract?: string;
57
+ transcribe?: boolean;
58
+ } & WebhookOption);
59
+ /** Input for {@link VidNavigatorClient.tweetStatement}. A plain string is treated as `tweet_id`. */
60
+ export type TweetStatementInput = {
61
+ tweet_id: string;
62
+ } & WebhookOption;
26
63
  export type TranscriptResult = {
27
64
  video_info: VideoInfo;
28
65
  transcript: TranscriptOutput;
@@ -39,6 +76,33 @@ export type TranscribeVideoCarouselResult = {
39
76
  usage?: UsageBlock;
40
77
  };
41
78
  export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVideoCarouselResult;
79
+ /** Snapshot of a transcription task. `result` has the same shape as {@link VidNavigatorClient.transcribe}'s return value. */
80
+ export type TranscribeAsyncJob = AsyncJob<TranscribeVideoResult>;
81
+ /** Snapshot of an extraction task. `result` is the extracted object, shaped like your schema. */
82
+ export type ExtractVideoAsyncJob = AsyncJob<Record<string, unknown>>;
83
+ /** Snapshot of a tweet claim analysis task. `result` is a {@link TweetStatement}. */
84
+ export type TweetStatementAsyncJob = AsyncJob<TweetStatement>;
85
+ export type TranscribeJob = Job<TranscribeAsyncJob, TranscribeVideoResult>;
86
+ /** Input that always yields a single-video result (the carousel shape needs `all_videos: true`). */
87
+ type SingleTranscribeInput = string | (TranscribeInput & {
88
+ all_videos?: false;
89
+ });
90
+ /**
91
+ * {@link JobOperation} for transcription, typed so that a plain URL (or `all_videos` left off)
92
+ * resolves to {@link TranscribeVideoSingleResult}.
93
+ */
94
+ export interface TranscribeOperation extends JobOperation<string | TranscribeInput, TranscribeAsyncJob, TranscribeVideoResult> {
95
+ (input: SingleTranscribeInput, options?: RunOptions<TranscribeAsyncJob>): Promise<TranscribeVideoSingleResult>;
96
+ (input: string | TranscribeInput, options?: RunOptions<TranscribeAsyncJob>): Promise<TranscribeVideoResult>;
97
+ submit(input: SingleTranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoSingleResult>>;
98
+ submit(input: string | TranscribeInput, options?: SubmitOptions): Promise<Job<TranscribeAsyncJob, TranscribeVideoResult>>;
99
+ }
100
+ export type ExtractVideoJob = Job<ExtractVideoAsyncJob, ExtractDataResult>;
101
+ export type TweetStatementJob = Job<TweetStatementAsyncJob, TweetStatement>;
102
+ /** `result()` resolves to the completed task with **all** pages of `videos` collected. */
103
+ export type TikTokProfileJob = Job<TikTokProfileTask, TikTokProfileTask>;
104
+ /** `result()` resolves to the completed task with **all** pages of `results` collected. */
105
+ export type TikTokSearchJob = Job<TikTokSearchTask, TikTokSearchTask>;
42
106
  export type UploadFileSuccessResult = {
43
107
  status: 'success';
44
108
  file_id: string;
@@ -127,7 +191,7 @@ export type ExtractVideoDataPayload = {
127
191
  what_to_extract?: string;
128
192
  transcribe?: boolean;
129
193
  include_usage?: boolean;
130
- };
194
+ } & WebhookOption;
131
195
  export type ExtractVideoDataMultipartPayload = {
132
196
  video_url: string;
133
197
  /** Path to a JSON or YAML schema file. The API accepts either a raw schema or a full extraction request object. */
@@ -135,7 +199,10 @@ export type ExtractVideoDataMultipartPayload = {
135
199
  what_to_extract?: string;
136
200
  transcribe?: boolean;
137
201
  include_usage?: boolean;
138
- };
202
+ } & WebhookOption;
203
+ export type TweetStatementPayload = {
204
+ tweet_id: string;
205
+ } & WebhookOption;
139
206
  export type ExtractFileDataPayload = {
140
207
  file_id: string;
141
208
  schema: ExtractionSchema;
@@ -151,7 +218,40 @@ export type ExtractFileDataMultipartPayload = {
151
218
  };
152
219
  export declare class VidNavigatorClient {
153
220
  private client;
221
+ /**
222
+ * Speech-to-text transcription of any length (Instagram, TikTok, X, Facebook, Vimeo, ...),
223
+ * built on `POST /transcribe/async`.
224
+ *
225
+ * - `await vn.transcribe(url)` submits, polls, and returns the result.
226
+ * - `await vn.transcribe.submit(url)` returns a {@link Job} handle right away.
227
+ * - `vn.transcribe.resume(task_id)` reattaches to a job you already submitted.
228
+ */
229
+ readonly transcribe: TranscribeOperation;
230
+ /**
231
+ * Structured-data extraction from a video of any length, built on `POST /extract/video/async`.
232
+ * The schema is validated when you submit. Same shapes as {@link VidNavigatorClient.transcribe}.
233
+ */
234
+ readonly extractVideo: JobOperation<ExtractVideoInput, ExtractVideoAsyncJob, ExtractDataResult>;
235
+ /**
236
+ * Structured claim analysis of an X/Twitter tweet (attached media of any length), built on
237
+ * `POST /tweet/statement/async`. Same shapes as {@link VidNavigatorClient.transcribe}.
238
+ */
239
+ readonly tweetStatement: JobOperation<string | TweetStatementInput, TweetStatementAsyncJob, TweetStatement>;
240
+ /**
241
+ * TikTok profile scrape, built on `POST /tiktok/profile`. The result is the completed task with
242
+ * every page of `videos` collected. Same shapes as {@link VidNavigatorClient.transcribe}.
243
+ */
244
+ readonly tiktokProfile: JobOperation<string | TikTokProfileScrapeRequest, TikTokProfileTask, TikTokProfileTask>;
245
+ /**
246
+ * TikTok keyword search, built on `POST /tiktok/search`. The result is the completed task with
247
+ * every page of `results` collected. Same shapes as {@link VidNavigatorClient.transcribe}.
248
+ */
249
+ readonly tiktokSearch: JobOperation<string | TikTokSearchRequest, TikTokSearchTask, TikTokSearchTask>;
154
250
  constructor(config: SDKConfig);
251
+ private defineOperation;
252
+ private submitAsyncJob;
253
+ private submitExtractVideo;
254
+ private getAsyncJob;
155
255
  private request;
156
256
  /**
157
257
  * Get a transcript for any supported video. The endpoint auto-detects the
@@ -165,7 +265,11 @@ export declare class VidNavigatorClient {
165
265
  * forwards to `getTranscript` and will be removed in a future release.
166
266
  */
167
267
  getYouTubeTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult>;
168
- transcribeVideo(payload: TranscribeVideoPayload): Promise<TranscribeVideoResult>;
268
+ /**
269
+ * Speech-to-text transcription. Blocking convenience wrapper around {@link VidNavigatorClient.transcribe}:
270
+ * submits to `POST /transcribe/async` and polls until the job finishes, so media of any length works.
271
+ */
272
+ transcribeVideo(payload: TranscribeVideoPayload, options?: PollOptions<TranscribeAsyncJob>): Promise<TranscribeVideoResult>;
169
273
  submitTikTokProfileScrape(payload: TikTokProfileScrapeRequest): Promise<TikTokProfileScrapeSubmission>;
170
274
  getTikTokProfileScrape(task_id: string, query?: {
171
275
  cursor?: string;
@@ -242,10 +346,17 @@ export declare class VidNavigatorClient {
242
346
  }>;
243
347
  analyzeVideo(payload: AnalyzeVideoPayload): Promise<AnalyzeVideoResult>;
244
348
  analyzeFile(payload: AnalyzeFilePayload): Promise<AnalyzeFileResult>;
245
- getTweetStatement(payload: {
246
- tweet_id: string;
247
- }): Promise<TweetStatement>;
248
- extractVideoData(payload: ExtractVideoDataPayload | ExtractVideoDataMultipartPayload): Promise<ExtractDataResult>;
349
+ /**
350
+ * Structured claim analysis of an X/Twitter tweet. Blocking convenience wrapper around
351
+ * {@link VidNavigatorClient.tweetStatement}: submits to `POST /tweet/statement/async` and polls.
352
+ */
353
+ getTweetStatement(payload: TweetStatementPayload, options?: RunOptions<TweetStatementAsyncJob>): Promise<TweetStatement>;
354
+ /**
355
+ * Structured-data extraction from an online video. Blocking convenience wrapper around
356
+ * {@link VidNavigatorClient.extractVideo}: submits to `POST /extract/video/async` and polls, so
357
+ * media of any length works. The result carries the extracted `data` and the video's `video_info`.
358
+ */
359
+ extractVideoData(payload: ExtractVideoDataPayload | ExtractVideoDataMultipartPayload, options?: PollOptions<ExtractVideoAsyncJob>): Promise<ExtractDataResult>;
249
360
  extractFileData(payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload): Promise<ExtractDataResult>;
250
361
  /**
251
362
  * Search YouTube for videos with AI analysis and ranking.