@supadata/js 1.1.2 → 1.2.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 CHANGED
@@ -15,14 +15,18 @@ npm install @supadata/js
15
15
 
16
16
  ## Usage
17
17
 
18
+ ### Initialization
19
+
18
20
  ```typescript
19
21
  import {
20
22
  Crawl,
21
23
  CrawlJob,
24
+ JobResult,
22
25
  Map,
23
26
  Scrape,
24
27
  Supadata,
25
28
  Transcript,
29
+ TranscriptOrJobId,
26
30
  YoutubeChannel,
27
31
  YoutubePlaylist,
28
32
  YoutubeVideo,
@@ -32,7 +36,44 @@ import {
32
36
  const supadata = new Supadata({
33
37
  apiKey: 'YOUR_API_KEY',
34
38
  });
39
+ ```
40
+
41
+ ### Transcripts
42
+
43
+ ```typescript
44
+ // Get transcript from any supported platform (YouTube, TikTok, Twitter) or file
45
+ const transcriptResult = await supadata.transcript({
46
+ url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
47
+ lang: 'en', // optional
48
+ text: true, // optional: return plain text instead of timestamped chunks
49
+ mode: 'auto', // optional: 'native', 'auto', or 'generate'
50
+ });
51
+
52
+ // Check if we got a transcript directly or a job ID for async processing
53
+ if ('jobId' in transcriptResult) {
54
+ // For large files, we get a job ID and need to poll for results
55
+ console.log(`Started transcript job: ${transcriptResult.jobId}`);
56
+
57
+ // Poll for job status
58
+ const jobResult = await supadata.transcript.getJobStatus(
59
+ transcriptResult.jobId
60
+ );
61
+ if (jobResult.status === 'completed') {
62
+ console.log('Transcript:', jobResult.result);
63
+ } else if (jobResult.status === 'failed') {
64
+ console.error('Transcript failed:', jobResult.error);
65
+ } else {
66
+ console.log('Job status:', jobResult.status); // 'queued' or 'active'
67
+ }
68
+ } else {
69
+ // For smaller files, we get the transcript directly
70
+ console.log('Transcript:', transcriptResult);
71
+ }
72
+ ```
73
+
74
+ ### YouTube
35
75
 
76
+ ```typescript
36
77
  // Get YouTube transcript
37
78
  const transcript: Transcript = await supadata.youtube.transcript({
38
79
  url: 'https://youtu.be/dQw4w9WgXcQ',
@@ -99,7 +140,11 @@ if (batchResults.status === 'completed') {
99
140
  } else {
100
141
  console.log('Batch job status:', batchResults.status);
101
142
  }
143
+ ```
102
144
 
