stophy 0.1.1 → 0.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/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ type ErrorResponse = {
8
8
  /**
9
9
  * Machine-readable error code.
10
10
  */
11
- code?: 'UNAUTHORIZED' | 'INSUFFICIENT_CREDITS' | 'BAD_REQUEST' | 'INVALID_INPUT' | 'NOT_FOUND' | 'CONCURRENCY_LIMITED' | 'INTERNAL_ERROR';
11
+ code?: "UNAUTHORIZED" | "INSUFFICIENT_CREDITS" | "BAD_REQUEST" | "INVALID_INPUT" | "NOT_FOUND" | "CONCURRENCY_LIMITED" | "INTERNAL_ERROR";
12
12
  /**
13
13
  * Human-readable error message.
14
14
  */
@@ -45,7 +45,7 @@ type TranscriptResult = {
45
45
  };
46
46
  type VideoDetails = {
47
47
  id: string;
48
- type?: 'video';
48
+ type?: "video";
49
49
  videoUrl: string;
50
50
  title: string | null;
51
51
  author?: string | null;
@@ -65,7 +65,7 @@ type VideoDetails = {
65
65
  };
66
66
  type RelatedVideo = {
67
67
  id: string;
68
- type?: 'video';
68
+ type?: "video";
69
69
  videoUrl: string;
70
70
  title?: string | null;
71
71
  author?: string | null;
@@ -131,7 +131,7 @@ type LiveChatData = {
131
131
  */
132
132
  type VideoData = VideoDetailsData | TranscriptResult | CommentsData | LiveChatData;
133
133
  type SearchVideo = {
134
- type: 'video';
134
+ type: "video";
135
135
  id: string;
136
136
  videoUrl: string;
137
137
  title: string;
@@ -151,7 +151,7 @@ type SearchVideo = {
151
151
  thumbnails: Array<Thumbnail>;
152
152
  };
153
153
  type SearchShort = {
154
- type: 'short';
154
+ type: "short";
155
155
  id: string;
156
156
  shortUrl: string;
157
157
  title: string;
@@ -168,7 +168,7 @@ type SearchShort = {
168
168
  thumbnails: Array<Thumbnail>;
169
169
  };
170
170
  type SearchPlaylist = {
171
- type: 'playlist';
171
+ type: "playlist";
172
172
  id: string;
173
173
  playlistUrl: string;
174
174
  title: string;
@@ -179,7 +179,7 @@ type SearchPlaylist = {
179
179
  thumbnails: Array<Thumbnail>;
180
180
  };
181
181
  type SearchChannel = {
182
- type: 'channel';
182
+ type: "channel";
183
183
  id: string;
184
184
  channelUrl: string;
185
185
  name: string;
@@ -191,13 +191,13 @@ type SearchChannel = {
191
191
  thumbnails: Array<Thumbnail>;
192
192
  };
193
193
  type SearchItem = ({
194
- type?: 'video';
194
+ type?: "video";
195
195
  } & SearchVideo) | ({
196
- type?: 'short';
196
+ type?: "short";
197
197
  } & SearchShort) | ({
198
- type?: 'playlist';
198
+ type?: "playlist";
199
199
  } & SearchPlaylist) | ({
200
- type?: 'channel';
200
+ type?: "channel";
201
201
  } & SearchChannel);
202
202
  type SearchData = {
203
203
  items: Array<SearchItem>;
@@ -254,7 +254,7 @@ type ChannelData = {
254
254
  };
255
255
  type PlaylistMeta = {
256
256
  id: string;
257
- type?: 'playlist';
257
+ type?: "playlist";
258
258
  playlistUrl: string;
259
259
  title?: string | null;
260
260
  author?: string | null;
@@ -265,7 +265,7 @@ type PlaylistMeta = {
265
265
  };
266
266
  type PlaylistItem = {
267
267
  id: string;
268
- type?: 'video';
268
+ type?: "video";
269
269
  videoUrl: string;
270
270
  title?: string | null;
271
271
  author?: string | null;
@@ -332,7 +332,7 @@ type GetVideoData = {
332
332
  /**
333
333
  * The type of data to retrieve.
334
334
  */
335
- type: 'details' | 'transcript' | 'comments' | 'replies' | 'livechat';
335
+ type: "details" | "transcript" | "comments" | "replies" | "livechat";
336
336
  /**
337
337
  * Full YouTube video URL. Not required when type is replies.
338
338
  */
@@ -340,11 +340,11 @@ type GetVideoData = {
340
340
  /**
341
341
  * Comment sort order. Only applies when type is comments.
342
342
  */
343
- sortBy?: 'latest' | 'top';
343
+ sortBy?: "latest" | "top";
344
344
  /**
345
345
  * Live chat mode. Only applies when type is livechat: 'top' = Top chat (moderated, default), 'live' = all messages. Applied on the first call; later polls keep the chosen mode.
346
346
  */
347
- chatType?: 'top' | 'live';
347
+ chatType?: "top" | "live";
348
348
  /**
349
349
  * Pagination token. Required when type is replies (use the repliesToken from a comment item); for livechat, pass the continuationToken from a previous livechat response to poll for new messages.
350
350
  */
@@ -352,7 +352,7 @@ type GetVideoData = {
352
352
  };
353
353
  path?: never;
354
354
  query?: never;
355
- url: '/v1/video';
355
+ url: "/v1/video";
356
356
  };
357
357
  type GetVideoErrors = {
358
358
  /**
@@ -385,7 +385,7 @@ type GetVideoResponses = {
385
385
  success: true;
386
386
  requestId: string;
387
387
  data: VideoData;
388
- cacheState: 'hit' | 'miss';
388
+ cacheState: "hit" | "miss";
389
389
  creditsUsed: number;
390
390
  creditsRemaining: number;
391
391
  };
@@ -400,23 +400,23 @@ type SearchVideosData = {
400
400
  /**
401
401
  * Filter by content type.
402
402
  */
403
- type?: 'video' | 'short' | 'channel' | 'playlist' | 'movie';
403
+ type?: "video" | "short" | "channel" | "playlist" | "movie";
404
404
  /**
405
405
  * Sort order. Defaults to relevance.
406
406
  */
407
- sortBy?: 'relevance' | 'popularity' | 'date' | 'rating';
407
+ sortBy?: "relevance" | "popularity" | "date" | "rating";
408
408
  /**
409
409
  * Filter by upload date.
410
410
  */
411
- uploadDate?: 'today' | 'week' | 'month' | 'year';
411
+ uploadDate?: "today" | "week" | "month" | "year";
412
412
  /**
413
413
  * Duration filter. Not applicable when type is short.
414
414
  */
415
- duration?: 'short' | 'medium' | 'long';
415
+ duration?: "short" | "medium" | "long";
416
416
  /**
417
417
  * Filter by video features.
418
418
  */
419
- features?: Array<'live' | '4k' | 'hd' | 'subtitles' | 'creativeCommons' | '360' | 'vr180' | '3d' | 'hdr' | 'location' | 'purchased'>;
419
+ features?: Array<"live" | "4k" | "hd" | "subtitles" | "creativeCommons" | "360" | "vr180" | "3d" | "hdr" | "location" | "purchased">;
420
420
  /**
421
421
  * Token from a previous response to fetch the next page.
422
422
  */
@@ -424,7 +424,7 @@ type SearchVideosData = {
424
424
  };
425
425
  path?: never;
426
426
  query?: never;
427
- url: '/v1/search';
427
+ url: "/v1/search";
428
428
  };
429
429
  type SearchVideosErrors = {
430
430
  /**
@@ -457,7 +457,7 @@ type SearchVideosResponses = {
457
457
  success: true;
458
458
  requestId: string;
459
459
  data: SearchData;
460
- cacheState: 'hit' | 'miss';
460
+ cacheState: "hit" | "miss";
461
461
  creditsUsed: number;
462
462
  creditsRemaining: number;
463
463
  };
@@ -472,7 +472,7 @@ type GetChannelData = {
472
472
  /**
473
473
  * Content tab to fetch. Defaults to video.
474
474
  */
475
- tab?: 'video' | 'short' | 'playlist' | 'about';
475
+ tab?: "video" | "short" | "playlist" | "about";
476
476
  /**
477
477
  * Token from a previous response to fetch the next page.
478
478
  */
@@ -480,11 +480,11 @@ type GetChannelData = {
480
480
  /**
481
481
  * Sort order for the selected tab.
482
482
  */
483
- sortBy?: 'latest' | 'popular' | 'oldest';
483
+ sortBy?: "latest" | "popular" | "oldest";
484
484
  };
485
485
  path?: never;
486
486
  query?: never;
487
- url: '/v1/channel';
487
+ url: "/v1/channel";
488
488
  };
489
489
  type GetChannelErrors = {
490
490
  /**
@@ -517,7 +517,7 @@ type GetChannelResponses = {
517
517
  success: true;
518
518
  requestId: string;
519
519
  data: ChannelData;
520
- cacheState: 'hit' | 'miss';
520
+ cacheState: "hit" | "miss";
521
521
  creditsUsed: number;
522
522
  creditsRemaining: number;
523
523
  };
@@ -536,7 +536,7 @@ type GetPlaylistData = {
536
536
  };
537
537
  path?: never;
538
538
  query?: never;
539
- url: '/v1/playlist';
539
+ url: "/v1/playlist";
540
540
  };
541
541
  type GetPlaylistErrors = {
542
542
  /**
@@ -569,7 +569,7 @@ type GetPlaylistResponses = {
569
569
  success: true;
570
570
  requestId: string;
571
571
  data: PlaylistData;
572
- cacheState: 'hit' | 'miss';
572
+ cacheState: "hit" | "miss";
573
573
  creditsUsed: number;
574
574
  creditsRemaining: number;
575
575
  };
@@ -592,7 +592,7 @@ type GetSuggestionsData = {
592
592
  */
593
593
  gl?: string;
594
594
  };
595
- url: '/v1/suggest';
595
+ url: "/v1/suggest";
596
596
  };
597
597
  type GetSuggestionsErrors = {
598
598
  /**
@@ -621,7 +621,7 @@ type GetSuggestionsResponses = {
621
621
  success: true;
622
622
  requestId: string;
623
623
  data: SuggestData;
624
- cacheState: 'hit' | 'miss';
624
+ cacheState: "hit" | "miss";
625
625
  creditsUsed: number;
626
626
  creditsRemaining: number;
627
627
  };
@@ -631,7 +631,7 @@ type GetCreditsData = {
631
631
  body?: never;
632
632
  path?: never;
633
633
  query?: never;
634
- url: '/v1/credits';
634
+ url: "/v1/credits";
635
635
  };
636
636
  type GetCreditsErrors = {
637
637
  /**
@@ -658,7 +658,7 @@ type GetLogsData = {
658
658
  /**
659
659
  * Time window: 'today', the last 7 days, or the last 30 days.
660
660
  */
661
- days?: 'today' | '7' | '30';
661
+ days?: "today" | "7" | "30";
662
662
  /**
663
663
  * Filter logs to a single endpoint, e.g. /video.
664
664
  */
@@ -668,7 +668,7 @@ type GetLogsData = {
668
668
  */
669
669
  page?: number;
670
670
  };
671
- url: '/v1/logs';
671
+ url: "/v1/logs";
672
672
  };
673
673
  type GetLogsErrors = {
674
674
  /**
@@ -695,13 +695,13 @@ type GetUsageData = {
695
695
  /**
696
696
  * Time window: 'today', the last 7 days, or the last 30 days.
697
697
  */
698
- days?: 'today' | '7' | '30';
698
+ days?: "today" | "7" | "30";
699
699
  /**
700
700
  * Timezone offset in minutes used to bucket activity into days. Defaults to UTC.
701
701
  */
702
702
  tz?: string;
703
703
  };
704
- url: '/v1/usage';
704
+ url: "/v1/usage";
705
705
  };
706
706
  type GetUsageErrors = {
707
707
  /**
@@ -722,57 +722,42 @@ type GetUsageResponses = {
722
722
  };
723
723
  type GetUsageResponse = GetUsageResponses[keyof GetUsageResponses];
724
724
  type ClientOptions = {
725
- baseUrl: 'https://api.stophy.dev' | (string & {});
725
+ baseUrl: "https://api.stophy.dev" | (string & {});
726
726
  };
727
727
 
728
- /** A video response with `data` narrowed to the shape for a given request `type`. */
729
- type VideoResponseFor<D> = Omit<GetVideoResponse, "data"> & {
730
- data: D;
728
+ type ChannelBody = GetChannelData["body"];
729
+ type ChannelOptions = Omit<ChannelBody, "channelUrl">;
730
+
731
+ type PlaylistBody = GetPlaylistData["body"];
732
+ type PlaylistOptions = Omit<PlaylistBody, "playlistUrl">;
733
+
734
+ type SearchBody = SearchVideosData["body"];
735
+ type SearchOptions = Omit<SearchBody, "q">;
736
+
737
+ type SuggestQuery = GetSuggestionsData["query"];
738
+ type SuggestOptions = Omit<SuggestQuery, "q">;
739
+
740
+ type VideoResponseFor<T> = Omit<GetVideoResponse, "data"> & {
741
+ data: T;
731
742
  };
743
+ type CommentsOptions = Pick<GetVideoData["body"], "sortBy" | "continuationToken">;
744
+ type LiveChatOptions = Pick<GetVideoData["body"], "chatType" | "continuationToken">;
732
745
 
733
746
  interface StophyOptions {
734
- /** API key from your dashboard. Sent as `Authorization: Bearer <key>`. */
735
- apiKey: string;
736
- /** Defaults to `https://api.stophy.dev`. */
747
+ /** Defaults to `STOPHY_API_KEY`. */
748
+ apiKey?: string;
749
+ /** Defaults to `STOPHY_BASE_URL` or `https://api.stophy.dev`. */
737
750
  baseUrl?: string;
738
- /** Bring your own `fetch` (handy for tests or non-global runtimes). */
739
751
  fetch?: typeof globalThis.fetch;
740
- /** Sent with every request. */
741
752
  headers?: Record<string, string>;
742
- /**
743
- * Retry attempts for transient failures (network errors and
744
- * 429/500/502/503/504). Set to `0` to disable. Defaults to `2`.
745
- */
746
753
  maxRetries?: number;
747
- /** Base delay for backoff, in ms. Defaults to `500`. */
748
754
  retryInitialDelayMs?: number;
749
755
  }
750
- /** Thrown when the API responds with a non-2xx status. */
751
- declare class StophyError extends Error {
752
- readonly code?: ErrorResponse["code"];
753
- readonly status: number;
754
- readonly requestId?: string;
755
- readonly details?: unknown;
756
- constructor(message: string, opts: {
757
- status: number;
758
- code?: ErrorResponse["code"];
759
- requestId?: string;
760
- details?: unknown;
761
- });
762
- }
763
- /**
764
- * Stophy API client — YouTube context API for AI agents.
765
- *
766
- * ```ts
767
- * const stophy = new Stophy({ apiKey: process.env.STOPHY_API_KEY! });
768
- * const { data } = await stophy.video({ type: "transcript", videoUrl });
769
- * ```
770
- */
756
+ type StophyClientInput = StophyOptions | string;
757
+ /** Typed client for the Stophy API. */
771
758
  declare class Stophy {
772
- /** The underlying fetch client, if you need lower-level access. */
773
759
  readonly client: Client;
774
- constructor(options: StophyOptions);
775
- /** Video details, transcript, comments, replies, or live chat — pick with `type`. */
760
+ constructor(input?: StophyClientInput);
776
761
  video(body: GetVideoData["body"] & {
777
762
  type: "details";
778
763
  }): Promise<VideoResponseFor<VideoDetailsData>>;
@@ -786,20 +771,36 @@ declare class Stophy {
786
771
  type: "livechat";
787
772
  }): Promise<VideoResponseFor<LiveChatData>>;
788
773
  video(body: GetVideoData["body"]): Promise<GetVideoResponse>;
789
- /** Search YouTube, optionally filtered by type, sort, date, duration, and features. */
774
+ videoDetails(videoUrl: string): Promise<VideoResponseFor<VideoDetailsData>>;
775
+ transcript(videoUrl: string): Promise<VideoResponseFor<TranscriptResult>>;
776
+ comments(videoUrl: string, options?: CommentsOptions): Promise<VideoResponseFor<CommentsData>>;
777
+ replies(continuationToken: string): Promise<VideoResponseFor<CommentsData>>;
778
+ liveChat(videoUrl: string, options?: LiveChatOptions): Promise<VideoResponseFor<LiveChatData>>;
790
779
  search(body: SearchVideosData["body"]): Promise<SearchVideosResponse>;
791
- /** Channel metadata and content. Switch sections with `tab`. */
780
+ search(query: string, options?: SearchOptions): Promise<SearchVideosResponse>;
792
781
  channel(body: GetChannelData["body"]): Promise<GetChannelResponse>;
793
- /** Playlist items. Page through long playlists with `continuationToken`. */
782
+ channel(channelUrl: string, options?: ChannelOptions): Promise<GetChannelResponse>;
794
783
  playlist(body: GetPlaylistData["body"]): Promise<GetPlaylistResponse>;
795
- /** Search autocomplete suggestions. */
784
+ playlist(playlistUrl: string, options?: PlaylistOptions): Promise<GetPlaylistResponse>;
796
785
  suggest(query: GetSuggestionsData["query"]): Promise<GetSuggestionsResponse>;
797
- /** Your current credit balance. */
786
+ suggest(query: string, options?: SuggestOptions): Promise<GetSuggestionsResponse>;
798
787
  credits(): Promise<GetCreditsResponse>;
799
- /** Recent API request logs. */
800
788
  logs(query?: GetLogsData["query"]): Promise<GetLogsResponse>;
801
- /** Daily credit and request counts. */
802
789
  usage(query?: GetUsageData["query"]): Promise<GetUsageResponse>;
803
790
  }
804
791
 
805
- export { type ChannelData, type ChannelLink, type ChannelProfile, type ClientOptions, type Comment, type CommentsData, type ContentItem, type CreditsData, type EmptyState, type ErrorResponse, type GetChannelData, type GetChannelError, type GetChannelErrors, type GetChannelResponse, type GetChannelResponses, type GetCreditsData, type GetCreditsError, type GetCreditsErrors, type GetCreditsResponse, type GetCreditsResponses, type GetLogsData, type GetLogsError, type GetLogsErrors, type GetLogsResponse, type GetLogsResponses, type GetPlaylistData, type GetPlaylistError, type GetPlaylistErrors, type GetPlaylistResponse, type GetPlaylistResponses, type GetSuggestionsData, type GetSuggestionsError, type GetSuggestionsErrors, type GetSuggestionsResponse, type GetSuggestionsResponses, type GetUsageData, type GetUsageError, type GetUsageErrors, type GetUsageResponse, type GetUsageResponses, type GetVideoData, type GetVideoError, type GetVideoErrors, type GetVideoResponse, type GetVideoResponses, type LiveChatData, type LiveChatMessage, type LogEntry, type LogsData, type PlaylistData, type PlaylistItem, type PlaylistMeta, type RelatedVideo, type SearchChannel, type SearchData, type SearchItem, type SearchPlaylist, type SearchShort, type SearchVideo, type SearchVideosData, type SearchVideosError, type SearchVideosErrors, type SearchVideosResponse, type SearchVideosResponses, Stophy, StophyError, type StophyOptions, type SuggestData, type Thumbnail, type TranscriptLanguage, type TranscriptResult, type TranscriptSegment, type UsageData, type UsageItem, type VideoData, type VideoDetails, type VideoDetailsData, Stophy as default };
792
+ /** Thrown when the Stophy API responds with a non-success status. */
793
+ declare class StophyError extends Error {
794
+ readonly code?: ErrorResponse["code"];
795
+ readonly status: number;
796
+ readonly requestId?: string;
797
+ readonly details?: unknown;
798
+ constructor(message: string, options: {
799
+ status: number;
800
+ code?: ErrorResponse["code"];
801
+ requestId?: string;
802
+ details?: unknown;
803
+ });
804
+ }
805
+
806
+ export { type ChannelData, type ChannelLink, type ChannelOptions, type ChannelProfile, type ClientOptions, type Comment, type CommentsData, type CommentsOptions, type ContentItem, type CreditsData, type EmptyState, type ErrorResponse, type GetChannelData, type GetChannelError, type GetChannelErrors, type GetChannelResponse, type GetChannelResponses, type GetCreditsData, type GetCreditsError, type GetCreditsErrors, type GetCreditsResponse, type GetCreditsResponses, type GetLogsData, type GetLogsError, type GetLogsErrors, type GetLogsResponse, type GetLogsResponses, type GetPlaylistData, type GetPlaylistError, type GetPlaylistErrors, type GetPlaylistResponse, type GetPlaylistResponses, type GetSuggestionsData, type GetSuggestionsError, type GetSuggestionsErrors, type GetSuggestionsResponse, type GetSuggestionsResponses, type GetUsageData, type GetUsageError, type GetUsageErrors, type GetUsageResponse, type GetUsageResponses, type GetVideoData, type GetVideoError, type GetVideoErrors, type GetVideoResponse, type GetVideoResponses, type LiveChatData, type LiveChatMessage, type LiveChatOptions, type LogEntry, type LogsData, type PlaylistData, type PlaylistItem, type PlaylistMeta, type PlaylistOptions, type RelatedVideo, type SearchChannel, type SearchData, type SearchItem, type SearchOptions, type SearchPlaylist, type SearchShort, type SearchVideo, type SearchVideosData, type SearchVideosError, type SearchVideosErrors, type SearchVideosResponse, type SearchVideosResponses, Stophy, type StophyClientInput, StophyError, type StophyOptions, type SuggestData, type SuggestOptions, type Thumbnail, type TranscriptLanguage, type TranscriptResult, type TranscriptSegment, type UsageData, type UsageItem, type VideoData, type VideoDetails, type VideoDetailsData, Stophy as default };