@supadata/js 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @supadata/ts
2
+
3
+ Official TypeScript/JavaScript SDK for the Supadata API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @supadata/js
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Supadata, Transcript } from "@supadata/js";
15
+
16
+ // Initialize the client
17
+ const supadata = new Supadata({
18
+ apiKey: "YOUR_API_KEY",
19
+ });
20
+
21
+ // Get YouTube transcript
22
+ const transcript = await supadata.youtube.transcript({
23
+ videoId: "VIDEO_ID",
24
+ });
25
+
26
+ // Translate YouTube transcript
27
+ const translated = await supadata.youtube.translate({
28
+ videoId: "VIDEO_ID",
29
+ lang: "es",
30
+ });
31
+
32
+ // Scrape web content
33
+ const webContent = await supadata.web.scrape("https://supadata.ai");
34
+
35
+ // Map website URLs
36
+ const siteMap = await supadata.web.map("https://supadata.ai");
37
+ ```
38
+
39
+ ## Error Handling
40
+
41
+ The SDK throws `SupadataError` for API-related errors. You can catch and handle these errors as follows:
42
+
43
+ ```typescript
44
+ import { SupadataError } from "@supadata/js";
45
+
46
+ try {
47
+ const transcript = await supadata.youtube.transcript({
48
+ videoId: "INVALID_ID",
49
+ });
50
+ } catch (error) {
51
+ if (error instanceof SupadataError) {
52
+ console.error(error.code); // e.g., 'video-not-found'
53
+ console.error(error.title); // Human readable error title
54
+ console.error(error.message); // Detailed error description
55
+ console.error(error.documentationUrl); // Link to error documentation
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## API Reference
61
+
62
+ See the [Documentation](https://supadata.ai/documentation) for more details on all possible parameters and options.
63
+
64
+ ## License
65
+
66
+ MIT
@@ -0,0 +1,12 @@
1
+ import { SupadataConfig, Error } from "./types.js";
2
+ export declare class BaseClient {
3
+ protected config: SupadataConfig;
4
+ constructor(config: SupadataConfig);
5
+ fetch<T>(endpoint: string, params: Record<string, unknown> | object): Promise<T>;
6
+ }
7
+ export declare class SupadataError extends Error {
8
+ code: Error["code"];
9
+ title: string;
10
+ documentationUrl: string;
11
+ constructor(error: Error);
12
+ }
package/dist/client.js ADDED
@@ -0,0 +1,43 @@
1
+ export class BaseClient {
2
+ config;
3
+ constructor(config) {
4
+ this.config = config;
5
+ }
6
+ async fetch(endpoint, params) {
7
+ const baseUrl = this.config.baseUrl || "https://api.supadata.ai/v1";
8
+ let url = `${baseUrl}${endpoint.startsWith("/") ? endpoint : `/${endpoint}`}`;
9
+ if (params) {
10
+ const queryParams = new URLSearchParams();
11
+ Object.entries(params).forEach(([key, value]) => {
12
+ if (value !== undefined && value !== null) {
13
+ queryParams.append(key, String(value));
14
+ }
15
+ });
16
+ url += `?${queryParams.toString()}`;
17
+ }
18
+ const response = await fetch(url, {
19
+ method: "GET",
20
+ headers: {
21
+ "x-api-key": this.config.apiKey,
22
+ "Content-Type": "application/json",
23
+ },
24
+ });
25
+ const data = await response.json();
26
+ if (!response.ok) {
27
+ const error = data;
28
+ throw new SupadataError(error);
29
+ }
30
+ return data;
31
+ }
32
+ }
33
+ export class SupadataError extends Error {
34
+ code;
35
+ title;
36
+ documentationUrl;
37
+ constructor(error) {
38
+ super(error.description);
39
+ this.code = error.code;
40
+ this.title = error.title;
41
+ this.documentationUrl = error.documentationUrl;
42
+ }
43
+ }
@@ -0,0 +1,12 @@
1
+ import { SupadataConfig } from './types.js';
2
+ import { YouTubeService } from './services/youtube.js';
3
+ import { WebService } from './services/web.js';
4
+ export * from './types.js';
5
+ export * from './client.js';
6
+ export * from './services/youtube.js';
7
+ export * from './services/web.js';
8
+ export declare class Supadata {
9
+ readonly youtube: YouTubeService;
10
+ readonly web: WebService;
11
+ constructor(config: SupadataConfig);
12
+ }
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ import { YouTubeService } from './services/youtube.js';
2
+ import { WebService } from './services/web.js';
3
+ export * from './types.js';
4
+ export * from './client.js';
5
+ export * from './services/youtube.js';
6
+ export * from './services/web.js';
7
+ export class Supadata {
8
+ youtube;
9
+ web;
10
+ constructor(config) {
11
+ this.youtube = new YouTubeService(config);
12
+ this.web = new WebService(config);
13
+ }
14
+ }
@@ -0,0 +1,6 @@
1
+ import { BaseClient } from '../client.js';
2
+ import { Scrape, Map } from '../types.js';
3
+ export declare class WebService extends BaseClient {
4
+ scrape(url: string): Promise<Scrape>;
5
+ map(url: string): Promise<Map>;
6
+ }
@@ -0,0 +1,9 @@
1
+ import { BaseClient } from '../client.js';
2
+ export class WebService extends BaseClient {
3
+ async scrape(url) {
4
+ return this.fetch('/web/scrape', { url });
5
+ }
6
+ async map(url) {
7
+ return this.fetch('/web/map', { url });
8
+ }
9
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseClient } from "../client.js";
2
+ import { Transcript, TranslatedTranscript } from "../types.js";
3
+ export interface TranscriptParams {
4
+ videoId: string;
5
+ lang?: string;
6
+ text?: boolean;
7
+ }
8
+ export interface TranslateParams extends TranscriptParams {
9
+ lang: string;
10
+ }
11
+ export declare class YouTubeService extends BaseClient {
12
+ transcript(params: TranscriptParams): Promise<Transcript>;
13
+ translate(params: TranslateParams): Promise<TranslatedTranscript>;
14
+ }
@@ -0,0 +1,9 @@
1
+ import { BaseClient } from "../client.js";
2
+ export class YouTubeService extends BaseClient {
3
+ async transcript(params) {
4
+ return this.fetch("/youtube/transcript", params);
5
+ }
6
+ async translate(params) {
7
+ return this.fetch("/youtube/transcript/translate", params);
8
+ }
9
+ }
@@ -0,0 +1,37 @@
1
+ export interface TranscriptChunk {
2
+ text: string;
3
+ offset: number;
4
+ duration: number;
5
+ lang: string;
6
+ }
7
+ export interface Transcript {
8
+ content: TranscriptChunk[] | string;
9
+ lang: string;
10
+ availableLangs: string[];
11
+ }
12
+ export interface TranslatedTranscript {
13
+ content: TranscriptChunk[] | string;
14
+ lang: string;
15
+ }
16
+ export interface Scrape {
17
+ url: string;
18
+ content: string;
19
+ name: string;
20
+ description: string;
21
+ ogUrl: string;
22
+ countCharacters: number;
23
+ urls: string[];
24
+ }
25
+ export interface Map {
26
+ urls: string[];
27
+ }
28
+ export interface SupadataConfig {
29
+ apiKey: string;
30
+ baseUrl?: string;
31
+ }
32
+ export interface Error {
33
+ code: 'invalid-request' | 'missing-parameters' | 'internal-error' | 'transcript-unavailable' | 'video-not-found' | 'video-id-invalid' | 'youtube-api-error' | 'quota-exceeded' | 'rate-limit-exceeded';
34
+ title: string;
35
+ description: string;
36
+ documentationUrl: string;
37
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@supadata/js",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript / JavaScript SDK for Supadata API",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
18
+ "prepare": "npm run build",
19
+ "format": "prettier --write \"src/**/*.{js,ts}\"",
20
+ "format:check": "prettier --check \"src/**/*.{js,ts}\""
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "keywords": [
27
+ "supadata",
28
+ "api",
29
+ "sdk",
30
+ "typescript",
31
+ "youtube",
32
+ "transcript",
33
+ "web scraping"
34
+ ],
35
+ "author": "Supadata AI",
36
+ "license": "MIT",
37
+ "devDependencies": {
38
+ "@types/jest": "^29.5.14",
39
+ "@types/node": "^22.10.10",
40
+ "jest": "^29.7.0",
41
+ "jest-fetch-mock": "^3.0.3",
42
+ "prettier": "^3.4.2",
43
+ "ts-jest": "^29.2.5",
44
+ "typescript": "^5.7.3"
45
+ }
46
+ }