145
+ ### Web
146
+
147
+ ```typescript
103
148
  // Scrape web content
104
149
  const webContent: Scrape = await supadata.web.scrape('https://supadata.ai');
105
150
 
@@ -107,7 +152,7 @@ const webContent: Scrape = await supadata.web.scrape('https://supadata.ai');
107
152
  const siteMap: Map = await supadata.web.map('https://supadata.ai');
108
153
 
109
154
  // Crawl website
110
- const crawl: Crawl = await supadata.web.crawl({
155
+ const crawl: JobId = await supadata.web.crawl({
111
156
  url: 'https://supadata.ai',
112
157
  limit: 10,
113
158
  });
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var r=class extends Error{error;details;documentationUrl;constructor(e){super(e.message||"An unexpected error occurred"),this.error=e.error||"internal-error",this.details=e.details||"An unexpected error occurred",this.documentationUrl=e.documentationUrl||"",this.name="SupadataError";}};var o=class{config;constructor(e){this.config=e;}async fetch(e,t={},i="GET"){let s=`${this.config.baseUrl||"https://api.supadata.ai/v1"}${e.startsWith("/")?e:`/${e}`}`;if(i==="GET"&&Object.keys(t).length>0){let u=new URLSearchParams;Object.entries(t).forEach(([a,b])=>{b!=null&&u.append(a,String(b));}),s+=`?${u.toString()}`;}return this.fetchUrl(s,i,t)}async fetchUrl(e,t="GET",i){let n={method:t,headers:{"x-api-key":this.config.apiKey,"Content-Type":"application/json"}};t==="POST"&&i&&(n.body=JSON.stringify(i));let s=await fetch(e,n),u=s.headers.get("content-type");if(!s.ok)if(u?.includes("application/json")){let a=await s.json();throw new r(a)}else throw new r({error:"internal-error",message:"Unexpected error response format",details:await s.text()});try{if(!u?.includes("application/json"))throw new r({error:"internal-error",message:"Invalid response format",details:"Expected JSON response but received different content type"});return await s.json()}catch(a){throw new r({error:"internal-error",message:"Failed to parse response",details:a instanceof Error?a.message:"Unknown error"})}}};var d=class extends o{transcript=Object.assign(async e=>this.fetch("/youtube/transcript",e),{batch:async e=>(this.validateBatchLimit(e),this.fetch("/youtube/transcript/batch",e,"POST"))});video=Object.assign(async e=>this.fetch("/youtube/video",e),{batch:async e=>(this.validateBatchLimit(e),this.fetch("/youtube/video/batch",e,"POST"))});channel=Object.assign(async e=>this.fetch("/youtube/channel",e),{videos:async e=>(this.validateLimit(e),this.fetch("/youtube/channel/videos",e))});playlist=Object.assign(async e=>this.fetch("/youtube/playlist",e),{videos:async e=>(this.validateLimit(e),this.fetch("/youtube/playlist/videos",e))});batch={getBatchResults:async e=>{if(!e)throw new r({error:"invalid-request",message:"Missing jobId",details:"The jobId parameter is required to get batch results."});return this.fetch(`/youtube/batch/${e}`)}};translate=async e=>this.fetch("/youtube/transcript/translate",e);validateLimit(e){if(e.limit!=null&&e.limit!=null&&(e.limit<1||e.limit>5e3))throw new r({error:"invalid-request",message:"Invalid limit.",details:"The limit must be between 1 and 5000."})}validateBatchLimit(e){if(e.limit!=null&&e.limit!=null&&(e.limit<1||e.limit>5e3))throw new r({error:"invalid-request",message:"Invalid limit for batch operation.",details:"The limit must be between 1 and 5000."})}};var p=class extends o{async scrape(e){return this.fetch("/web/scrape",{url:e})}async map(e){return this.fetch("/web/map",{url:e})}async crawl(e){return this.fetch("/web/crawl",e,"POST")}async getCrawlResults(e){let t,i=[],n;do t=await(n?this.fetchUrl(n):this.fetch(`/web/crawl/${e}`)),t.pages&&(i=[...i,...t.pages]),n=t.next;while(n);return t}};var h=class{youtube;web;constructor(e){this.youtube=new d(e),this.web=new p(e);}};
2
- exports.BaseClient=o;exports.Supadata=h;exports.SupadataError=r;exports.WebService=p;exports.YouTubeService=d;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var e=class extends Error{error;details;documentationUrl;constructor(t){super(t.message||"An unexpected error occurred"),this.error=t.error||"internal-error",this.details=t.details||"An unexpected error occurred",this.documentationUrl=t.documentationUrl||"",this.name="SupadataError";}};var h={name:"@supadata/js",version:"1.2.0",description:"TypeScript / JavaScript SDK for Supadata API",homepage:"https://supadata.ai",repository:"https://github.com/supadata-ai/js",main:"./dist/index.cjs",module:"./dist/index.mjs",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.mjs",require:"./dist/index.cjs",default:"./dist/index.mjs"}},scripts:{dev:"tsup --watch",build:"tsup",test:"node --experimental-vm-modules node_modules/jest/bin/jest.js",prepare:"npm run build",format:'prettier --write "src/**/*.{js,ts}"',"format:check":'prettier --check "src/**/*.{js,ts}"'},files:["dist","README.md"],keywords:["supadata","api","sdk","typescript","youtube","transcript","web scraping"],author:"Supadata AI",license:"MIT",devDependencies:{"@types/jest":"^29.5.14","@types/node":"^22.10.10",jest:"^29.7.0","jest-fetch-mock":"^3.0.3",prettier:"^3.4.2","ts-jest":"^29.2.5",typescript:"^5.7.3",tsup:"^8.3.6"}};var y=`supadata-js/${h.version}`,n=class{config;constructor(t){this.config=t;}async fetch(t,r={},s="GET"){let a=`${this.config.baseUrl||"https://api.supadata.ai/v1"}${t.startsWith("/")?t:`/${t}`}`;if(s==="GET"&&Object.keys(r).length>0){let u=new URLSearchParams;Object.entries(r).forEach(([o,m])=>{m!=null&&u.append(o,String(m));}),a+=`?${u.toString()}`;}return this.fetchUrl(a,s,r)}async fetchUrl(t,r="GET",s){let i={method:r,headers:{"x-api-key":this.config.apiKey,"Content-Type":"application/json","User-Agent":y}};r==="POST"&&s&&(i.body=JSON.stringify(s));let a=await fetch(t,i),u=a.headers.get("content-type");if(!a.ok)if(u?.includes("application/json")){let o=await a.json();throw new e(o)}else throw new e({error:"internal-error",message:"Unexpected error response format",details:await a.text()});try{if(!u?.includes("application/json"))throw new e({error:"internal-error",message:"Invalid response format",details:"Expected JSON response but received different content type"});return await a.json()}catch(o){throw new e({error:"internal-error",message:"Failed to parse response",details:o instanceof Error?o.message:"Unknown error"})}}};var p=class extends n{transcript=Object.assign(async t=>this.fetch("/youtube/transcript",t),{batch:async t=>(this.validateBatchLimit(t),this.fetch("/youtube/transcript/batch",t,"POST"))});video=Object.assign(async t=>this.fetch("/youtube/video",t),{batch:async t=>(this.validateBatchLimit(t),this.fetch("/youtube/video/batch",t,"POST"))});channel=Object.assign(async t=>this.fetch("/youtube/channel",t),{videos:async t=>(this.validateLimit(t),this.fetch("/youtube/channel/videos",t))});playlist=Object.assign(async t=>this.fetch("/youtube/playlist",t),{videos:async t=>(this.validateLimit(t),this.fetch("/youtube/playlist/videos",t))});batch={getBatchResults:async t=>{if(!t)throw new e({error:"invalid-request",message:"Missing jobId",details:"The jobId parameter is required to get batch results."});return this.fetch(`/youtube/batch/${t}`)}};translate=async t=>this.fetch("/youtube/transcript/translate",t);validateLimit(t){if(t.limit!=null&&t.limit!=null&&(t.limit<1||t.limit>5e3))throw new e({error:"invalid-request",message:"Invalid limit.",details:"The limit must be between 1 and 5000."})}validateBatchLimit(t){if(t.limit!=null&&t.limit!=null&&(t.limit<1||t.limit>5e3))throw new e({error:"invalid-request",message:"Invalid limit for batch operation.",details:"The limit must be between 1 and 5000."})}};var b=class extends n{async scrape(t){return this.fetch("/web/scrape",{url:t})}async map(t){return this.fetch("/web/map",{url:t})}async crawl(t){return this.fetch("/web/crawl",t,"POST")}async getCrawlResults(t){let r,s=[],i;do r=await(i?this.fetchUrl(i):this.fetch(`/web/crawl/${t}`)),r.pages&&(s=[...s,...r.pages]),i=r.next;while(i);return r}};var d=class extends n{get=async t=>this.fetch("/transcript",t);getJobStatus=async t=>{if(!t)throw new e({error:"invalid-request",message:"Missing jobId",details:"The jobId parameter is required to get transcript job status."});return this.fetch(`/transcript/${t}`)}};var g=class{youtube;web;_transcriptService;constructor(t){this.youtube=new p(t),this.web=new b(t),this._transcriptService=new d(t);}transcript=Object.assign(async t=>this._transcriptService.get(t),{getJobStatus:t=>this._transcriptService.getJobStatus(t)})};
2
+ exports.BaseClient=n;exports.Supadata=g;exports.SupadataError=e;exports.TranscriptService=d;exports.WebService=b;exports.YouTubeService=p;//# sourceMappingURL=index.cjs.map
3
3
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/client.ts","../src/services/youtube.ts","../src/services/web.ts","../src/index.ts"],"names":["SupadataError","error","BaseClient","config","endpoint","params","method","url","queryParams","key","value","body","options","response","contentType","errorData","YouTubeService","jobId","WebService","request","pages","nextUrl","Supadata"],"mappings":"aAoDO,IAAMA,CAAN,CAAA,cAA4B,KAAM,CACvC,KAQA,CAAA,OAAA,CACA,gBAEA,CAAA,WAAA,CAAYC,CAKT,CAAA,CACD,KAAMA,CAAAA,CAAAA,CAAM,SAAW,8BAA8B,CAAA,CACrD,IAAK,CAAA,KAAA,CAAQA,CAAM,CAAA,KAAA,EAAS,gBAC5B,CAAA,IAAA,CAAK,QAAUA,CAAM,CAAA,OAAA,EAAW,8BAChC,CAAA,IAAA,CAAK,gBAAmBA,CAAAA,CAAAA,CAAM,gBAAoB,EAAA,EAAA,CAClD,KAAK,IAAO,CAAA,gBACd,CACF,EC1EaC,IAAAA,CAAAA,CAAN,KAAiB,CACZ,OAEV,WAAYC,CAAAA,CAAAA,CAAwB,CAClC,IAAA,CAAK,MAASA,CAAAA,EAChB,CAEA,MAAgB,MACdC,CACAC,CAAAA,CAAAA,CAA8B,EAAC,CAC/BC,CAAyB,CAAA,KAAA,CACb,CAEZ,IAAIC,EAAM,CADM,EAAA,IAAA,CAAK,MAAO,CAAA,OAAA,EAAW,4BACnB,CAAA,EAClBH,CAAS,CAAA,UAAA,CAAW,GAAG,CAAIA,CAAAA,CAAAA,CAAW,CAAIA,CAAAA,EAAAA,CAAQ,CACpD,CAAA,CAAA,CAAA,CAEA,GAAIE,CAAAA,GAAW,KAAS,EAAA,MAAA,CAAO,IAAKD,CAAAA,CAAM,CAAE,CAAA,MAAA,CAAS,CAAG,CAAA,CACtD,IAAMG,CAAc,CAAA,IAAI,eACxB,CAAA,MAAA,CAAO,OAAQH,CAAAA,CAAM,CAAE,C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zC,OAAO,IAAK,CAAA,KAAA,CAAc,aAAe,CAAA,CAAE,GAAAA,CAAAA,CAAI,CAAC,CAClD,CAQA,MAAM,GAAA,CAAIA,CAA+B,CAAA,CACvC,OAAO,IAAA,CAAK,KAAe,CAAA,UAAA,CAAY,CAAE,GAAAA,CAAAA,CAAI,CAAC,CAChD,CAUA,MAAM,KAAMY,CAAAA,CAAAA,CAAuC,CACjD,OAAO,IAAA,CAAK,KAAa,CAAA,YAAA,CAAcA,CAAS,CAAA,MAAM,CACxD,CASA,MAAM,eAAA,CAAgBF,CAAkC,CAAA,CACtD,IAAIJ,CAAAA,CACAO,CAAkB,CAAA,GAClBC,CAEJ,CAAA,GACER,CAAW,CAAA,MAAOQ,CACd,CAAA,IAAA,CAAK,QAAmBA,CAAAA,CAAO,EAC/B,IAAK,CAAA,KAAA,CAAgB,CAAcJ,WAAAA,EAAAA,CAAK,CAAE,CAAA,CAAA,CAAA,CAE1CJ,CAAS,CAAA,KAAA,GACXO,EAAQ,CAAC,GAAGA,CAAO,CAAA,GAAGP,CAAS,CAAA,KAAK,CAEtCQ,CAAAA,CAAAA,CAAAA,CAAUR,EAAS,IACZQ,CAAAA,MAAAA,CAAAA,EAET,OAAOR,CACT,CACF,ECpDaS,IAAAA,CAAAA,CAAN,KAAe,CACX,OAAA,CACA,GAET,CAAA,WAAA,CAAYnB,CAAwB,CAAA,CAClC,IAAK,CAAA,OAAA,CAAU,IAAIa,CAAeb,CAAAA,CAAM,CACxC,CAAA,IAAA,CAAK,GAAM,CAAA,IAAIe,CAAWf,CAAAA,CAAM,EAClC,CACF","file":"index.cjs","sourcesContent":["export interface TranscriptChunk {\n text: string;\n offset: number;\n duration: number;\n lang: string;\n}\n\nexport interface Transcript {\n content: TranscriptChunk[] | string;\n lang: string;\n availableLangs: string[];\n}\n\nexport interface TranslatedTranscript {\n content: TranscriptChunk[] | string;\n lang: string;\n}\n\nexport interface Scrape {\n url: string;\n content: string;\n name: string;\n description: string;\n ogUrl: string;\n countCharacters: number;\n urls: string[];\n}\n\nexport interface SiteMap {\n urls: string[];\n}\n\nexport interface CrawlRequest {\n url: string;\n limit?: number;\n}\n\nexport interface Crawl {\n jobId: string;\n}\n\nexport interface CrawlJob {\n status: 'scraping' | 'completed' | 'failed' | 'cancelled';\n pages?: Scrape[];\n next?: string;\n}\n\nexport interface SupadataConfig {\n apiKey: string;\n baseUrl?: string;\n}\n\nexport class SupadataError extends Error {\n error:\n | 'invalid-request'\n | 'internal-error'\n | 'transcript-unavailable'\n | 'not-found'\n | 'unauthorized'\n | 'upgrade-required'\n | 'limit-exceeded';\n details: string;\n documentationUrl: string;\n\n constructor(error: {\n error: SupadataError['error'];\n message?: string;\n details?: string;\n documentationUrl?: string;\n }) {\n super(error.message || 'An unexpected error occurred');\n this.error = error.error || 'internal-error';\n this.details = error.details || 'An unexpected error occurred';\n this.documentationUrl = error.documentationUrl || '';\n this.name = 'SupadataError';\n }\n}\n\nexport interface YoutubeVideo {\n id: string;\n title: string;\n description: string;\n duration: number;\n channel: {\n id: string;\n name: string;\n };\n tags: string[];\n thumbnail: string;\n uploadDate: string;\n viewCount: number;\n likeCount: number;\n transcriptLanguages: string[];\n}\n\nexport interface YoutubeChannel {\n id: string;\n name: string;\n handle: string;\n description: string;\n subscriberCount: number;\n videoCount: number;\n thumbnail: string;\n banner: string;\n}\n\nexport interface YoutubePlaylist {\n id: string;\n title: string;\n videoCount: number;\n viewCount: number;\n lastUpdated: string;\n description: string;\n thumbnail: string;\n}\n\nexport interface YoutubeBatchSource {\n videoIds?: string[];\n playlistId?: string;\n channelId?: string;\n limit?: number;\n}\n\nexport interface YoutubeTranscriptBatchRequest extends YoutubeBatchSource {\n lang?: string;\n text?: boolean;\n}\n\nexport interface YoutubeVideoBatchRequest extends YoutubeBatchSource {}\n\nexport interface YoutubeBatchJob {\n jobId: string;\n}\n\nexport type YoutubeBatchJobStatus =\n | 'queued'\n | 'active'\n | 'completed'\n | 'failed';\n\nexport interface YoutubeBatchResultItem {\n videoId: string;\n transcript?: Transcript;\n video?: YoutubeVideo;\n errorCode?: string;\n}\n\nexport interface YoutubeBatchStats {\n total: number;\n succeeded: number;\n failed: number;\n}\n\nexport interface YoutubeBatchResults {\n status: YoutubeBatchJobStatus;\n results?: YoutubeBatchResultItem[];\n stats?: YoutubeBatchStats;\n completedAt?: string;\n}\n","import { SupadataConfig, SupadataError } from './types.js';\n\nexport class BaseClient {\n protected config: SupadataConfig;\n\n constructor(config: SupadataConfig) {\n this.config = config;\n }\n\n protected async fetch<T>(\n endpoint: string,\n params: Record<string, any> = {},\n method: 'GET' | 'POST' = 'GET'\n ): Promise<T> {\n const baseUrl = this.config.baseUrl || 'https://api.supadata.ai/v1';\n let url = `${baseUrl}${\n endpoint.startsWith('/') ? endpoint : `/${endpoint}`\n }`;\n\n if (method === 'GET' && Object.keys(params).length > 0) {\n const queryParams = new URLSearchParams();\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n queryParams.append(key, String(value));\n }\n });\n url += `?${queryParams.toString()}`;\n }\n\n return this.fetchUrl<T>(url, method, params);\n }\n\n protected async fetchUrl<T>(\n url: string,\n method: 'GET' | 'POST' = 'GET',\n body?: Record<string, any>\n ): Promise<T> {\n const options: RequestInit = {\n method,\n headers: {\n 'x-api-key': this.config.apiKey,\n 'Content-Type': 'application/json',\n },\n };\n\n if (method === 'POST' && body) {\n options.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, options);\n\n const contentType = response.headers.get('content-type');\n\n if (!response.ok) {\n // Handle standard API errors\n if (contentType?.includes('application/json')) {\n const errorData = await response.json();\n throw new SupadataError(errorData);\n } else {\n // Fallback for unexpected non-JSON errors\n throw new SupadataError({\n error: 'internal-error',\n message: 'Unexpected error response format',\n details: await response.text(),\n });\n }\n }\n\n try {\n if (!contentType?.includes('application/json')) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Invalid response format',\n details: 'Expected JSON response but received different content type',\n });\n }\n\n return (await response.json()) as T;\n } catch (error) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Failed to parse response',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport {\n SupadataError,\n Transcript,\n TranslatedTranscript,\n YoutubeBatchJob,\n YoutubeBatchResults,\n YoutubeChannel,\n YoutubePlaylist,\n YoutubeTranscriptBatchRequest,\n YoutubeVideo,\n YoutubeVideoBatchRequest,\n} from '../types.js';\n\n/**\n * Ensures exactly one property from the specified keys is provided.\n * @example\n * // Valid: { url: \"...\" } or { videoId: \"...\" }\n * // Invalid: {} or { url: \"...\", videoId: \"...\" }\n */\ntype ExactlyOne<T, Keys extends keyof T> = {\n [K in Keys]: { [P in K]-?: T[P] } & { [P in Exclude<Keys, K>]?: never };\n}[Keys] &\n Omit<T, Keys>;\n\nexport type TranscriptParams = {\n lang?: string;\n text?: boolean;\n} & ExactlyOne<{ videoId: string; url: string }, 'videoId' | 'url'>;\n\nexport interface TranslateParams extends Omit<TranscriptParams, 'lang'> {\n lang: string;\n}\n\nexport interface ResourceParams {\n id: string;\n}\n\nexport interface ChannelVideosParams extends ResourceParams {\n limit?: number;\n type?: 'video' | 'short' | 'live' | 'all';\n}\n\nexport interface PlaylistVideosParams extends ResourceParams {\n limit?: number;\n}\n\nexport interface VideoIds {\n videoIds: string[];\n shortIds: string[];\n liveIds: string[];\n}\n\nexport class YouTubeService extends BaseClient {\n /**\n * Handles YouTube Transcript operations.\n */\n transcript = Object.assign(\n /**\n * Fetches a transcript for a YouTube video.\n * @param params - Parameters for fetching the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The language code for the transcript (optional)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a Transcript object\n */\n async (params: TranscriptParams): Promise<Transcript> => {\n return this.fetch<Transcript>('/youtube/transcript', params);\n },\n {\n /**\n * Batch fetches transcripts for multiple YouTube videos.\n * @param params - Parameters for the transcript batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch transcripts for\n * @param params.lang - The language code for the transcripts (optional)\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeTranscriptBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/transcript/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube video operations.\n */\n video = Object.assign(\n /**\n * Fetches a YouTube video based on the provided parameters.\n * @param params - The parameters required to fetch the YouTube video\n * @param params.id - The YouTube video ID\n * @returns A promise that resolves to a YoutubeVideo object\n */\n async (params: ResourceParams): Promise<YoutubeVideo> => {\n return this.fetch<YoutubeVideo>('/youtube/video', params);\n },\n {\n /**\n * Batch fetches metadata for multiple YouTube videos.\n * @param params - Parameters for the video metadata batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch metadata for\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeVideoBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/video/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube channel operations.\n */\n channel = Object.assign(\n /**\n * Fetches YouTube channel information.\n * @param params - The parameters required to fetch the YouTube channel information\n * @param params.id - The YouTube channel ID\n * @returns A promise that resolves to a YoutubeChannel object containing the channel information\n */\n async (params: ResourceParams): Promise<YoutubeChannel> => {\n return this.fetch<YoutubeChannel>('/youtube/channel', params);\n },\n {\n /**\n * Fetches the videos of a YouTube channel.\n * @param params - The parameters required to fetch the YouTube channel videos\n * @param params.id - The YouTube channel ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @param params.type - The type of videos to fetch ('video', 'short', 'live', or 'all', default: 'video')\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: ChannelVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/channel/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube playlist operations.\n */\n playlist = Object.assign(\n /**\n * Fetches a YouTube playlist.\n * @param params - The parameters required to fetch the playlist\n * @param params.id - The YouTube playlist ID\n * @returns A promise that resolves to a YoutubePlaylist object\n */\n async (params: ResourceParams): Promise<YoutubePlaylist> => {\n return this.fetch<YoutubePlaylist>('/youtube/playlist', params);\n },\n {\n /**\n * Fetches the videos of a YouTube playlist.\n * @param params - The parameters required to fetch the playlist videos\n * @param params.id - The YouTube playlist ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: PlaylistVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/playlist/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube batch operations.\n */\n batch = {\n /**\n * Retrieves the status and results of a batch job.\n * @param jobId - The ID of the batch job\n * @returns A promise that resolves to the YoutubeBatchResults containing job status and results\n * @throws {SupadataError} If jobId is not provided\n */\n getBatchResults: async (jobId: string): Promise<YoutubeBatchResults> => {\n if (!jobId) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Missing jobId',\n details: 'The jobId parameter is required to get batch results.',\n });\n }\n return this.fetch<YoutubeBatchResults>(`/youtube/batch/${jobId}`);\n },\n };\n\n /**\n * Translates a YouTube video transcript to a specified language.\n * @param params - Parameters for translating the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The target language code for translation\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a TranslatedTranscript object\n */\n translate = async (\n params: TranslateParams\n ): Promise<TranslatedTranscript> => {\n return this.fetch<TranslatedTranscript>(\n '/youtube/transcript/translate',\n params\n );\n };\n\n private validateLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n\n // Add a specific validator for batch limits as per documentation (Max: 5000, Default: 10)\n private validateBatchLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit for batch operation.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport { Crawl, CrawlJob, CrawlRequest, Scrape, SiteMap } from '../types.js';\n\nexport class WebService extends BaseClient {\n /**\n * Extract content from any web page to Markdown format.\n *\n * @param url - URL of the webpage to scrape\n * @returns A promise that resolves to the scraped content\n */\n async scrape(url: string): Promise<Scrape> {\n return this.fetch<Scrape>('/web/scrape', { url });\n }\n\n /**\n * Extract all links found on a webpage.\n *\n * @param url - URL of the webpage to map\n * @returns A promise that resolves to a map of URLs found on the page\n */\n async map(url: string): Promise<SiteMap> {\n return this.fetch<SiteMap>('/web/map', { url });\n }\n\n /**\n * Create a crawl job to extract content from all pages on a website.\n *\n * @param request - Crawl request parameters\n * @param request.url - URL of the website to crawl\n * @param request.limit - Maximum number of pages to crawl (default: 100, max: 5000)\n * @returns A promise that resolves to the crawl job id\n */\n async crawl(request: CrawlRequest): Promise<Crawl> {\n return this.fetch<Crawl>('/web/crawl', request, 'POST');\n }\n\n /**\n * Get the status and results of a crawl job.\n * Automatically handles pagination to retrieve all pages from the crawl.\n *\n * @param jobId - The ID of the crawl job to retrieve\n * @returns A promise that resolves to the complete crawl job results\n */\n async getCrawlResults(jobId: string): Promise<CrawlJob> {\n let response: CrawlJob;\n let pages: Scrape[] = [];\n let nextUrl: string | undefined;\n\n do {\n response = await (nextUrl\n ? this.fetchUrl<CrawlJob>(nextUrl)\n : this.fetch<CrawlJob>(`/web/crawl/${jobId}`));\n\n if (response.pages) {\n pages = [...pages, ...response.pages];\n }\n nextUrl = response.next;\n } while (nextUrl);\n\n return response;\n }\n}\n","import { SupadataConfig } from './types.js';\nimport { YouTubeService } from './services/youtube.js';\nimport { WebService } from './services/web.js';\n\nexport * from './types.js';\nexport * from './client.js';\nexport * from './services/youtube.js';\nexport * from './services/web.js';\n\nexport class Supadata {\n readonly youtube: YouTubeService;\n readonly web: WebService;\n\n constructor(config: SupadataConfig) {\n this.youtube = new YouTubeService(config);\n this.web = new WebService(config);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/types.ts","../package.json","../src/client.ts","../src/services/youtube.ts","../src/services/web.ts","../src/services/transcript.ts","../src/index.ts"],"names":["SupadataError","error","package_default","USER_AGENT","BaseClient","config","endpoint","params","method","url","queryParams","key","value","body","options","response","contentType","errorData","YouTubeService","jobId","WebService","request","pages","nextUrl","TranscriptService","Supadata"],"mappings":"aAgDO,IAAMA,EAAN,cAA4B,KAAM,CACvC,KAQA,CAAA,OAAA,CACA,iBAEA,WAAYC,CAAAA,CAAAA,CAKT,CACD,KAAA,CAAMA,EAAM,OAAW,EAAA,8BAA8B,EACrD,IAAK,CAAA,KAAA,CAAQA,EAAM,KAAS,EAAA,gBAAA,CAC5B,IAAK,CAAA,OAAA,CAAUA,EAAM,OAAW,EAAA,8BAAA,CAChC,KAAK,gBAAmBA,CAAAA,CAAAA,CAAM,kBAAoB,EAClD,CAAA,IAAA,CAAK,KAAO,gBACd,CACF,ECxEA,IAAAC,CAAAA,CAAA,CACE,IAAQ,CAAA,cAAA,CACR,QAAW,OACX,CAAA,WAAA,CAAe,8CACf,CAAA,QAAA,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MAAOE,CACE,EAAA,IAAA,CAAK,mBAAmB,GAAIA,CAAAA,CAAM,EAE3C,CACE,YAAA,CAAeY,GACN,IAAK,CAAA,kBAAA,CAAmB,aAAaA,CAAK,CAErD,CACF,CACF","file":"index.cjs","sourcesContent":["export interface TranscriptChunk {\n text: string;\n offset: number;\n duration: number;\n lang: string;\n}\n\nexport interface Transcript {\n content: TranscriptChunk[] | string;\n lang: string;\n availableLangs: string[];\n}\n\nexport interface TranslatedTranscript {\n content: TranscriptChunk[] | string;\n lang: string;\n}\n\nexport interface Scrape {\n url: string;\n content: string;\n name: string;\n description: string;\n ogUrl: string;\n countCharacters: number;\n urls: string[];\n}\n\nexport interface SiteMap {\n urls: string[];\n}\n\nexport interface CrawlRequest {\n url: string;\n limit?: number;\n}\n\nexport interface CrawlJob {\n status: 'scraping' | 'completed' | 'failed' | 'cancelled';\n pages?: Scrape[];\n next?: string;\n}\n\nexport interface SupadataConfig {\n apiKey: string;\n baseUrl?: string;\n}\n\nexport class SupadataError extends Error {\n error:\n | 'invalid-request'\n | 'internal-error'\n | 'transcript-unavailable'\n | 'not-found'\n | 'unauthorized'\n | 'upgrade-required'\n | 'limit-exceeded';\n details: string;\n documentationUrl: string;\n\n constructor(error: {\n error: SupadataError['error'];\n message?: string;\n details?: string;\n documentationUrl?: string;\n }) {\n super(error.message || 'An unexpected error occurred');\n this.error = error.error || 'internal-error';\n this.details = error.details || 'An unexpected error occurred';\n this.documentationUrl = error.documentationUrl || '';\n this.name = 'SupadataError';\n }\n}\n\nexport interface YoutubeVideo {\n id: string;\n title: string;\n description: string;\n duration: number;\n channel: {\n id: string;\n name: string;\n };\n tags: string[];\n thumbnail: string;\n uploadDate: string;\n viewCount: number;\n likeCount: number;\n transcriptLanguages: string[];\n}\n\nexport interface YoutubeChannel {\n id: string;\n name: string;\n handle: string;\n description: string;\n subscriberCount: number;\n videoCount: number;\n thumbnail: string;\n banner: string;\n}\n\nexport interface YoutubePlaylist {\n id: string;\n title: string;\n videoCount: number;\n viewCount: number;\n lastUpdated: string;\n description: string;\n thumbnail: string;\n}\n\nexport interface YoutubeBatchSource {\n videoIds?: string[];\n playlistId?: string;\n channelId?: string;\n limit?: number;\n}\n\nexport interface YoutubeTranscriptBatchRequest extends YoutubeBatchSource {\n lang?: string;\n text?: boolean;\n}\n\nexport interface YoutubeVideoBatchRequest extends YoutubeBatchSource {}\n\nexport interface JobId {\n jobId: string;\n}\n\nexport interface YoutubeBatchJob extends JobId {}\n\nexport type JobStatus = 'queued' | 'active' | 'completed' | 'failed';\n\nexport type YoutubeBatchJobStatus = JobStatus;\n\nexport interface YoutubeBatchResultItem {\n videoId: string;\n transcript?: Transcript;\n video?: YoutubeVideo;\n errorCode?: string;\n}\n\nexport interface YoutubeBatchStats {\n total: number;\n succeeded: number;\n failed: number;\n}\n\nexport interface YoutubeBatchResults {\n status: YoutubeBatchJobStatus;\n results?: YoutubeBatchResultItem[];\n stats?: YoutubeBatchStats;\n completedAt?: string;\n}\n\nexport type TranscriptOrJobId = Transcript | JobId;\n\nexport interface JobResult<T = any> {\n status: JobStatus;\n result?: T | null;\n error?: {\n error: SupadataError['error'];\n message: string;\n details: string;\n documentationUrl?: string;\n } | null;\n}\n","{\n \"name\": \"@supadata/js\",\n \"version\": \"1.2.0\",\n \"description\": \"TypeScript / JavaScript SDK for Supadata API\",\n \"homepage\": \"https://supadata.ai\",\n \"repository\": \"https://github.com/supadata-ai/js\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.mjs\"\n }\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"tsup\",\n \"test\": \"node --experimental-vm-modules node_modules/jest/bin/jest.js\",\n \"prepare\": \"npm run build\",\n \"format\": \"prettier --write \\\"src/**/*.{js,ts}\\\"\",\n \"format:check\": \"prettier --check \\\"src/**/*.{js,ts}\\\"\"\n },\n \"files\": [\n \"dist\",\n \"README.md\"\n ],\n \"keywords\": [\n \"supadata\",\n \"api\",\n \"sdk\",\n \"typescript\",\n \"youtube\",\n \"transcript\",\n \"web scraping\"\n ],\n \"author\": \"Supadata AI\",\n \"license\": \"MIT\",\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.14\",\n \"@types/node\": \"^22.10.10\",\n \"jest\": \"^29.7.0\",\n \"jest-fetch-mock\": \"^3.0.3\",\n \"prettier\": \"^3.4.2\",\n \"ts-jest\": \"^29.2.5\",\n \"typescript\": \"^5.7.3\",\n \"tsup\": \"^8.3.6\"\n }\n}","import { SupadataConfig, SupadataError } from './types.js';\n// @ts-expect-error: Non-TS import for version from package.json\nimport pkg from '../package.json';\n\nconst USER_AGENT = `supadata-js/${pkg.version}`;\n\nexport class BaseClient {\n protected config: SupadataConfig;\n\n constructor(config: SupadataConfig) {\n this.config = config;\n }\n\n protected async fetch<T>(\n endpoint: string,\n params: Record<string, any> = {},\n method: 'GET' | 'POST' = 'GET'\n ): Promise<T> {\n const baseUrl = this.config.baseUrl || 'https://api.supadata.ai/v1';\n let url = `${baseUrl}${\n endpoint.startsWith('/') ? endpoint : `/${endpoint}`\n }`;\n\n if (method === 'GET' && Object.keys(params).length > 0) {\n const queryParams = new URLSearchParams();\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n queryParams.append(key, String(value));\n }\n });\n url += `?${queryParams.toString()}`;\n }\n\n return this.fetchUrl<T>(url, method, params);\n }\n\n protected async fetchUrl<T>(\n url: string,\n method: 'GET' | 'POST' = 'GET',\n body?: Record<string, any>\n ): Promise<T> {\n const options: RequestInit = {\n method,\n headers: {\n 'x-api-key': this.config.apiKey,\n 'Content-Type': 'application/json',\n 'User-Agent': USER_AGENT,\n },\n };\n\n if (method === 'POST' && body) {\n options.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, options);\n\n const contentType = response.headers.get('content-type');\n\n if (!response.ok) {\n // Handle standard API errors\n if (contentType?.includes('application/json')) {\n const errorData = await response.json();\n throw new SupadataError(errorData);\n } else {\n // Fallback for unexpected non-JSON errors\n throw new SupadataError({\n error: 'internal-error',\n message: 'Unexpected error response format',\n details: await response.text(),\n });\n }\n }\n\n try {\n if (!contentType?.includes('application/json')) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Invalid response format',\n details: 'Expected JSON response but received different content type',\n });\n }\n\n return (await response.json()) as T;\n } catch (error) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Failed to parse response',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport {\n SupadataError,\n Transcript,\n TranslatedTranscript,\n YoutubeBatchJob,\n YoutubeBatchResults,\n YoutubeChannel,\n YoutubePlaylist,\n YoutubeTranscriptBatchRequest,\n YoutubeVideo,\n YoutubeVideoBatchRequest,\n} from '../types.js';\n\n/**\n * Ensures exactly one property from the specified keys is provided.\n * @example\n * // Valid: { url: \"...\" } or { videoId: \"...\" }\n * // Invalid: {} or { url: \"...\", videoId: \"...\" }\n */\ntype ExactlyOne<T, Keys extends keyof T> = {\n [K in Keys]: { [P in K]-?: T[P] } & { [P in Exclude<Keys, K>]?: never };\n}[Keys] &\n Omit<T, Keys>;\n\nexport type TranscriptParams = {\n lang?: string;\n text?: boolean;\n} & ExactlyOne<{ videoId: string; url: string }, 'videoId' | 'url'>;\n\nexport interface TranslateParams extends Omit<TranscriptParams, 'lang'> {\n lang: string;\n}\n\nexport interface ResourceParams {\n id: string;\n}\n\nexport interface ChannelVideosParams extends ResourceParams {\n limit?: number;\n type?: 'video' | 'short' | 'live' | 'all';\n}\n\nexport interface PlaylistVideosParams extends ResourceParams {\n limit?: number;\n}\n\nexport interface VideoIds {\n videoIds: string[];\n shortIds: string[];\n liveIds: string[];\n}\n\nexport class YouTubeService extends BaseClient {\n /**\n * Handles YouTube Transcript operations.\n */\n transcript = Object.assign(\n /**\n * Fetches a transcript for a YouTube video.\n * @param params - Parameters for fetching the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The language code for the transcript (optional)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a Transcript object\n */\n async (params: TranscriptParams): Promise<Transcript> => {\n return this.fetch<Transcript>('/youtube/transcript', params);\n },\n {\n /**\n * Batch fetches transcripts for multiple YouTube videos.\n * @param params - Parameters for the transcript batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch transcripts for\n * @param params.lang - The language code for the transcripts (optional)\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeTranscriptBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/transcript/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube video operations.\n */\n video = Object.assign(\n /**\n * Fetches a YouTube video based on the provided parameters.\n * @param params - The parameters required to fetch the YouTube video\n * @param params.id - The YouTube video ID\n * @returns A promise that resolves to a YoutubeVideo object\n */\n async (params: ResourceParams): Promise<YoutubeVideo> => {\n return this.fetch<YoutubeVideo>('/youtube/video', params);\n },\n {\n /**\n * Batch fetches metadata for multiple YouTube videos.\n * @param params - Parameters for the video metadata batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch metadata for\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeVideoBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/video/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube channel operations.\n */\n channel = Object.assign(\n /**\n * Fetches YouTube channel information.\n * @param params - The parameters required to fetch the YouTube channel information\n * @param params.id - The YouTube channel ID\n * @returns A promise that resolves to a YoutubeChannel object containing the channel information\n */\n async (params: ResourceParams): Promise<YoutubeChannel> => {\n return this.fetch<YoutubeChannel>('/youtube/channel', params);\n },\n {\n /**\n * Fetches the videos of a YouTube channel.\n * @param params - The parameters required to fetch the YouTube channel videos\n * @param params.id - The YouTube channel ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @param params.type - The type of videos to fetch ('video', 'short', 'live', or 'all', default: 'video')\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: ChannelVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/channel/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube playlist operations.\n */\n playlist = Object.assign(\n /**\n * Fetches a YouTube playlist.\n * @param params - The parameters required to fetch the playlist\n * @param params.id - The YouTube playlist ID\n * @returns A promise that resolves to a YoutubePlaylist object\n */\n async (params: ResourceParams): Promise<YoutubePlaylist> => {\n return this.fetch<YoutubePlaylist>('/youtube/playlist', params);\n },\n {\n /**\n * Fetches the videos of a YouTube playlist.\n * @param params - The parameters required to fetch the playlist videos\n * @param params.id - The YouTube playlist ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: PlaylistVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/playlist/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube batch operations.\n */\n batch = {\n /**\n * Retrieves the status and results of a batch job.\n * @param jobId - The ID of the batch job\n * @returns A promise that resolves to the YoutubeBatchResults containing job status and results\n * @throws {SupadataError} If jobId is not provided\n */\n getBatchResults: async (jobId: string): Promise<YoutubeBatchResults> => {\n if (!jobId) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Missing jobId',\n details: 'The jobId parameter is required to get batch results.',\n });\n }\n return this.fetch<YoutubeBatchResults>(`/youtube/batch/${jobId}`);\n },\n };\n\n /**\n * Translates a YouTube video transcript to a specified language.\n * @param params - Parameters for translating the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The target language code for translation\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a TranslatedTranscript object\n */\n translate = async (\n params: TranslateParams\n ): Promise<TranslatedTranscript> => {\n return this.fetch<TranslatedTranscript>(\n '/youtube/transcript/translate',\n params\n );\n };\n\n private validateLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n\n // Add a specific validator for batch limits as per documentation (Max: 5000, Default: 10)\n private validateBatchLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit for batch operation.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport { CrawlJob, CrawlRequest, JobId, Scrape, SiteMap } from '../types.js';\n\nexport class WebService extends BaseClient {\n /**\n * Extract content from any web page to Markdown format.\n *\n * @param url - URL of the webpage to scrape\n * @returns A promise that resolves to the scraped content\n */\n async scrape(url: string): Promise<Scrape> {\n return this.fetch<Scrape>('/web/scrape', { url });\n }\n\n /**\n * Extract all links found on a webpage.\n *\n * @param url - URL of the webpage to map\n * @returns A promise that resolves to a map of URLs found on the page\n */\n async map(url: string): Promise<SiteMap> {\n return this.fetch<SiteMap>('/web/map', { url });\n }\n\n /**\n * Create a crawl job to extract content from all pages on a website.\n *\n * @param request - Crawl request parameters\n * @param request.url - URL of the website to crawl\n * @param request.limit - Maximum number of pages to crawl (default: 100, max: 5000)\n * @returns A promise that resolves to the crawl job id\n */\n async crawl(request: CrawlRequest): Promise<JobId> {\n return this.fetch<JobId>('/web/crawl', request, 'POST');\n }\n\n /**\n * Get the status and results of a crawl job.\n * Automatically handles pagination to retrieve all pages from the crawl.\n *\n * @param jobId - The ID of the crawl job to retrieve\n * @returns A promise that resolves to the complete crawl job results\n */\n async getCrawlResults(jobId: string): Promise<CrawlJob> {\n let response: CrawlJob;\n let pages: Scrape[] = [];\n let nextUrl: string | undefined;\n\n do {\n response = await (nextUrl\n ? this.fetchUrl<CrawlJob>(nextUrl)\n : this.fetch<CrawlJob>(`/web/crawl/${jobId}`));\n\n if (response.pages) {\n pages = [...pages, ...response.pages];\n }\n nextUrl = response.next;\n } while (nextUrl);\n\n return response;\n }\n}\n","import { BaseClient } from '../client.js';\nimport {\n JobId,\n JobResult,\n SupadataError,\n Transcript,\n TranscriptOrJobId,\n} from '../types.js';\n\nexport interface GeneralTranscriptParams {\n url: string;\n lang?: string;\n text?: boolean;\n chunkSize?: number;\n mode?: 'native' | 'auto' | 'generate';\n}\n\nexport class TranscriptService extends BaseClient {\n /**\n * Get transcript from a supported video platform or file URL.\n * @param params - Parameters for fetching the transcript\n * @returns A promise that resolves to either a Transcript or JobId for async processing\n */\n get = async (params: GeneralTranscriptParams): Promise<TranscriptOrJobId> => {\n return this.fetch<TranscriptOrJobId>('/transcript', params);\n };\n\n /**\n * Get results for a transcript job by job ID.\n * @param jobId - The ID of the transcript job\n * @returns A promise that resolves to the job result containing status and transcript if completed\n * @throws {SupadataError} If jobId is not provided\n */\n getJobStatus = async (jobId: string): Promise<JobResult<Transcript>> => {\n if (!jobId) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Missing jobId',\n details:\n 'The jobId parameter is required to get transcript job status.',\n });\n }\n return this.fetch<JobResult<Transcript>>(`/transcript/${jobId}`);\n };\n}\n","import {\n JobResult,\n SupadataConfig,\n Transcript,\n TranscriptOrJobId,\n} from './types.js';\nimport { YouTubeService } from './services/youtube.js';\nimport { WebService } from './services/web.js';\nimport {\n TranscriptService,\n GeneralTranscriptParams,\n} from './services/transcript.js';\n\nexport * from './types.js';\nexport * from './client.js';\nexport * from './services/youtube.js';\nexport * from './services/web.js';\nexport {\n TranscriptService,\n GeneralTranscriptParams,\n} from './services/transcript.js';\n\nexport class Supadata {\n readonly youtube: YouTubeService;\n readonly web: WebService;\n private _transcriptService: TranscriptService;\n\n constructor(config: SupadataConfig) {\n this.youtube = new YouTubeService(config);\n this.web = new WebService(config);\n this._transcriptService = new TranscriptService(config);\n }\n\n /**\n * Get transcript from a supported video platform (YouTube, TikTok, Twitter) or file URL.\n * If the video is too large to return transcript immediately, request returns a job ID.\n */\n transcript = Object.assign(\n async (params: GeneralTranscriptParams): Promise<TranscriptOrJobId> => {\n return this._transcriptService.get(params);\n },\n {\n getJobStatus: (jobId: string): Promise<JobResult<Transcript>> => {\n return this._transcriptService.getJobStatus(jobId);\n },\n }\n );\n}\n"]}
package/dist/index.d.mts CHANGED
@@ -29,9 +29,6 @@ interface CrawlRequest {
29
29
  url: string;
30
30
  limit?: number;
31
31
  }
32
- interface Crawl {
33
- jobId: string;
34
- }
35
32
  interface CrawlJob {
36
33
  status: 'scraping' | 'completed' | 'failed' | 'cancelled';
37
34
  pages?: Scrape[];
@@ -99,10 +96,13 @@ interface YoutubeTranscriptBatchRequest extends YoutubeBatchSource {
99
96
  }
100
97
  interface YoutubeVideoBatchRequest extends YoutubeBatchSource {
101
98
  }
102
- interface YoutubeBatchJob {
99
+ interface JobId {
103
100
  jobId: string;
104
101
  }
105
- type YoutubeBatchJobStatus = 'queued' | 'active' | 'completed' | 'failed';
102
+ interface YoutubeBatchJob extends JobId {
103
+ }
104
+ type JobStatus = 'queued' | 'active' | 'completed' | 'failed';
105
+ type YoutubeBatchJobStatus = JobStatus;
106
106
  interface YoutubeBatchResultItem {
107
107
  videoId: string;
108
108
  transcript?: Transcript;
@@ -120,6 +120,17 @@ interface YoutubeBatchResults {
120
120
  stats?: YoutubeBatchStats;
121
121
  completedAt?: string;
122
122
  }
123
+ type TranscriptOrJobId = Transcript | JobId;
124
+ interface JobResult<T = any> {
125
+ status: JobStatus;
126
+ result?: T | null;
127
+ error?: {
128
+ error: SupadataError['error'];
129
+ message: string;
130
+ details: string;
131
+ documentationUrl?: string;
132
+ } | null;
133
+ }
123
134
 
124
135
  declare class BaseClient {
125
136
  protected config: SupadataConfig;
@@ -273,7 +284,7 @@ declare class WebService extends BaseClient {
273
284
  * @param request.limit - Maximum number of pages to crawl (default: 100, max: 5000)
274
285
  * @returns A promise that resolves to the crawl job id
275
286
  */
276
- crawl(request: CrawlRequest): Promise<Crawl>;
287
+ crawl(request: CrawlRequest): Promise<JobId>;
277
288
  /**
278
289
  * Get the status and results of a crawl job.
279
290
  * Automatically handles pagination to retrieve all pages from the crawl.
@@ -284,10 +295,41 @@ declare class WebService extends BaseClient {
284
295
  getCrawlResults(jobId: string): Promise<CrawlJob>;
285
296
  }
286
297
 
298
+ interface GeneralTranscriptParams {
299
+ url: string;
300
+ lang?: string;
301
+ text?: boolean;
302
+ chunkSize?: number;
303
+ mode?: 'native' | 'auto' | 'generate';
304
+ }
305
+ declare class TranscriptService extends BaseClient {
306
+ /**
307
+ * Get transcript from a supported video platform or file URL.
308
+ * @param params - Parameters for fetching the transcript
309
+ * @returns A promise that resolves to either a Transcript or JobId for async processing
310
+ */
311
+ get: (params: GeneralTranscriptParams) => Promise<TranscriptOrJobId>;
312
+ /**
313
+ * Get results for a transcript job by job ID.
314
+ * @param jobId - The ID of the transcript job
315
+ * @returns A promise that resolves to the job result containing status and transcript if completed
316
+ * @throws {SupadataError} If jobId is not provided
317
+ */
318
+ getJobStatus: (jobId: string) => Promise<JobResult<Transcript>>;
319
+ }
320
+
287
321
  declare class Supadata {
288
322
  readonly youtube: YouTubeService;
289
323
  readonly web: WebService;
324
+ private _transcriptService;
290
325
  constructor(config: SupadataConfig);
326
+ /**
327
+ * Get transcript from a supported video platform (YouTube, TikTok, Twitter) or file URL.
328
+ * If the video is too large to return transcript immediately, request returns a job ID.
329
+ */
330
+ transcript: ((params: GeneralTranscriptParams) => Promise<TranscriptOrJobId>) & {
331
+ getJobStatus: (jobId: string) => Promise<JobResult<Transcript>>;
332
+ };
291
333
  }
292
334
 
293
- export { BaseClient, type ChannelVideosParams, type Crawl, type CrawlJob, type CrawlRequest, type PlaylistVideosParams, type ResourceParams, type Scrape, type SiteMap, Supadata, type SupadataConfig, SupadataError, type Transcript, type TranscriptChunk, type TranscriptParams, type TranslateParams, type TranslatedTranscript, type VideoIds, WebService, YouTubeService, type YoutubeBatchJob, type YoutubeBatchJobStatus, type YoutubeBatchResultItem, type YoutubeBatchResults, type YoutubeBatchSource, type YoutubeBatchStats, type YoutubeChannel, type YoutubePlaylist, type YoutubeTranscriptBatchRequest, type YoutubeVideo, type YoutubeVideoBatchRequest };
335
+ export { BaseClient, type ChannelVideosParams, type CrawlJob, type CrawlRequest, type GeneralTranscriptParams, type JobId, type JobResult, type JobStatus, type PlaylistVideosParams, type ResourceParams, type Scrape, type SiteMap, Supadata, type SupadataConfig, SupadataError, type Transcript, type TranscriptChunk, type TranscriptOrJobId, type TranscriptParams, TranscriptService, type TranslateParams, type TranslatedTranscript, type VideoIds, WebService, YouTubeService, type YoutubeBatchJob, type YoutubeBatchJobStatus, type YoutubeBatchResultItem, type YoutubeBatchResults, type YoutubeBatchSource, type YoutubeBatchStats, type YoutubeChannel, type YoutubePlaylist, type YoutubeTranscriptBatchRequest, type YoutubeVideo, type YoutubeVideoBatchRequest };
package/dist/index.d.ts CHANGED
@@ -29,9 +29,6 @@ interface CrawlRequest {
29
29
  url: string;
30
30
  limit?: number;
31
31
  }
32
- interface Crawl {
33
- jobId: string;
34
- }
35
32
  interface CrawlJob {
36
33
  status: 'scraping' | 'completed' | 'failed' | 'cancelled';
37
34
  pages?: Scrape[];
@@ -99,10 +96,13 @@ interface YoutubeTranscriptBatchRequest extends YoutubeBatchSource {
99
96
  }
100
97
  interface YoutubeVideoBatchRequest extends YoutubeBatchSource {
101
98
  }
102
- interface YoutubeBatchJob {
99
+ interface JobId {
103
100
  jobId: string;
104
101
  }
105
- type YoutubeBatchJobStatus = 'queued' | 'active' | 'completed' | 'failed';
102
+ interface YoutubeBatchJob extends JobId {
103
+ }
104
+ type JobStatus = 'queued' | 'active' | 'completed' | 'failed';
105
+ type YoutubeBatchJobStatus = JobStatus;
106
106
  interface YoutubeBatchResultItem {
107
107
  videoId: string;
108
108
  transcript?: Transcript;
@@ -120,6 +120,17 @@ interface YoutubeBatchResults {
120
120
  stats?: YoutubeBatchStats;
121
121
  completedAt?: string;
122
122
  }
123
+ type TranscriptOrJobId = Transcript | JobId;
124
+ interface JobResult<T = any> {
125
+ status: JobStatus;
126
+ result?: T | null;
127
+ error?: {
128
+ error: SupadataError['error'];
129
+ message: string;
130
+ details: string;
131
+ documentationUrl?: string;
132
+ } | null;
133
+ }
123
134
 
124
135
  declare class BaseClient {
125
136
  protected config: SupadataConfig;
@@ -273,7 +284,7 @@ declare class WebService extends BaseClient {
273
284
  * @param request.limit - Maximum number of pages to crawl (default: 100, max: 5000)
274
285
  * @returns A promise that resolves to the crawl job id
275
286
  */
276
- crawl(request: CrawlRequest): Promise<Crawl>;
287
+ crawl(request: CrawlRequest): Promise<JobId>;
277
288
  /**
278
289
  * Get the status and results of a crawl job.
279
290
  * Automatically handles pagination to retrieve all pages from the crawl.
@@ -284,10 +295,41 @@ declare class WebService extends BaseClient {
284
295
  getCrawlResults(jobId: string): Promise<CrawlJob>;
285
296
  }
286
297
 
298
+ interface GeneralTranscriptParams {
299
+ url: string;
300
+ lang?: string;
301
+ text?: boolean;
302
+ chunkSize?: number;
303
+ mode?: 'native' | 'auto' | 'generate';
304
+ }
305
+ declare class TranscriptService extends BaseClient {
306
+ /**
307
+ * Get transcript from a supported video platform or file URL.
308
+ * @param params - Parameters for fetching the transcript
309
+ * @returns A promise that resolves to either a Transcript or JobId for async processing
310
+ */
311
+ get: (params: GeneralTranscriptParams) => Promise<TranscriptOrJobId>;
312
+ /**
313
+ * Get results for a transcript job by job ID.
314
+ * @param jobId - The ID of the transcript job
315
+ * @returns A promise that resolves to the job result containing status and transcript if completed
316
+ * @throws {SupadataError} If jobId is not provided
317
+ */
318
+ getJobStatus: (jobId: string) => Promise<JobResult<Transcript>>;
319
+ }
320
+
287
321
  declare class Supadata {
288
322
  readonly youtube: YouTubeService;
289
323
  readonly web: WebService;
324
+ private _transcriptService;
290
325
  constructor(config: SupadataConfig);
326
+ /**
327
+ * Get transcript from a supported video platform (YouTube, TikTok, Twitter) or file URL.
328
+ * If the video is too large to return transcript immediately, request returns a job ID.
329
+ */
330
+ transcript: ((params: GeneralTranscriptParams) => Promise<TranscriptOrJobId>) & {
331
+ getJobStatus: (jobId: string) => Promise<JobResult<Transcript>>;
332
+ };
291
333
  }
292
334
 
293
- export { BaseClient, type ChannelVideosParams, type Crawl, type CrawlJob, type CrawlRequest, type PlaylistVideosParams, type ResourceParams, type Scrape, type SiteMap, Supadata, type SupadataConfig, SupadataError, type Transcript, type TranscriptChunk, type TranscriptParams, type TranslateParams, type TranslatedTranscript, type VideoIds, WebService, YouTubeService, type YoutubeBatchJob, type YoutubeBatchJobStatus, type YoutubeBatchResultItem, type YoutubeBatchResults, type YoutubeBatchSource, type YoutubeBatchStats, type YoutubeChannel, type YoutubePlaylist, type YoutubeTranscriptBatchRequest, type YoutubeVideo, type YoutubeVideoBatchRequest };
335
+ export { BaseClient, type ChannelVideosParams, type CrawlJob, type CrawlRequest, type GeneralTranscriptParams, type JobId, type JobResult, type JobStatus, type PlaylistVideosParams, type ResourceParams, type Scrape, type SiteMap, Supadata, type SupadataConfig, SupadataError, type Transcript, type TranscriptChunk, type TranscriptOrJobId, type TranscriptParams, TranscriptService, type TranslateParams, type TranslatedTranscript, type VideoIds, WebService, YouTubeService, type YoutubeBatchJob, type YoutubeBatchJobStatus, type YoutubeBatchResultItem, type YoutubeBatchResults, type YoutubeBatchSource, type YoutubeBatchStats, type YoutubeChannel, type YoutubePlaylist, type YoutubeTranscriptBatchRequest, type YoutubeVideo, type YoutubeVideoBatchRequest };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- var r=class extends Error{error;details;documentationUrl;constructor(e){super(e.message||"An unexpected error occurred"),this.error=e.error||"internal-error",this.details=e.details||"An unexpected error occurred",this.documentationUrl=e.documentationUrl||"",this.name="SupadataError";}};var o=class{config;constructor(e){this.config=e;}async fetch(e,t={},i="GET"){let s=`${this.config.baseUrl||"https://api.supadata.ai/v1"}${e.startsWith("/")?e:`/${e}`}`;if(i==="GET"&&Object.keys(t).length>0){let u=new URLSearchParams;Object.entries(t).forEach(([a,h])=>{h!=null&&u.append(a,String(h));}),s+=`?${u.toString()}`;}return this.fetchUrl(s,i,t)}async fetchUrl(e,t="GET",i){let n={method:t,headers:{"x-api-key":this.config.apiKey,"Content-Type":"application/json"}};t==="POST"&&i&&(n.body=JSON.stringify(i));let s=await fetch(e,n),u=s.headers.get("content-type");if(!s.ok)if(u?.includes("application/json")){let a=await s.json();throw new r(a)}else throw new r({error:"internal-error",message:"Unexpected error response format",details:await s.text()});try{if(!u?.includes("application/json"))throw new r({error:"internal-error",message:"Invalid response format",details:"Expected JSON response but received different content type"});return await s.json()}catch(a){throw new r({error:"internal-error",message:"Failed to parse response",details:a instanceof Error?a.message:"Unknown error"})}}};var p=class extends o{transcript=Object.assign(async e=>this.fetch("/youtube/transcript",e),{batch:async e=>(this.validateBatchLimit(e),this.fetch("/youtube/transcript/batch",e,"POST"))});video=Object.assign(async e=>this.fetch("/youtube/video",e),{batch:async e=>(this.validateBatchLimit(e),this.fetch("/youtube/video/batch",e,"POST"))});channel=Object.assign(async e=>this.fetch("/youtube/channel",e),{videos:async e=>(this.validateLimit(e),this.fetch("/youtube/channel/videos",e))});playlist=Object.assign(async e=>this.fetch("/youtube/playlist",e),{videos:async e=>(this.validateLimit(e),this.fetch("/youtube/playlist/videos",e))});batch={getBatchResults:async e=>{if(!e)throw new r({error:"invalid-request",message:"Missing jobId",details:"The jobId parameter is required to get batch results."});return this.fetch(`/youtube/batch/${e}`)}};translate=async e=>this.fetch("/youtube/transcript/translate",e);validateLimit(e){if(e.limit!=null&&e.limit!=null&&(e.limit<1||e.limit>5e3))throw new r({error:"invalid-request",message:"Invalid limit.",details:"The limit must be between 1 and 5000."})}validateBatchLimit(e){if(e.limit!=null&&e.limit!=null&&(e.limit<1||e.limit>5e3))throw new r({error:"invalid-request",message:"Invalid limit for batch operation.",details:"The limit must be between 1 and 5000."})}};var b=class extends o{async scrape(e){return this.fetch("/web/scrape",{url:e})}async map(e){return this.fetch("/web/map",{url:e})}async crawl(e){return this.fetch("/web/crawl",e,"POST")}async getCrawlResults(e){let t,i=[],n;do t=await(n?this.fetchUrl(n):this.fetch(`/web/crawl/${e}`)),t.pages&&(i=[...i,...t.pages]),n=t.next;while(n);return t}};var g=class{youtube;web;constructor(e){this.youtube=new p(e),this.web=new b(e);}};
2
- export{o as BaseClient,g as Supadata,r as SupadataError,b as WebService,p as YouTubeService};//# sourceMappingURL=index.mjs.map
1
+ var e=class extends Error{error;details;documentationUrl;constructor(t){super(t.message||"An unexpected error occurred"),this.error=t.error||"internal-error",this.details=t.details||"An unexpected error occurred",this.documentationUrl=t.documentationUrl||"",this.name="SupadataError";}};var g={name:"@supadata/js",version:"1.2.0",description:"TypeScript / JavaScript SDK for Supadata API",homepage:"https://supadata.ai",repository:"https://github.com/supadata-ai/js",main:"./dist/index.cjs",module:"./dist/index.mjs",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.mjs",require:"./dist/index.cjs",default:"./dist/index.mjs"}},scripts:{dev:"tsup --watch",build:"tsup",test:"node --experimental-vm-modules node_modules/jest/bin/jest.js",prepare:"npm run build",format:'prettier --write "src/**/*.{js,ts}"',"format:check":'prettier --check "src/**/*.{js,ts}"'},files:["dist","README.md"],keywords:["supadata","api","sdk","typescript","youtube","transcript","web scraping"],author:"Supadata AI",license:"MIT",devDependencies:{"@types/jest":"^29.5.14","@types/node":"^22.10.10",jest:"^29.7.0","jest-fetch-mock":"^3.0.3",prettier:"^3.4.2","ts-jest":"^29.2.5",typescript:"^5.7.3",tsup:"^8.3.6"}};var x=`supadata-js/${g.version}`,n=class{config;constructor(t){this.config=t;}async fetch(t,r={},s="GET"){let a=`${this.config.baseUrl||"https://api.supadata.ai/v1"}${t.startsWith("/")?t:`/${t}`}`;if(s==="GET"&&Object.keys(r).length>0){let u=new URLSearchParams;Object.entries(r).forEach(([o,h])=>{h!=null&&u.append(o,String(h));}),a+=`?${u.toString()}`;}return this.fetchUrl(a,s,r)}async fetchUrl(t,r="GET",s){let i={method:r,headers:{"x-api-key":this.config.apiKey,"Content-Type":"application/json","User-Agent":x}};r==="POST"&&s&&(i.body=JSON.stringify(s));let a=await fetch(t,i),u=a.headers.get("content-type");if(!a.ok)if(u?.includes("application/json")){let o=await a.json();throw new e(o)}else throw new e({error:"internal-error",message:"Unexpected error response format",details:await a.text()});try{if(!u?.includes("application/json"))throw new e({error:"internal-error",message:"Invalid response format",details:"Expected JSON response but received different content type"});return await a.json()}catch(o){throw new e({error:"internal-error",message:"Failed to parse response",details:o instanceof Error?o.message:"Unknown error"})}}};var b=class extends n{transcript=Object.assign(async t=>this.fetch("/youtube/transcript",t),{batch:async t=>(this.validateBatchLimit(t),this.fetch("/youtube/transcript/batch",t,"POST"))});video=Object.assign(async t=>this.fetch("/youtube/video",t),{batch:async t=>(this.validateBatchLimit(t),this.fetch("/youtube/video/batch",t,"POST"))});channel=Object.assign(async t=>this.fetch("/youtube/channel",t),{videos:async t=>(this.validateLimit(t),this.fetch("/youtube/channel/videos",t))});playlist=Object.assign(async t=>this.fetch("/youtube/playlist",t),{videos:async t=>(this.validateLimit(t),this.fetch("/youtube/playlist/videos",t))});batch={getBatchResults:async t=>{if(!t)throw new e({error:"invalid-request",message:"Missing jobId",details:"The jobId parameter is required to get batch results."});return this.fetch(`/youtube/batch/${t}`)}};translate=async t=>this.fetch("/youtube/transcript/translate",t);validateLimit(t){if(t.limit!=null&&t.limit!=null&&(t.limit<1||t.limit>5e3))throw new e({error:"invalid-request",message:"Invalid limit.",details:"The limit must be between 1 and 5000."})}validateBatchLimit(t){if(t.limit!=null&&t.limit!=null&&(t.limit<1||t.limit>5e3))throw new e({error:"invalid-request",message:"Invalid limit for batch operation.",details:"The limit must be between 1 and 5000."})}};var m=class extends n{async scrape(t){return this.fetch("/web/scrape",{url:t})}async map(t){return this.fetch("/web/map",{url:t})}async crawl(t){return this.fetch("/web/crawl",t,"POST")}async getCrawlResults(t){let r,s=[],i;do r=await(i?this.fetchUrl(i):this.fetch(`/web/crawl/${t}`)),r.pages&&(s=[...s,...r.pages]),i=r.next;while(i);return r}};var p=class extends n{get=async t=>this.fetch("/transcript",t);getJobStatus=async t=>{if(!t)throw new e({error:"invalid-request",message:"Missing jobId",details:"The jobId parameter is required to get transcript job status."});return this.fetch(`/transcript/${t}`)}};var f=class{youtube;web;_transcriptService;constructor(t){this.youtube=new b(t),this.web=new m(t),this._transcriptService=new p(t);}transcript=Object.assign(async t=>this._transcriptService.get(t),{getJobStatus:t=>this._transcriptService.getJobStatus(t)})};
2
+ export{n as BaseClient,f as Supadata,e as SupadataError,p as TranscriptService,m as WebService,b as YouTubeService};//# sourceMappingURL=index.mjs.map
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/client.ts","../src/services/youtube.ts","../src/services/web.ts","../src/index.ts"],"names":["SupadataError","error","BaseClient","config","endpoint","params","method","url","queryParams","key","value","body","options","response","contentType","errorData","YouTubeService","jobId","WebService","request","pages","nextUrl","Supadata"],"mappings":"AAoDO,IAAMA,CAAN,CAAA,cAA4B,KAAM,CACvC,KAQA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,MAAM,CACxD,CASA,MAAM,eAAA,CAAgBF,CAAkC,CAAA,CACtD,IAAIJ,CAAAA,CACAO,CAAkB,CAAA,GAClBC,CAEJ,CAAA,GACER,CAAW,CAAA,MAAOQ,CACd,CAAA,IAAA,CAAK,QAAmBA,CAAAA,CAAO,EAC/B,IAAK,CAAA,KAAA,CAAgB,CAAcJ,WAAAA,EAAAA,CAAK,CAAE,CAAA,CAAA,CAAA,CAE1CJ,CAAS,CAAA,KAAA,GACXO,EAAQ,CAAC,GAAGA,CAAO,CAAA,GAAGP,CAAS,CAAA,KAAK,CAEtCQ,CAAAA,CAAAA,CAAAA,CAAUR,EAAS,IACZQ,CAAAA,MAAAA,CAAAA,EAET,OAAOR,CACT,CACF,ECpDaS,IAAAA,CAAAA,CAAN,KAAe,CACX,OAAA,CACA,GAET,CAAA,WAAA,CAAYnB,CAAwB,CAAA,CAClC,IAAK,CAAA,OAAA,CAAU,IAAIa,CAAeb,CAAAA,CAAM,CACxC,CAAA,IAAA,CAAK,GAAM,CAAA,IAAIe,CAAWf,CAAAA,CAAM,EAClC,CACF","file":"index.mjs","sourcesContent":["export interface TranscriptChunk {\n text: string;\n offset: number;\n duration: number;\n lang: string;\n}\n\nexport interface Transcript {\n content: TranscriptChunk[] | string;\n lang: string;\n availableLangs: string[];\n}\n\nexport interface TranslatedTranscript {\n content: TranscriptChunk[] | string;\n lang: string;\n}\n\nexport interface Scrape {\n url: string;\n content: string;\n name: string;\n description: string;\n ogUrl: string;\n countCharacters: number;\n urls: string[];\n}\n\nexport interface SiteMap {\n urls: string[];\n}\n\nexport interface CrawlRequest {\n url: string;\n limit?: number;\n}\n\nexport interface Crawl {\n jobId: string;\n}\n\nexport interface CrawlJob {\n status: 'scraping' | 'completed' | 'failed' | 'cancelled';\n pages?: Scrape[];\n next?: string;\n}\n\nexport interface SupadataConfig {\n apiKey: string;\n baseUrl?: string;\n}\n\nexport class SupadataError extends Error {\n error:\n | 'invalid-request'\n | 'internal-error'\n | 'transcript-unavailable'\n | 'not-found'\n | 'unauthorized'\n | 'upgrade-required'\n | 'limit-exceeded';\n details: string;\n documentationUrl: string;\n\n constructor(error: {\n error: SupadataError['error'];\n message?: string;\n details?: string;\n documentationUrl?: string;\n }) {\n super(error.message || 'An unexpected error occurred');\n this.error = error.error || 'internal-error';\n this.details = error.details || 'An unexpected error occurred';\n this.documentationUrl = error.documentationUrl || '';\n this.name = 'SupadataError';\n }\n}\n\nexport interface YoutubeVideo {\n id: string;\n title: string;\n description: string;\n duration: number;\n channel: {\n id: string;\n name: string;\n };\n tags: string[];\n thumbnail: string;\n uploadDate: string;\n viewCount: number;\n likeCount: number;\n transcriptLanguages: string[];\n}\n\nexport interface YoutubeChannel {\n id: string;\n name: string;\n handle: string;\n description: string;\n subscriberCount: number;\n videoCount: number;\n thumbnail: string;\n banner: string;\n}\n\nexport interface YoutubePlaylist {\n id: string;\n title: string;\n videoCount: number;\n viewCount: number;\n lastUpdated: string;\n description: string;\n thumbnail: string;\n}\n\nexport interface YoutubeBatchSource {\n videoIds?: string[];\n playlistId?: string;\n channelId?: string;\n limit?: number;\n}\n\nexport interface YoutubeTranscriptBatchRequest extends YoutubeBatchSource {\n lang?: string;\n text?: boolean;\n}\n\nexport interface YoutubeVideoBatchRequest extends YoutubeBatchSource {}\n\nexport interface YoutubeBatchJob {\n jobId: string;\n}\n\nexport type YoutubeBatchJobStatus =\n | 'queued'\n | 'active'\n | 'completed'\n | 'failed';\n\nexport interface YoutubeBatchResultItem {\n videoId: string;\n transcript?: Transcript;\n video?: YoutubeVideo;\n errorCode?: string;\n}\n\nexport interface YoutubeBatchStats {\n total: number;\n succeeded: number;\n failed: number;\n}\n\nexport interface YoutubeBatchResults {\n status: YoutubeBatchJobStatus;\n results?: YoutubeBatchResultItem[];\n stats?: YoutubeBatchStats;\n completedAt?: string;\n}\n","import { SupadataConfig, SupadataError } from './types.js';\n\nexport class BaseClient {\n protected config: SupadataConfig;\n\n constructor(config: SupadataConfig) {\n this.config = config;\n }\n\n protected async fetch<T>(\n endpoint: string,\n params: Record<string, any> = {},\n method: 'GET' | 'POST' = 'GET'\n ): Promise<T> {\n const baseUrl = this.config.baseUrl || 'https://api.supadata.ai/v1';\n let url = `${baseUrl}${\n endpoint.startsWith('/') ? endpoint : `/${endpoint}`\n }`;\n\n if (method === 'GET' && Object.keys(params).length > 0) {\n const queryParams = new URLSearchParams();\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n queryParams.append(key, String(value));\n }\n });\n url += `?${queryParams.toString()}`;\n }\n\n return this.fetchUrl<T>(url, method, params);\n }\n\n protected async fetchUrl<T>(\n url: string,\n method: 'GET' | 'POST' = 'GET',\n body?: Record<string, any>\n ): Promise<T> {\n const options: RequestInit = {\n method,\n headers: {\n 'x-api-key': this.config.apiKey,\n 'Content-Type': 'application/json',\n },\n };\n\n if (method === 'POST' && body) {\n options.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, options);\n\n const contentType = response.headers.get('content-type');\n\n if (!response.ok) {\n // Handle standard API errors\n if (contentType?.includes('application/json')) {\n const errorData = await response.json();\n throw new SupadataError(errorData);\n } else {\n // Fallback for unexpected non-JSON errors\n throw new SupadataError({\n error: 'internal-error',\n message: 'Unexpected error response format',\n details: await response.text(),\n });\n }\n }\n\n try {\n if (!contentType?.includes('application/json')) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Invalid response format',\n details: 'Expected JSON response but received different content type',\n });\n }\n\n return (await response.json()) as T;\n } catch (error) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Failed to parse response',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport {\n SupadataError,\n Transcript,\n TranslatedTranscript,\n YoutubeBatchJob,\n YoutubeBatchResults,\n YoutubeChannel,\n YoutubePlaylist,\n YoutubeTranscriptBatchRequest,\n YoutubeVideo,\n YoutubeVideoBatchRequest,\n} from '../types.js';\n\n/**\n * Ensures exactly one property from the specified keys is provided.\n * @example\n * // Valid: { url: \"...\" } or { videoId: \"...\" }\n * // Invalid: {} or { url: \"...\", videoId: \"...\" }\n */\ntype ExactlyOne<T, Keys extends keyof T> = {\n [K in Keys]: { [P in K]-?: T[P] } & { [P in Exclude<Keys, K>]?: never };\n}[Keys] &\n Omit<T, Keys>;\n\nexport type TranscriptParams = {\n lang?: string;\n text?: boolean;\n} & ExactlyOne<{ videoId: string; url: string }, 'videoId' | 'url'>;\n\nexport interface TranslateParams extends Omit<TranscriptParams, 'lang'> {\n lang: string;\n}\n\nexport interface ResourceParams {\n id: string;\n}\n\nexport interface ChannelVideosParams extends ResourceParams {\n limit?: number;\n type?: 'video' | 'short' | 'live' | 'all';\n}\n\nexport interface PlaylistVideosParams extends ResourceParams {\n limit?: number;\n}\n\nexport interface VideoIds {\n videoIds: string[];\n shortIds: string[];\n liveIds: string[];\n}\n\nexport class YouTubeService extends BaseClient {\n /**\n * Handles YouTube Transcript operations.\n */\n transcript = Object.assign(\n /**\n * Fetches a transcript for a YouTube video.\n * @param params - Parameters for fetching the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The language code for the transcript (optional)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a Transcript object\n */\n async (params: TranscriptParams): Promise<Transcript> => {\n return this.fetch<Transcript>('/youtube/transcript', params);\n },\n {\n /**\n * Batch fetches transcripts for multiple YouTube videos.\n * @param params - Parameters for the transcript batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch transcripts for\n * @param params.lang - The language code for the transcripts (optional)\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeTranscriptBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/transcript/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube video operations.\n */\n video = Object.assign(\n /**\n * Fetches a YouTube video based on the provided parameters.\n * @param params - The parameters required to fetch the YouTube video\n * @param params.id - The YouTube video ID\n * @returns A promise that resolves to a YoutubeVideo object\n */\n async (params: ResourceParams): Promise<YoutubeVideo> => {\n return this.fetch<YoutubeVideo>('/youtube/video', params);\n },\n {\n /**\n * Batch fetches metadata for multiple YouTube videos.\n * @param params - Parameters for the video metadata batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch metadata for\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeVideoBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/video/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube channel operations.\n */\n channel = Object.assign(\n /**\n * Fetches YouTube channel information.\n * @param params - The parameters required to fetch the YouTube channel information\n * @param params.id - The YouTube channel ID\n * @returns A promise that resolves to a YoutubeChannel object containing the channel information\n */\n async (params: ResourceParams): Promise<YoutubeChannel> => {\n return this.fetch<YoutubeChannel>('/youtube/channel', params);\n },\n {\n /**\n * Fetches the videos of a YouTube channel.\n * @param params - The parameters required to fetch the YouTube channel videos\n * @param params.id - The YouTube channel ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @param params.type - The type of videos to fetch ('video', 'short', 'live', or 'all', default: 'video')\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: ChannelVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/channel/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube playlist operations.\n */\n playlist = Object.assign(\n /**\n * Fetches a YouTube playlist.\n * @param params - The parameters required to fetch the playlist\n * @param params.id - The YouTube playlist ID\n * @returns A promise that resolves to a YoutubePlaylist object\n */\n async (params: ResourceParams): Promise<YoutubePlaylist> => {\n return this.fetch<YoutubePlaylist>('/youtube/playlist', params);\n },\n {\n /**\n * Fetches the videos of a YouTube playlist.\n * @param params - The parameters required to fetch the playlist videos\n * @param params.id - The YouTube playlist ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: PlaylistVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/playlist/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube batch operations.\n */\n batch = {\n /**\n * Retrieves the status and results of a batch job.\n * @param jobId - The ID of the batch job\n * @returns A promise that resolves to the YoutubeBatchResults containing job status and results\n * @throws {SupadataError} If jobId is not provided\n */\n getBatchResults: async (jobId: string): Promise<YoutubeBatchResults> => {\n if (!jobId) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Missing jobId',\n details: 'The jobId parameter is required to get batch results.',\n });\n }\n return this.fetch<YoutubeBatchResults>(`/youtube/batch/${jobId}`);\n },\n };\n\n /**\n * Translates a YouTube video transcript to a specified language.\n * @param params - Parameters for translating the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The target language code for translation\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a TranslatedTranscript object\n */\n translate = async (\n params: TranslateParams\n ): Promise<TranslatedTranscript> => {\n return this.fetch<TranslatedTranscript>(\n '/youtube/transcript/translate',\n params\n );\n };\n\n private validateLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n\n // Add a specific validator for batch limits as per documentation (Max: 5000, Default: 10)\n private validateBatchLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit for batch operation.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport { Crawl, CrawlJob, CrawlRequest, Scrape, SiteMap } from '../types.js';\n\nexport class WebService extends BaseClient {\n /**\n * Extract content from any web page to Markdown format.\n *\n * @param url - URL of the webpage to scrape\n * @returns A promise that resolves to the scraped content\n */\n async scrape(url: string): Promise<Scrape> {\n return this.fetch<Scrape>('/web/scrape', { url });\n }\n\n /**\n * Extract all links found on a webpage.\n *\n * @param url - URL of the webpage to map\n * @returns A promise that resolves to a map of URLs found on the page\n */\n async map(url: string): Promise<SiteMap> {\n return this.fetch<SiteMap>('/web/map', { url });\n }\n\n /**\n * Create a crawl job to extract content from all pages on a website.\n *\n * @param request - Crawl request parameters\n * @param request.url - URL of the website to crawl\n * @param request.limit - Maximum number of pages to crawl (default: 100, max: 5000)\n * @returns A promise that resolves to the crawl job id\n */\n async crawl(request: CrawlRequest): Promise<Crawl> {\n return this.fetch<Crawl>('/web/crawl', request, 'POST');\n }\n\n /**\n * Get the status and results of a crawl job.\n * Automatically handles pagination to retrieve all pages from the crawl.\n *\n * @param jobId - The ID of the crawl job to retrieve\n * @returns A promise that resolves to the complete crawl job results\n */\n async getCrawlResults(jobId: string): Promise<CrawlJob> {\n let response: CrawlJob;\n let pages: Scrape[] = [];\n let nextUrl: string | undefined;\n\n do {\n response = await (nextUrl\n ? this.fetchUrl<CrawlJob>(nextUrl)\n : this.fetch<CrawlJob>(`/web/crawl/${jobId}`));\n\n if (response.pages) {\n pages = [...pages, ...response.pages];\n }\n nextUrl = response.next;\n } while (nextUrl);\n\n return response;\n }\n}\n","import { SupadataConfig } from './types.js';\nimport { YouTubeService } from './services/youtube.js';\nimport { WebService } from './services/web.js';\n\nexport * from './types.js';\nexport * from './client.js';\nexport * from './services/youtube.js';\nexport * from './services/web.js';\n\nexport class Supadata {\n readonly youtube: YouTubeService;\n readonly web: WebService;\n\n constructor(config: SupadataConfig) {\n this.youtube = new YouTubeService(config);\n this.web = new WebService(config);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/types.ts","../package.json","../src/client.ts","../src/services/youtube.ts","../src/services/web.ts","../src/services/transcript.ts","../src/index.ts"],"names":["SupadataError","error","package_default","USER_AGENT","BaseClient","config","endpoint","params","method","url","queryParams","key","value","body","options","response","contentType","errorData","YouTubeService","jobId","WebService","request","pages","nextUrl","TranscriptService","Supadata"],"mappings":"AAgDO,IAAMA,EAAN,cAA4B,KAAM,CACvC,KAQA,CAAA,OAAA,CACA,iBAEA,WAAYC,CAAAA,CAAAA,CAKT,CACD,KAAA,CAAMA,EAAM,OAAW,EAAA,8BAA8B,EACrD,IAAK,CAAA,KAAA,CAAQA,EAAM,KAAS,EAAA,gBAAA,CAC5B,IAAK,CAAA,OAAA,CAAUA,EAAM,OAAW,EAAA,8BAAA,CAChC,KAAK,gBAAmBA,CAAAA,CAAAA,CAAM,kBAAoB,EAClD,CAAA,IAAA,CAAK,KAAO,gBACd,CACF,ECxEA,IAAAC,CAAAA,CAAA,CACE,IAAQ,CAAA,cAAA,CACR,QAAW,OACX,CAAA,WAAA,CAAe,8CACf,CAAA,QAAA,CAAY,sBACZ,UAAc,CAAA,mCAAA,CACd,KAAQ,kBACR,CAAA,MAAA,CAAU,mBACV,KAAS,CAAA,mBAAA,CACT,QAAW,CACT,GAAA,CAAK,CACH,KAAS,CAAA,mBAAA,CACT,OAAU,kBACV,CAAA,OAAA,CAAW,mBACX,OAAW,CAAA,kBACb,CACF,CAAA,CACA,QAAW,CACT,GAAA,CAAO,eACP,KAAS,CAAA,MAAA,CACT,KAAQ,8DACR,CAAA,OAAA,CAAW,gBACX,MA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AK,SAAmBA,CAAO,CAAA,CAC/B,IAAK,CAAA,KAAA,CAAgB,cAAcJ,CAAK,CAAA,CAAE,GAE1CJ,CAAS,CAAA,KAAA,GACXO,EAAQ,CAAC,GAAGA,EAAO,GAAGP,CAAAA,CAAS,KAAK,CAEtCQ,CAAAA,CAAAA,CAAAA,CAAUR,EAAS,IACZQ,CAAAA,MAAAA,CAAAA,EAET,OAAOR,CACT,CACF,EC5CO,IAAMS,EAAN,cAAgCpB,CAAW,CAMhD,GAAM,CAAA,MAAOG,GACJ,IAAK,CAAA,KAAA,CAAyB,cAAeA,CAAM,CAAA,CAS5D,aAAe,MAAOY,CAAAA,EAAkD,CACtE,GAAI,CAACA,EACH,MAAM,IAAInB,CAAc,CAAA,CACtB,MAAO,iBACP,CAAA,OAAA,CAAS,gBACT,OACE,CAAA,+DACJ,CAAC,CAEH,CAAA,OAAO,KAAK,KAA6B,CAAA,CAAA,YAAA,EAAemB,CAAK,CAAE,CAAA,CACjE,CACF,ECtBO,IAAMM,EAAN,KAAe,CACX,OACA,CAAA,GAAA,CACD,mBAER,WAAYpB,CAAAA,CAAAA,CAAwB,CAClC,IAAK,CAAA,OAAA,CAAU,IAAIa,CAAeb,CAAAA,CAAM,EACxC,IAAK,CAAA,GAAA,CAAM,IAAIe,CAAWf,CAAAA,CAAM,EAChC,IAAK,CAAA,kBAAA,CAAqB,IAAImB,CAAkBnB,CAAAA,CAAM,EACxD,CAMA,WAAa,MAAO,CAAA,MAAA,CAClB,MAAOE,CACE,EAAA,IAAA,CAAK,mBAAmB,GAAIA,CAAAA,CAAM,EAE3C,CACE,YAAA,CAAeY,GACN,IAAK,CAAA,kBAAA,CAAmB,aAAaA,CAAK,CAErD,CACF,CACF","file":"index.mjs","sourcesContent":["export interface TranscriptChunk {\n text: string;\n offset: number;\n duration: number;\n lang: string;\n}\n\nexport interface Transcript {\n content: TranscriptChunk[] | string;\n lang: string;\n availableLangs: string[];\n}\n\nexport interface TranslatedTranscript {\n content: TranscriptChunk[] | string;\n lang: string;\n}\n\nexport interface Scrape {\n url: string;\n content: string;\n name: string;\n description: string;\n ogUrl: string;\n countCharacters: number;\n urls: string[];\n}\n\nexport interface SiteMap {\n urls: string[];\n}\n\nexport interface CrawlRequest {\n url: string;\n limit?: number;\n}\n\nexport interface CrawlJob {\n status: 'scraping' | 'completed' | 'failed' | 'cancelled';\n pages?: Scrape[];\n next?: string;\n}\n\nexport interface SupadataConfig {\n apiKey: string;\n baseUrl?: string;\n}\n\nexport class SupadataError extends Error {\n error:\n | 'invalid-request'\n | 'internal-error'\n | 'transcript-unavailable'\n | 'not-found'\n | 'unauthorized'\n | 'upgrade-required'\n | 'limit-exceeded';\n details: string;\n documentationUrl: string;\n\n constructor(error: {\n error: SupadataError['error'];\n message?: string;\n details?: string;\n documentationUrl?: string;\n }) {\n super(error.message || 'An unexpected error occurred');\n this.error = error.error || 'internal-error';\n this.details = error.details || 'An unexpected error occurred';\n this.documentationUrl = error.documentationUrl || '';\n this.name = 'SupadataError';\n }\n}\n\nexport interface YoutubeVideo {\n id: string;\n title: string;\n description: string;\n duration: number;\n channel: {\n id: string;\n name: string;\n };\n tags: string[];\n thumbnail: string;\n uploadDate: string;\n viewCount: number;\n likeCount: number;\n transcriptLanguages: string[];\n}\n\nexport interface YoutubeChannel {\n id: string;\n name: string;\n handle: string;\n description: string;\n subscriberCount: number;\n videoCount: number;\n thumbnail: string;\n banner: string;\n}\n\nexport interface YoutubePlaylist {\n id: string;\n title: string;\n videoCount: number;\n viewCount: number;\n lastUpdated: string;\n description: string;\n thumbnail: string;\n}\n\nexport interface YoutubeBatchSource {\n videoIds?: string[];\n playlistId?: string;\n channelId?: string;\n limit?: number;\n}\n\nexport interface YoutubeTranscriptBatchRequest extends YoutubeBatchSource {\n lang?: string;\n text?: boolean;\n}\n\nexport interface YoutubeVideoBatchRequest extends YoutubeBatchSource {}\n\nexport interface JobId {\n jobId: string;\n}\n\nexport interface YoutubeBatchJob extends JobId {}\n\nexport type JobStatus = 'queued' | 'active' | 'completed' | 'failed';\n\nexport type YoutubeBatchJobStatus = JobStatus;\n\nexport interface YoutubeBatchResultItem {\n videoId: string;\n transcript?: Transcript;\n video?: YoutubeVideo;\n errorCode?: string;\n}\n\nexport interface YoutubeBatchStats {\n total: number;\n succeeded: number;\n failed: number;\n}\n\nexport interface YoutubeBatchResults {\n status: YoutubeBatchJobStatus;\n results?: YoutubeBatchResultItem[];\n stats?: YoutubeBatchStats;\n completedAt?: string;\n}\n\nexport type TranscriptOrJobId = Transcript | JobId;\n\nexport interface JobResult<T = any> {\n status: JobStatus;\n result?: T | null;\n error?: {\n error: SupadataError['error'];\n message: string;\n details: string;\n documentationUrl?: string;\n } | null;\n}\n","{\n \"name\": \"@supadata/js\",\n \"version\": \"1.2.0\",\n \"description\": \"TypeScript / JavaScript SDK for Supadata API\",\n \"homepage\": \"https://supadata.ai\",\n \"repository\": \"https://github.com/supadata-ai/js\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.mjs\"\n }\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"tsup\",\n \"test\": \"node --experimental-vm-modules node_modules/jest/bin/jest.js\",\n \"prepare\": \"npm run build\",\n \"format\": \"prettier --write \\\"src/**/*.{js,ts}\\\"\",\n \"format:check\": \"prettier --check \\\"src/**/*.{js,ts}\\\"\"\n },\n \"files\": [\n \"dist\",\n \"README.md\"\n ],\n \"keywords\": [\n \"supadata\",\n \"api\",\n \"sdk\",\n \"typescript\",\n \"youtube\",\n \"transcript\",\n \"web scraping\"\n ],\n \"author\": \"Supadata AI\",\n \"license\": \"MIT\",\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.14\",\n \"@types/node\": \"^22.10.10\",\n \"jest\": \"^29.7.0\",\n \"jest-fetch-mock\": \"^3.0.3\",\n \"prettier\": \"^3.4.2\",\n \"ts-jest\": \"^29.2.5\",\n \"typescript\": \"^5.7.3\",\n \"tsup\": \"^8.3.6\"\n }\n}","import { SupadataConfig, SupadataError } from './types.js';\n// @ts-expect-error: Non-TS import for version from package.json\nimport pkg from '../package.json';\n\nconst USER_AGENT = `supadata-js/${pkg.version}`;\n\nexport class BaseClient {\n protected config: SupadataConfig;\n\n constructor(config: SupadataConfig) {\n this.config = config;\n }\n\n protected async fetch<T>(\n endpoint: string,\n params: Record<string, any> = {},\n method: 'GET' | 'POST' = 'GET'\n ): Promise<T> {\n const baseUrl = this.config.baseUrl || 'https://api.supadata.ai/v1';\n let url = `${baseUrl}${\n endpoint.startsWith('/') ? endpoint : `/${endpoint}`\n }`;\n\n if (method === 'GET' && Object.keys(params).length > 0) {\n const queryParams = new URLSearchParams();\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n queryParams.append(key, String(value));\n }\n });\n url += `?${queryParams.toString()}`;\n }\n\n return this.fetchUrl<T>(url, method, params);\n }\n\n protected async fetchUrl<T>(\n url: string,\n method: 'GET' | 'POST' = 'GET',\n body?: Record<string, any>\n ): Promise<T> {\n const options: RequestInit = {\n method,\n headers: {\n 'x-api-key': this.config.apiKey,\n 'Content-Type': 'application/json',\n 'User-Agent': USER_AGENT,\n },\n };\n\n if (method === 'POST' && body) {\n options.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, options);\n\n const contentType = response.headers.get('content-type');\n\n if (!response.ok) {\n // Handle standard API errors\n if (contentType?.includes('application/json')) {\n const errorData = await response.json();\n throw new SupadataError(errorData);\n } else {\n // Fallback for unexpected non-JSON errors\n throw new SupadataError({\n error: 'internal-error',\n message: 'Unexpected error response format',\n details: await response.text(),\n });\n }\n }\n\n try {\n if (!contentType?.includes('application/json')) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Invalid response format',\n details: 'Expected JSON response but received different content type',\n });\n }\n\n return (await response.json()) as T;\n } catch (error) {\n throw new SupadataError({\n error: 'internal-error',\n message: 'Failed to parse response',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport {\n SupadataError,\n Transcript,\n TranslatedTranscript,\n YoutubeBatchJob,\n YoutubeBatchResults,\n YoutubeChannel,\n YoutubePlaylist,\n YoutubeTranscriptBatchRequest,\n YoutubeVideo,\n YoutubeVideoBatchRequest,\n} from '../types.js';\n\n/**\n * Ensures exactly one property from the specified keys is provided.\n * @example\n * // Valid: { url: \"...\" } or { videoId: \"...\" }\n * // Invalid: {} or { url: \"...\", videoId: \"...\" }\n */\ntype ExactlyOne<T, Keys extends keyof T> = {\n [K in Keys]: { [P in K]-?: T[P] } & { [P in Exclude<Keys, K>]?: never };\n}[Keys] &\n Omit<T, Keys>;\n\nexport type TranscriptParams = {\n lang?: string;\n text?: boolean;\n} & ExactlyOne<{ videoId: string; url: string }, 'videoId' | 'url'>;\n\nexport interface TranslateParams extends Omit<TranscriptParams, 'lang'> {\n lang: string;\n}\n\nexport interface ResourceParams {\n id: string;\n}\n\nexport interface ChannelVideosParams extends ResourceParams {\n limit?: number;\n type?: 'video' | 'short' | 'live' | 'all';\n}\n\nexport interface PlaylistVideosParams extends ResourceParams {\n limit?: number;\n}\n\nexport interface VideoIds {\n videoIds: string[];\n shortIds: string[];\n liveIds: string[];\n}\n\nexport class YouTubeService extends BaseClient {\n /**\n * Handles YouTube Transcript operations.\n */\n transcript = Object.assign(\n /**\n * Fetches a transcript for a YouTube video.\n * @param params - Parameters for fetching the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The language code for the transcript (optional)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a Transcript object\n */\n async (params: TranscriptParams): Promise<Transcript> => {\n return this.fetch<Transcript>('/youtube/transcript', params);\n },\n {\n /**\n * Batch fetches transcripts for multiple YouTube videos.\n * @param params - Parameters for the transcript batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch transcripts for\n * @param params.lang - The language code for the transcripts (optional)\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeTranscriptBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/transcript/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube video operations.\n */\n video = Object.assign(\n /**\n * Fetches a YouTube video based on the provided parameters.\n * @param params - The parameters required to fetch the YouTube video\n * @param params.id - The YouTube video ID\n * @returns A promise that resolves to a YoutubeVideo object\n */\n async (params: ResourceParams): Promise<YoutubeVideo> => {\n return this.fetch<YoutubeVideo>('/youtube/video', params);\n },\n {\n /**\n * Batch fetches metadata for multiple YouTube videos.\n * @param params - Parameters for the video metadata batch job\n * @param params.videoIds - Array of YouTube video IDs to fetch metadata for\n * @param params.limit - Maximum number of videos to process (optional, default: 10, max: 5000)\n * @returns A promise that resolves to a YoutubeBatchJob object with the job ID\n */\n batch: async (\n params: YoutubeVideoBatchRequest\n ): Promise<YoutubeBatchJob> => {\n this.validateBatchLimit(params);\n return this.fetch<YoutubeBatchJob>(\n '/youtube/video/batch',\n params,\n 'POST'\n );\n },\n }\n );\n\n /**\n * Handles YouTube channel operations.\n */\n channel = Object.assign(\n /**\n * Fetches YouTube channel information.\n * @param params - The parameters required to fetch the YouTube channel information\n * @param params.id - The YouTube channel ID\n * @returns A promise that resolves to a YoutubeChannel object containing the channel information\n */\n async (params: ResourceParams): Promise<YoutubeChannel> => {\n return this.fetch<YoutubeChannel>('/youtube/channel', params);\n },\n {\n /**\n * Fetches the videos of a YouTube channel.\n * @param params - The parameters required to fetch the YouTube channel videos\n * @param params.id - The YouTube channel ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @param params.type - The type of videos to fetch ('video', 'short', 'live', or 'all', default: 'video')\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: ChannelVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/channel/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube playlist operations.\n */\n playlist = Object.assign(\n /**\n * Fetches a YouTube playlist.\n * @param params - The parameters required to fetch the playlist\n * @param params.id - The YouTube playlist ID\n * @returns A promise that resolves to a YoutubePlaylist object\n */\n async (params: ResourceParams): Promise<YoutubePlaylist> => {\n return this.fetch<YoutubePlaylist>('/youtube/playlist', params);\n },\n {\n /**\n * Fetches the videos of a YouTube playlist.\n * @param params - The parameters required to fetch the playlist videos\n * @param params.id - The YouTube playlist ID\n * @param params.limit - The maximum number of videos to fetch (default: 30, max: 5000)\n * @returns A promise that resolves to an object containing arrays of video IDs, short IDs, and live IDs\n * @throws {SupadataError} If the limit is invalid (less than 1 or greater than 5000)\n */\n videos: async (params: PlaylistVideosParams): Promise<VideoIds> => {\n this.validateLimit(params);\n return this.fetch<VideoIds>('/youtube/playlist/videos', params);\n },\n }\n );\n\n /**\n * Handles YouTube batch operations.\n */\n batch = {\n /**\n * Retrieves the status and results of a batch job.\n * @param jobId - The ID of the batch job\n * @returns A promise that resolves to the YoutubeBatchResults containing job status and results\n * @throws {SupadataError} If jobId is not provided\n */\n getBatchResults: async (jobId: string): Promise<YoutubeBatchResults> => {\n if (!jobId) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Missing jobId',\n details: 'The jobId parameter is required to get batch results.',\n });\n }\n return this.fetch<YoutubeBatchResults>(`/youtube/batch/${jobId}`);\n },\n };\n\n /**\n * Translates a YouTube video transcript to a specified language.\n * @param params - Parameters for translating the transcript\n * @param params.videoId - The YouTube video ID (mutually exclusive with url)\n * @param params.url - The YouTube video URL (mutually exclusive with videoId)\n * @param params.lang - The target language code for translation\n * @param params.text - Whether to return only the text content (optional)\n * @returns A promise that resolves to a TranslatedTranscript object\n */\n translate = async (\n params: TranslateParams\n ): Promise<TranslatedTranscript> => {\n return this.fetch<TranslatedTranscript>(\n '/youtube/transcript/translate',\n params\n );\n };\n\n private validateLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n\n // Add a specific validator for batch limits as per documentation (Max: 5000, Default: 10)\n private validateBatchLimit(params: { limit?: number }) {\n if (\n params.limit != undefined &&\n params.limit != null &&\n (params.limit < 1 || params.limit > 5000)\n ) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Invalid limit for batch operation.',\n details: 'The limit must be between 1 and 5000.',\n });\n }\n }\n}\n","import { BaseClient } from '../client.js';\nimport { CrawlJob, CrawlRequest, JobId, Scrape, SiteMap } from '../types.js';\n\nexport class WebService extends BaseClient {\n /**\n * Extract content from any web page to Markdown format.\n *\n * @param url - URL of the webpage to scrape\n * @returns A promise that resolves to the scraped content\n */\n async scrape(url: string): Promise<Scrape> {\n return this.fetch<Scrape>('/web/scrape', { url });\n }\n\n /**\n * Extract all links found on a webpage.\n *\n * @param url - URL of the webpage to map\n * @returns A promise that resolves to a map of URLs found on the page\n */\n async map(url: string): Promise<SiteMap> {\n return this.fetch<SiteMap>('/web/map', { url });\n }\n\n /**\n * Create a crawl job to extract content from all pages on a website.\n *\n * @param request - Crawl request parameters\n * @param request.url - URL of the website to crawl\n * @param request.limit - Maximum number of pages to crawl (default: 100, max: 5000)\n * @returns A promise that resolves to the crawl job id\n */\n async crawl(request: CrawlRequest): Promise<JobId> {\n return this.fetch<JobId>('/web/crawl', request, 'POST');\n }\n\n /**\n * Get the status and results of a crawl job.\n * Automatically handles pagination to retrieve all pages from the crawl.\n *\n * @param jobId - The ID of the crawl job to retrieve\n * @returns A promise that resolves to the complete crawl job results\n */\n async getCrawlResults(jobId: string): Promise<CrawlJob> {\n let response: CrawlJob;\n let pages: Scrape[] = [];\n let nextUrl: string | undefined;\n\n do {\n response = await (nextUrl\n ? this.fetchUrl<CrawlJob>(nextUrl)\n : this.fetch<CrawlJob>(`/web/crawl/${jobId}`));\n\n if (response.pages) {\n pages = [...pages, ...response.pages];\n }\n nextUrl = response.next;\n } while (nextUrl);\n\n return response;\n }\n}\n","import { BaseClient } from '../client.js';\nimport {\n JobId,\n JobResult,\n SupadataError,\n Transcript,\n TranscriptOrJobId,\n} from '../types.js';\n\nexport interface GeneralTranscriptParams {\n url: string;\n lang?: string;\n text?: boolean;\n chunkSize?: number;\n mode?: 'native' | 'auto' | 'generate';\n}\n\nexport class TranscriptService extends BaseClient {\n /**\n * Get transcript from a supported video platform or file URL.\n * @param params - Parameters for fetching the transcript\n * @returns A promise that resolves to either a Transcript or JobId for async processing\n */\n get = async (params: GeneralTranscriptParams): Promise<TranscriptOrJobId> => {\n return this.fetch<TranscriptOrJobId>('/transcript', params);\n };\n\n /**\n * Get results for a transcript job by job ID.\n * @param jobId - The ID of the transcript job\n * @returns A promise that resolves to the job result containing status and transcript if completed\n * @throws {SupadataError} If jobId is not provided\n */\n getJobStatus = async (jobId: string): Promise<JobResult<Transcript>> => {\n if (!jobId) {\n throw new SupadataError({\n error: 'invalid-request',\n message: 'Missing jobId',\n details:\n 'The jobId parameter is required to get transcript job status.',\n });\n }\n return this.fetch<JobResult<Transcript>>(`/transcript/${jobId}`);\n };\n}\n","import {\n JobResult,\n SupadataConfig,\n Transcript,\n TranscriptOrJobId,\n} from './types.js';\nimport { YouTubeService } from './services/youtube.js';\nimport { WebService } from './services/web.js';\nimport {\n TranscriptService,\n GeneralTranscriptParams,\n} from './services/transcript.js';\n\nexport * from './types.js';\nexport * from './client.js';\nexport * from './services/youtube.js';\nexport * from './services/web.js';\nexport {\n TranscriptService,\n GeneralTranscriptParams,\n} from './services/transcript.js';\n\nexport class Supadata {\n readonly youtube: YouTubeService;\n readonly web: WebService;\n private _transcriptService: TranscriptService;\n\n constructor(config: SupadataConfig) {\n this.youtube = new YouTubeService(config);\n this.web = new WebService(config);\n this._transcriptService = new TranscriptService(config);\n }\n\n /**\n * Get transcript from a supported video platform (YouTube, TikTok, Twitter) or file URL.\n * If the video is too large to return transcript immediately, request returns a job ID.\n */\n transcript = Object.assign(\n async (params: GeneralTranscriptParams): Promise<TranscriptOrJobId> => {\n return this._transcriptService.get(params);\n },\n {\n getJobStatus: (jobId: string): Promise<JobResult<Transcript>> => {\n return this._transcriptService.getJobStatus(jobId);\n },\n }\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supadata/js",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "TypeScript / JavaScript SDK for Supadata API",
5
5
  "homepage": "https://supadata.ai",
6
6
  "repository": "https://github.com/supadata-ai/js",