vidnavigator 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +453 -106
- package/dist/errors.d.ts +37 -0
- package/dist/errors.js +53 -1
- package/dist/http.d.ts +11 -0
- package/dist/http.js +51 -0
- package/dist/index.d.ts +221 -58
- package/dist/index.js +237 -108
- package/dist/jobs.d.ts +92 -0
- package/dist/jobs.js +132 -0
- package/dist/models/AsyncJob.d.ts +92 -0
- package/dist/models/AsyncJob.js +45 -0
- package/dist/models/TikTok.d.ts +54 -0
- package/dist/models/TikTok.js +10 -0
- package/dist/models/TweetStatement.d.ts +4 -0
- package/dist/models/Usage.d.ts +71 -0
- package/dist/models/Usage.js +70 -1
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/webhooks.d.ts +63 -0
- package/dist/webhooks.js +98 -0
- package/package.json +1 -1
- package/src/errors.ts +59 -1
- package/src/http.ts +77 -0
- package/src/index.ts +520 -236
- package/src/jobs.ts +215 -0
- package/src/models/AsyncJob.ts +130 -0
- package/src/models/TikTok.ts +521 -448
- package/src/models/TweetStatement.ts +89 -84
- package/src/models/Usage.ts +127 -0
- package/src/models/index.ts +2 -1
- package/src/webhooks.ts +156 -0
|
@@ -1,84 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
| '
|
|
5
|
-
| '
|
|
6
|
-
| '
|
|
7
|
-
| '
|
|
8
|
-
| '
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
| '
|
|
14
|
-
| '
|
|
15
|
-
| '
|
|
16
|
-
| '
|
|
17
|
-
| '
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
| '
|
|
23
|
-
| '
|
|
24
|
-
| '
|
|
25
|
-
| '
|
|
26
|
-
| '
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
| '
|
|
32
|
-
| '
|
|
33
|
-
| '
|
|
34
|
-
| '
|
|
35
|
-
| '
|
|
36
|
-
| '
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
| '
|
|
42
|
-
| '
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
1
|
+
import { UsageBlock } from './Usage';
|
|
2
|
+
|
|
3
|
+
export type TweetClaimType =
|
|
4
|
+
| 'factual_claim'
|
|
5
|
+
| 'opinion'
|
|
6
|
+
| 'question'
|
|
7
|
+
| 'call_to_action'
|
|
8
|
+
| 'satire'
|
|
9
|
+
| 'news_sharing'
|
|
10
|
+
| 'personal_experience';
|
|
11
|
+
|
|
12
|
+
export type TweetIntent =
|
|
13
|
+
| 'educate'
|
|
14
|
+
| 'inform'
|
|
15
|
+
| 'analyze'
|
|
16
|
+
| 'persuade'
|
|
17
|
+
| 'entertain'
|
|
18
|
+
| 'inspire'
|
|
19
|
+
| 'challenge';
|
|
20
|
+
|
|
21
|
+
export type TweetTone =
|
|
22
|
+
| 'serious'
|
|
23
|
+
| 'humorous'
|
|
24
|
+
| 'provocative'
|
|
25
|
+
| 'neutral'
|
|
26
|
+
| 'warm'
|
|
27
|
+
| 'skeptical'
|
|
28
|
+
| 'inspirational';
|
|
29
|
+
|
|
30
|
+
export type TweetEmotion =
|
|
31
|
+
| 'curiosity'
|
|
32
|
+
| 'urgency'
|
|
33
|
+
| 'outrage'
|
|
34
|
+
| 'fear'
|
|
35
|
+
| 'hope_inspiration'
|
|
36
|
+
| 'confidence_reassurance'
|
|
37
|
+
| 'empathy_warmth'
|
|
38
|
+
| 'awe_wonder';
|
|
39
|
+
|
|
40
|
+
export type TweetAuthority =
|
|
41
|
+
| 'data_driven'
|
|
42
|
+
| 'expert_led'
|
|
43
|
+
| 'experience_based'
|
|
44
|
+
| 'speculative';
|
|
45
|
+
|
|
46
|
+
export interface TweetStatementJSON {
|
|
47
|
+
final_statement?: string;
|
|
48
|
+
statement_query?: string;
|
|
49
|
+
detailed_analysis?: string;
|
|
50
|
+
topics?: string[];
|
|
51
|
+
entities?: string[];
|
|
52
|
+
claim_type?: TweetClaimType;
|
|
53
|
+
intent?: TweetIntent;
|
|
54
|
+
tone?: TweetTone;
|
|
55
|
+
emotion?: TweetEmotion;
|
|
56
|
+
authority?: TweetAuthority;
|
|
57
|
+
tweet_text?: string | null;
|
|
58
|
+
tweet_media_summary?: string | null;
|
|
59
|
+
quoted_tweet_text?: string | null;
|
|
60
|
+
quoted_media_summary?: string | null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class TweetStatement {
|
|
64
|
+
final_statement?: string;
|
|
65
|
+
/** @deprecated Not part of the API contract and not returned by the async endpoint; always undefined. */
|
|
66
|
+
statement_query?: string;
|
|
67
|
+
detailed_analysis?: string;
|
|
68
|
+
topics?: string[];
|
|
69
|
+
entities?: string[];
|
|
70
|
+
claim_type?: TweetClaimType;
|
|
71
|
+
intent?: TweetIntent;
|
|
72
|
+
tone?: TweetTone;
|
|
73
|
+
emotion?: TweetEmotion;
|
|
74
|
+
authority?: TweetAuthority;
|
|
75
|
+
tweet_text?: string | null;
|
|
76
|
+
tweet_media_summary?: string | null;
|
|
77
|
+
quoted_tweet_text?: string | null;
|
|
78
|
+
quoted_media_summary?: string | null;
|
|
79
|
+
/** Per-call usage, populated when requested with include_usage. */
|
|
80
|
+
usage?: UsageBlock;
|
|
81
|
+
|
|
82
|
+
constructor(data: TweetStatementJSON) {
|
|
83
|
+
Object.assign(this, data);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static fromJSON(json: TweetStatementJSON): TweetStatement {
|
|
87
|
+
return new TweetStatement(json);
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/models/Usage.ts
CHANGED
|
@@ -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;
|
package/src/models/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './AnalysisResult';
|
|
2
|
+
export * from './AsyncJob';
|
|
2
3
|
export * from './Carousel';
|
|
3
4
|
export * from './CarouselVideoResult';
|
|
4
5
|
export * from './Extraction';
|
|
@@ -9,4 +10,4 @@ export * from './TikTok';
|
|
|
9
10
|
export * from './TranscriptSegment';
|
|
10
11
|
export * from './TweetStatement';
|
|
11
12
|
export * from './VideoInfo';
|
|
12
|
-
export * from './Usage';
|
|
13
|
+
export * from './Usage';
|
package/src/webhooks.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { AsyncJobError } from './models';
|
|
3
|
+
import { VidNavigatorError, WebhookSignatureError } from './errors';
|
|
4
|
+
|
|
5
|
+
/** Event types delivered to a `webhook_url` when an async job reaches a terminal state. */
|
|
6
|
+
export type WebhookEventType =
|
|
7
|
+
| 'transcribe.completed'
|
|
8
|
+
| 'transcribe.failed'
|
|
9
|
+
| 'extract_video.completed'
|
|
10
|
+
| 'extract_video.failed'
|
|
11
|
+
| 'tweet_statement.completed'
|
|
12
|
+
| 'tweet_statement.failed'
|
|
13
|
+
| 'tiktok_profile.completed'
|
|
14
|
+
| 'tiktok_profile.failed'
|
|
15
|
+
| 'tiktok_search.completed'
|
|
16
|
+
| 'tiktok_search.failed';
|
|
17
|
+
|
|
18
|
+
/** `data.result` of a `tiktok_profile.*` / `tiktok_search.*` event: a summary, not the videos. */
|
|
19
|
+
export interface TikTokWebhookResult {
|
|
20
|
+
/** Same fields as the task's `stats` (e.g. `videos_matched`, or `results_count` / `sort_by` for searches). */
|
|
21
|
+
stats?: Record<string, unknown>;
|
|
22
|
+
/** Whether the full result can be downloaded as one JSON file (`download_url` on the task). */
|
|
23
|
+
download_url_available?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The JSON body POSTed to your `webhook_url`. */
|
|
27
|
+
export interface WebhookEvent {
|
|
28
|
+
/** Event id, e.g. `evt_9f2c...`. */
|
|
29
|
+
id: string;
|
|
30
|
+
type: WebhookEventType;
|
|
31
|
+
created_at: string;
|
|
32
|
+
api_version?: string;
|
|
33
|
+
data: {
|
|
34
|
+
task_id: string;
|
|
35
|
+
task_status: 'completed' | 'failed';
|
|
36
|
+
job_type?: string;
|
|
37
|
+
check_status_url?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Raw (unparsed) result of the completed job. For transcription, extraction and tweet jobs it
|
|
40
|
+
* is the same data the job's `result()` parses. For TikTok tasks it is a summary only,
|
|
41
|
+
* {@link TikTokWebhookResult} (a scrape can hold thousands of videos); fetch the videos with
|
|
42
|
+
* `vn.tiktokProfile.resume(task_id).result()`. Omitted when `result_truncated` is true.
|
|
43
|
+
*/
|
|
44
|
+
result?: Record<string, unknown> | TikTokWebhookResult | null;
|
|
45
|
+
/** True when the result exceeded 256 KB; fetch it with `resume(task_id).result()` instead. */
|
|
46
|
+
result_truncated?: boolean;
|
|
47
|
+
error?: AsyncJobError | null;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Header names sent with every webhook delivery. */
|
|
52
|
+
export const WEBHOOK_HEADERS = {
|
|
53
|
+
/** Same as the event `type`. */
|
|
54
|
+
event: 'x-vidnavigator-event',
|
|
55
|
+
/** Delivery id, stable across retries — dedupe on this. */
|
|
56
|
+
delivery: 'x-vidnavigator-delivery',
|
|
57
|
+
/** The job's `task_id`. */
|
|
58
|
+
taskId: 'x-vidnavigator-task-id',
|
|
59
|
+
/** `t=<unix_ts>,v1=<hmac_sha256 hex>` */
|
|
60
|
+
signature: 'x-vidnavigator-signature',
|
|
61
|
+
} as const;
|
|
62
|
+
|
|
63
|
+
export interface VerifyWebhookOptions {
|
|
64
|
+
/** Reject deliveries whose timestamp is older (or further in the future) than this. Default 300 (5 minutes). Pass `0` to disable. */
|
|
65
|
+
toleranceSeconds?: number;
|
|
66
|
+
/** Override "now" as a unix timestamp in seconds (useful for tests). */
|
|
67
|
+
now?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseSignatureHeader(header: string): { timestamp: number; signatures: string[] } | null {
|
|
71
|
+
let timestamp: number | undefined;
|
|
72
|
+
const signatures: string[] = [];
|
|
73
|
+
for (const part of header.split(',')) {
|
|
74
|
+
const idx = part.indexOf('=');
|
|
75
|
+
if (idx === -1) continue;
|
|
76
|
+
const key = part.slice(0, idx).trim();
|
|
77
|
+
const value = part.slice(idx + 1).trim();
|
|
78
|
+
if (key === 't') timestamp = Number(value);
|
|
79
|
+
else if (key === 'v1' && value) signatures.push(value);
|
|
80
|
+
}
|
|
81
|
+
if (timestamp === undefined || !Number.isFinite(timestamp) || signatures.length === 0) return null;
|
|
82
|
+
return { timestamp, signatures };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function assertValidSignature(
|
|
86
|
+
payload: string | Buffer,
|
|
87
|
+
signatureHeader: string | string[] | undefined,
|
|
88
|
+
secret: string,
|
|
89
|
+
options: VerifyWebhookOptions = {}
|
|
90
|
+
): void {
|
|
91
|
+
if (!secret) throw new WebhookSignatureError('A webhook signing secret is required.');
|
|
92
|
+
const header = Array.isArray(signatureHeader) ? signatureHeader[0] : signatureHeader;
|
|
93
|
+
if (!header) throw new WebhookSignatureError('Missing X-VidNavigator-Signature header.');
|
|
94
|
+
|
|
95
|
+
const parsed = parseSignatureHeader(header);
|
|
96
|
+
if (!parsed) throw new WebhookSignatureError('Malformed X-VidNavigator-Signature header.');
|
|
97
|
+
|
|
98
|
+
const tolerance = options.toleranceSeconds ?? 300;
|
|
99
|
+
const now = options.now ?? Math.floor(Date.now() / 1000);
|
|
100
|
+
if (tolerance > 0 && Math.abs(now - parsed.timestamp) > tolerance) {
|
|
101
|
+
throw new WebhookSignatureError('Webhook timestamp is outside the allowed tolerance.');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const body = typeof payload === 'string' ? payload : payload.toString('utf8');
|
|
105
|
+
const expected = crypto
|
|
106
|
+
.createHmac('sha256', secret)
|
|
107
|
+
.update(`${parsed.timestamp}.${body}`)
|
|
108
|
+
.digest();
|
|
109
|
+
|
|
110
|
+
const matches = parsed.signatures.some((sig) => {
|
|
111
|
+
if (!/^[0-9a-f]+$/i.test(sig)) return false;
|
|
112
|
+
const received = Buffer.from(sig, 'hex');
|
|
113
|
+
return received.length === expected.length && crypto.timingSafeEqual(received, expected);
|
|
114
|
+
});
|
|
115
|
+
if (!matches) throw new WebhookSignatureError('Webhook signature does not match.');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Verify the `X-VidNavigator-Signature` header of a webhook delivery.
|
|
120
|
+
*
|
|
121
|
+
* `payload` must be the **raw** request body exactly as received (not re-serialized JSON).
|
|
122
|
+
* Returns `true` when the HMAC-SHA256 signature matches and the timestamp is within tolerance.
|
|
123
|
+
*/
|
|
124
|
+
export function verifyWebhookSignature(
|
|
125
|
+
payload: string | Buffer,
|
|
126
|
+
signatureHeader: string | string[] | undefined,
|
|
127
|
+
secret: string,
|
|
128
|
+
options?: VerifyWebhookOptions
|
|
129
|
+
): boolean {
|
|
130
|
+
try {
|
|
131
|
+
assertValidSignature(payload, signatureHeader, secret, options);
|
|
132
|
+
return true;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof WebhookSignatureError) return false;
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Verify a webhook delivery and parse its body into a {@link WebhookEvent}.
|
|
141
|
+
* Throws {@link WebhookSignatureError} when the signature is invalid or stale.
|
|
142
|
+
*/
|
|
143
|
+
export function constructWebhookEvent(
|
|
144
|
+
payload: string | Buffer,
|
|
145
|
+
signatureHeader: string | string[] | undefined,
|
|
146
|
+
secret: string,
|
|
147
|
+
options?: VerifyWebhookOptions
|
|
148
|
+
): WebhookEvent {
|
|
149
|
+
assertValidSignature(payload, signatureHeader, secret, options);
|
|
150
|
+
const body = typeof payload === 'string' ? payload : payload.toString('utf8');
|
|
151
|
+
try {
|
|
152
|
+
return JSON.parse(body) as WebhookEvent;
|
|
153
|
+
} catch {
|
|
154
|
+
throw new VidNavigatorError('Webhook payload is not valid JSON.');
|
|
155
|
+
}
|
|
156
|
+
}
|