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/README.md +25 -18
- package/dist/index.cjs +180 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -84
- package/dist/index.d.ts +85 -84
- package/dist/index.js +180 -85
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createClient, createConfig } from '@hey-api/client-fetch';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
var client = createClient(
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
// src/generated/client.gen.ts
|
|
4
|
+
var client = createClient(
|
|
5
|
+
createConfig({
|
|
6
|
+
baseUrl: "https://api.stophy.dev"
|
|
7
|
+
})
|
|
8
|
+
);
|
|
7
9
|
|
|
8
10
|
// src/generated/sdk.gen.ts
|
|
9
11
|
var getVideo = (options) => {
|
|
@@ -119,93 +121,56 @@ var getUsage = (options) => {
|
|
|
119
121
|
});
|
|
120
122
|
};
|
|
121
123
|
|
|
122
|
-
// src/
|
|
124
|
+
// src/errors.ts
|
|
123
125
|
var StophyError = class extends Error {
|
|
124
126
|
code;
|
|
125
127
|
status;
|
|
126
128
|
requestId;
|
|
127
129
|
details;
|
|
128
|
-
constructor(message,
|
|
130
|
+
constructor(message, options) {
|
|
129
131
|
super(message);
|
|
130
132
|
this.name = "StophyError";
|
|
131
|
-
this.status =
|
|
132
|
-
this.code =
|
|
133
|
-
this.requestId =
|
|
134
|
-
this.details =
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var Stophy = class {
|
|
138
|
-
/** The underlying fetch client, if you need lower-level access. */
|
|
139
|
-
client;
|
|
140
|
-
constructor(options) {
|
|
141
|
-
if (!options?.apiKey) {
|
|
142
|
-
throw new Error("Stophy: `apiKey` is required.");
|
|
143
|
-
}
|
|
144
|
-
const baseFetch = options.fetch ?? globalThis.fetch;
|
|
145
|
-
this.client = createClient(
|
|
146
|
-
createConfig({
|
|
147
|
-
baseUrl: options.baseUrl ?? "https://api.stophy.dev",
|
|
148
|
-
auth: () => options.apiKey,
|
|
149
|
-
headers: options.headers,
|
|
150
|
-
fetch: withRetries(
|
|
151
|
-
baseFetch,
|
|
152
|
-
options.maxRetries ?? 2,
|
|
153
|
-
options.retryInitialDelayMs ?? 500
|
|
154
|
-
)
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
async video(body) {
|
|
159
|
-
return unwrap(await getVideo({ client: this.client, body }));
|
|
160
|
-
}
|
|
161
|
-
/** Search YouTube, optionally filtered by type, sort, date, duration, and features. */
|
|
162
|
-
async search(body) {
|
|
163
|
-
return unwrap(await searchVideos({ client: this.client, body }));
|
|
164
|
-
}
|
|
165
|
-
/** Channel metadata and content. Switch sections with `tab`. */
|
|
166
|
-
async channel(body) {
|
|
167
|
-
return unwrap(await getChannel({ client: this.client, body }));
|
|
168
|
-
}
|
|
169
|
-
/** Playlist items. Page through long playlists with `continuationToken`. */
|
|
170
|
-
async playlist(body) {
|
|
171
|
-
return unwrap(await getPlaylist({ client: this.client, body }));
|
|
172
|
-
}
|
|
173
|
-
/** Search autocomplete suggestions. */
|
|
174
|
-
async suggest(query) {
|
|
175
|
-
return unwrap(await getSuggestions({ client: this.client, query }));
|
|
176
|
-
}
|
|
177
|
-
/** Your current credit balance. */
|
|
178
|
-
async credits() {
|
|
179
|
-
return unwrap(await getCredits({ client: this.client }));
|
|
180
|
-
}
|
|
181
|
-
/** Recent API request logs. */
|
|
182
|
-
async logs(query) {
|
|
183
|
-
return unwrap(await getLogs({ client: this.client, query }));
|
|
184
|
-
}
|
|
185
|
-
/** Daily credit and request counts. */
|
|
186
|
-
async usage(query) {
|
|
187
|
-
return unwrap(await getUsage({ client: this.client, query }));
|
|
133
|
+
this.status = options.status;
|
|
134
|
+
this.code = options.code;
|
|
135
|
+
this.requestId = options.requestId;
|
|
136
|
+
this.details = options.details;
|
|
188
137
|
}
|
|
189
138
|
};
|
|
139
|
+
|
|
140
|
+
// src/transport.ts
|
|
141
|
+
var DEFAULT_BASE_URL = "https://api.stophy.dev";
|
|
190
142
|
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
143
|
+
function createTransport(options) {
|
|
144
|
+
const baseFetch = options.fetch ?? globalThis.fetch;
|
|
145
|
+
return createClient(
|
|
146
|
+
createConfig({
|
|
147
|
+
baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
148
|
+
auth: () => options.apiKey,
|
|
149
|
+
headers: options.headers,
|
|
150
|
+
fetch: withRetries(
|
|
151
|
+
baseFetch,
|
|
152
|
+
options.maxRetries ?? 2,
|
|
153
|
+
options.retryInitialDelayMs ?? 500
|
|
154
|
+
)
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
}
|
|
191
158
|
function withRetries(baseFetch, maxRetries, initialDelayMs) {
|
|
192
|
-
if (maxRetries <= 0)
|
|
193
|
-
return baseFetch;
|
|
194
|
-
}
|
|
159
|
+
if (maxRetries <= 0) return baseFetch;
|
|
195
160
|
return async (input, init) => {
|
|
196
161
|
for (let attempt = 0; ; attempt++) {
|
|
197
162
|
const request = input instanceof Request ? input.clone() : input;
|
|
198
163
|
try {
|
|
199
164
|
const response = await baseFetch(request, init);
|
|
200
165
|
if (attempt < maxRetries && RETRYABLE_STATUS.has(response.status)) {
|
|
201
|
-
await sleep(
|
|
166
|
+
await sleep(
|
|
167
|
+
retryAfterMs(response) ?? backoffMs(attempt, initialDelayMs)
|
|
168
|
+
);
|
|
202
169
|
continue;
|
|
203
170
|
}
|
|
204
171
|
return response;
|
|
205
172
|
} catch (error) {
|
|
206
|
-
if (attempt >= maxRetries)
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
173
|
+
if (attempt >= maxRetries) throw error;
|
|
209
174
|
await sleep(backoffMs(attempt, initialDelayMs));
|
|
210
175
|
}
|
|
211
176
|
}
|
|
@@ -217,13 +182,9 @@ function backoffMs(attempt, base) {
|
|
|
217
182
|
}
|
|
218
183
|
function retryAfterMs(response) {
|
|
219
184
|
const header = response.headers.get("retry-after");
|
|
220
|
-
if (!header)
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
185
|
+
if (!header) return null;
|
|
223
186
|
const seconds = Number(header);
|
|
224
|
-
if (!Number.isNaN(seconds))
|
|
225
|
-
return seconds * 1e3;
|
|
226
|
-
}
|
|
187
|
+
if (!Number.isNaN(seconds)) return seconds * 1e3;
|
|
227
188
|
const date = Date.parse(header);
|
|
228
189
|
return Number.isNaN(date) ? null : Math.max(0, date - Date.now());
|
|
229
190
|
}
|
|
@@ -231,19 +192,153 @@ function sleep(ms) {
|
|
|
231
192
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
232
193
|
}
|
|
233
194
|
function unwrap(result) {
|
|
234
|
-
if (result.error
|
|
235
|
-
|
|
236
|
-
|
|
195
|
+
if (result.error === void 0 && result.data !== void 0)
|
|
196
|
+
return result.data;
|
|
197
|
+
const error = result.error ?? {};
|
|
198
|
+
throw new StophyError(
|
|
199
|
+
error.error ?? `Stophy request failed with status ${result.response.status}`,
|
|
200
|
+
{
|
|
237
201
|
status: result.response.status,
|
|
238
|
-
code:
|
|
202
|
+
code: error.code,
|
|
239
203
|
requestId: result.response.headers.get("x-request-id") ?? void 0,
|
|
240
|
-
details:
|
|
241
|
-
}
|
|
204
|
+
details: error.details
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/methods/account.ts
|
|
210
|
+
function credits(client2) {
|
|
211
|
+
return getCredits({ client: client2 }).then(unwrap);
|
|
212
|
+
}
|
|
213
|
+
function logs(client2, query) {
|
|
214
|
+
return getLogs({ client: client2, query }).then(unwrap);
|
|
215
|
+
}
|
|
216
|
+
function usage(client2, query) {
|
|
217
|
+
return getUsage({ client: client2, query }).then(unwrap);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/methods/channel.ts
|
|
221
|
+
function channel(client2, urlOrBody, options = {}) {
|
|
222
|
+
const body = typeof urlOrBody === "string" ? { channelUrl: urlOrBody, ...options } : urlOrBody;
|
|
223
|
+
return getChannel({ client: client2, body }).then(unwrap);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/methods/playlist.ts
|
|
227
|
+
function playlist(client2, urlOrBody, options = {}) {
|
|
228
|
+
const body = typeof urlOrBody === "string" ? { playlistUrl: urlOrBody, ...options } : urlOrBody;
|
|
229
|
+
return getPlaylist({ client: client2, body }).then(unwrap);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/methods/search.ts
|
|
233
|
+
function search(client2, queryOrBody, options = {}) {
|
|
234
|
+
if (typeof queryOrBody === "string" && !queryOrBody.trim()) {
|
|
235
|
+
throw new Error("query cannot be empty");
|
|
236
|
+
}
|
|
237
|
+
const body = typeof queryOrBody === "string" ? { q: queryOrBody, ...options } : queryOrBody;
|
|
238
|
+
return searchVideos({ client: client2, body }).then(unwrap);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/methods/suggest.ts
|
|
242
|
+
function suggest(client2, queryOrOptions, options = {}) {
|
|
243
|
+
if (typeof queryOrOptions === "string" && !queryOrOptions.trim()) {
|
|
244
|
+
throw new Error("query cannot be empty");
|
|
242
245
|
}
|
|
243
|
-
|
|
246
|
+
const query = typeof queryOrOptions === "string" ? { q: queryOrOptions, ...options } : queryOrOptions;
|
|
247
|
+
return getSuggestions({ client: client2, query }).then(unwrap);
|
|
244
248
|
}
|
|
245
|
-
var index_default = Stophy;
|
|
246
249
|
|
|
247
|
-
|
|
250
|
+
// src/methods/video.ts
|
|
251
|
+
async function video(client2, body) {
|
|
252
|
+
return unwrap(await getVideo({ client: client2, body }));
|
|
253
|
+
}
|
|
254
|
+
function videoDetails(client2, videoUrl) {
|
|
255
|
+
return video(client2, { type: "details", videoUrl });
|
|
256
|
+
}
|
|
257
|
+
function transcript(client2, videoUrl) {
|
|
258
|
+
return video(client2, { type: "transcript", videoUrl });
|
|
259
|
+
}
|
|
260
|
+
function comments(client2, videoUrl, options = {}) {
|
|
261
|
+
return video(client2, {
|
|
262
|
+
type: "comments",
|
|
263
|
+
videoUrl,
|
|
264
|
+
...options
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function replies(client2, continuationToken) {
|
|
268
|
+
return video(client2, {
|
|
269
|
+
type: "replies",
|
|
270
|
+
continuationToken
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function liveChat(client2, videoUrl, options = {}) {
|
|
274
|
+
return video(client2, {
|
|
275
|
+
type: "livechat",
|
|
276
|
+
videoUrl,
|
|
277
|
+
...options
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/client.ts
|
|
282
|
+
function env(name) {
|
|
283
|
+
return typeof process === "undefined" ? void 0 : process.env[name];
|
|
284
|
+
}
|
|
285
|
+
var Stophy = class {
|
|
286
|
+
client;
|
|
287
|
+
constructor(input = {}) {
|
|
288
|
+
const options = typeof input === "string" ? { apiKey: input } : input;
|
|
289
|
+
const apiKey = options.apiKey?.trim() || env("STOPHY_API_KEY")?.trim();
|
|
290
|
+
if (!apiKey) {
|
|
291
|
+
throw new Error(
|
|
292
|
+
"Stophy: provide `apiKey` or set the STOPHY_API_KEY environment variable."
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
this.client = createTransport({
|
|
296
|
+
...options,
|
|
297
|
+
apiKey,
|
|
298
|
+
baseUrl: options.baseUrl ?? env("STOPHY_BASE_URL")
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async video(body) {
|
|
302
|
+
return video(this.client, body);
|
|
303
|
+
}
|
|
304
|
+
videoDetails(videoUrl) {
|
|
305
|
+
return videoDetails(this.client, videoUrl);
|
|
306
|
+
}
|
|
307
|
+
transcript(videoUrl) {
|
|
308
|
+
return transcript(this.client, videoUrl);
|
|
309
|
+
}
|
|
310
|
+
comments(videoUrl, options) {
|
|
311
|
+
return comments(this.client, videoUrl, options);
|
|
312
|
+
}
|
|
313
|
+
replies(continuationToken) {
|
|
314
|
+
return replies(this.client, continuationToken);
|
|
315
|
+
}
|
|
316
|
+
liveChat(videoUrl, options) {
|
|
317
|
+
return liveChat(this.client, videoUrl, options);
|
|
318
|
+
}
|
|
319
|
+
async search(queryOrBody, options) {
|
|
320
|
+
return search(this.client, queryOrBody, options);
|
|
321
|
+
}
|
|
322
|
+
async channel(urlOrBody, options) {
|
|
323
|
+
return channel(this.client, urlOrBody, options);
|
|
324
|
+
}
|
|
325
|
+
async playlist(urlOrBody, options) {
|
|
326
|
+
return playlist(this.client, urlOrBody, options);
|
|
327
|
+
}
|
|
328
|
+
async suggest(queryOrOptions, options) {
|
|
329
|
+
return suggest(this.client, queryOrOptions, options);
|
|
330
|
+
}
|
|
331
|
+
credits() {
|
|
332
|
+
return credits(this.client);
|
|
333
|
+
}
|
|
334
|
+
logs(query) {
|
|
335
|
+
return logs(this.client, query);
|
|
336
|
+
}
|
|
337
|
+
usage(query) {
|
|
338
|
+
return usage(this.client, query);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export { Stophy, StophyError, Stophy as default };
|
|
248
343
|
//# sourceMappingURL=index.js.map
|
|
249
344
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generated/client.gen.ts","../src/generated/sdk.gen.ts","../src/index.ts"],"names":["createClient","createConfig"],"mappings":";;;AAeO,IAAM,MAAA,GAAS,aAAa,YAAA,CAA4B;AAAA,EAC3D,OAAA,EAAS;AACb,CAAC,CAAC,CAAA;;;ACOK,IAAM,QAAA,GAAW,CAAuC,OAAA,KAAiD;AAC5G,EAAA,OAAA,CAAQ,OAAA,CAAQ,MAAA,IAAU,MAAA,EAAe,IAAA,CAAoD;AAAA,IACzF,QAAA,EAAU;AAA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CAAO,IAAA;AAChB;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["// This file is auto-generated by @hey-api/openapi-ts\n\nimport type { ClientOptions } from './types.gen';\nimport { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';\n\n/**\n * The `createClientConfig()` function will be called on client initialization\n * and the returned object will become the client's initial configuration.\n *\n * You may want to initialize your client this way instead of calling\n * `setConfig()`. This is useful for example if you're using Next.js\n * to ensure your client always has the correct values.\n */\nexport type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;\n\nexport const client = createClient(createConfig<ClientOptions>({\n baseUrl: 'https://api.stophy.dev'\n}));","// This file is auto-generated by @hey-api/openapi-ts\n\nimport type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';\nimport type { GetVideoData, GetVideoResponse, GetVideoError, SearchVideosData, SearchVideosResponse, SearchVideosError, GetChannelData, GetChannelResponse, GetChannelError, GetPlaylistData, GetPlaylistResponse, GetPlaylistError, GetSuggestionsData, GetSuggestionsResponse, GetSuggestionsError, GetCreditsData, GetCreditsResponse, GetCreditsError, GetLogsData, GetLogsResponse, GetLogsError, GetUsageData, GetUsageResponse, GetUsageError } from './types.gen';\nimport { client as _heyApiClient } from './client.gen';\n\nexport type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {\n /**\n * You can provide a client instance returned by `createClient()` instead of\n * individual options. This might be also useful if you want to implement a\n * custom client.\n */\n client?: Client;\n /**\n * You can pass arbitrary values through the `meta` object. This can be\n * used to access values that aren't defined as part of the SDK function.\n */\n meta?: Record<string, unknown>;\n};\n\n/**\n * Video\n * Fetch video details, transcript, comments, replies, or live chat. Pass type: details for metadata, transcript for timestamped captions, comments for top-level comments, replies for a comment thread (pass the repliesToken from a comment as continuationToken), or livechat for live stream chat messages.\n */\nexport const getVideo = <ThrowOnError extends boolean = false>(options: Options<GetVideoData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).post<GetVideoResponse, GetVideoError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/video',\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options?.headers\n }\n });\n};\n\n/**\n * Search\n * Search YouTube with optional filters for content type, sort order, upload date, duration, and features. Returns paginated results.\n */\nexport const searchVideos = <ThrowOnError extends boolean = false>(options: Options<SearchVideosData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).post<SearchVideosResponse, SearchVideosError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/search',\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options?.headers\n }\n });\n};\n\n/**\n * Channel\n * Retrieve channel metadata and content by channelUrl. Use the tab field to switch between videos, shorts, playlists, and about info.\n */\nexport const getChannel = <ThrowOnError extends boolean = false>(options: Options<GetChannelData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).post<GetChannelResponse, GetChannelError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/channel',\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options?.headers\n }\n });\n};\n\n/**\n * Playlist\n * Retrieve items from a YouTube playlist. Use continuationToken to page through long playlists.\n */\nexport const getPlaylist = <ThrowOnError extends boolean = false>(options: Options<GetPlaylistData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).post<GetPlaylistResponse, GetPlaylistError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/playlist',\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options?.headers\n }\n });\n};\n\n/**\n * Suggest\n * Get YouTube search autocomplete suggestions for a query.\n */\nexport const getSuggestions = <ThrowOnError extends boolean = false>(options: Options<GetSuggestionsData, ThrowOnError>) => {\n return (options.client ?? _heyApiClient).get<GetSuggestionsResponse, GetSuggestionsError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/suggest',\n ...options\n });\n};\n\n/**\n * Credits\n * Return the current credit balance for the authenticated API key.\n */\nexport const getCredits = <ThrowOnError extends boolean = false>(options?: Options<GetCreditsData, ThrowOnError>) => {\n return (options?.client ?? _heyApiClient).get<GetCreditsResponse, GetCreditsError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/credits',\n ...options\n });\n};\n\n/**\n * Logs\n * Return recent API request logs for the authenticated key.\n */\nexport const getLogs = <ThrowOnError extends boolean = false>(options?: Options<GetLogsData, ThrowOnError>) => {\n return (options?.client ?? _heyApiClient).get<GetLogsResponse, GetLogsError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/logs',\n ...options\n });\n};\n\n/**\n * Usage\n * Return daily credit and request counts for the authenticated key.\n */\nexport const getUsage = <ThrowOnError extends boolean = false>(options?: Options<GetUsageData, ThrowOnError>) => {\n return (options?.client ?? _heyApiClient).get<GetUsageResponse, GetUsageError, ThrowOnError>({\n security: [\n {\n scheme: 'bearer',\n type: 'http'\n }\n ],\n url: '/v1/usage',\n ...options\n });\n};","import { createClient, createConfig, type Client } from \"@hey-api/client-fetch\";\nimport * as ops from \"./generated/sdk.gen\";\nimport type {\n ErrorResponse,\n GetVideoData,\n GetVideoResponse,\n SearchVideosData,\n SearchVideosResponse,\n GetChannelData,\n GetChannelResponse,\n GetPlaylistData,\n GetPlaylistResponse,\n GetSuggestionsData,\n GetSuggestionsResponse,\n GetCreditsResponse,\n GetLogsData,\n GetLogsResponse,\n GetUsageData,\n GetUsageResponse,\n VideoDetailsData,\n TranscriptResult,\n CommentsData,\n LiveChatData,\n} from \"./generated/types.gen\";\n\n/** A video response with `data` narrowed to the shape for a given request `type`. */\ntype VideoResponseFor<D> = Omit<GetVideoResponse, \"data\"> & { data: D };\n\nexport * from \"./generated/types.gen\";\n\nexport interface StophyOptions {\n /** API key from your dashboard. Sent as `Authorization: Bearer <key>`. */\n apiKey: string;\n /** Defaults to `https://api.stophy.dev`. */\n baseUrl?: string;\n /** Bring your own `fetch` (handy for tests or non-global runtimes). */\n fetch?: typeof globalThis.fetch;\n /** Sent with every request. */\n headers?: Record<string, string>;\n /**\n * Retry attempts for transient failures (network errors and\n * 429/500/502/503/504). Set to `0` to disable. Defaults to `2`.\n */\n maxRetries?: number;\n /** Base delay for backoff, in ms. Defaults to `500`. */\n retryInitialDelayMs?: number;\n}\n\n/** Thrown when the API responds with a non-2xx status. */\nexport class StophyError extends Error {\n readonly code?: ErrorResponse[\"code\"];\n readonly status: number;\n readonly requestId?: string;\n readonly details?: unknown;\n\n constructor(\n message: string,\n opts: {\n status: number;\n code?: ErrorResponse[\"code\"];\n requestId?: string;\n details?: unknown;\n },\n ) {\n super(message);\n this.name = \"StophyError\";\n this.status = opts.status;\n this.code = opts.code;\n this.requestId = opts.requestId;\n this.details = opts.details;\n }\n}\n\n/**\n * Stophy API client — YouTube context API for AI agents.\n *\n * ```ts\n * const stophy = new Stophy({ apiKey: process.env.STOPHY_API_KEY! });\n * const { data } = await stophy.video({ type: \"transcript\", videoUrl });\n * ```\n */\nexport class Stophy {\n /** The underlying fetch client, if you need lower-level access. */\n readonly client: Client;\n\n constructor(options: StophyOptions) {\n if (!options?.apiKey) {\n throw new Error(\"Stophy: `apiKey` is required.\");\n }\n const baseFetch = options.fetch ?? globalThis.fetch;\n this.client = createClient(\n createConfig({\n baseUrl: options.baseUrl ?? \"https://api.stophy.dev\",\n auth: () => options.apiKey,\n headers: options.headers,\n fetch: withRetries(\n baseFetch,\n options.maxRetries ?? 2,\n options.retryInitialDelayMs ?? 500,\n ),\n }),\n );\n }\n\n /** Video details, transcript, comments, replies, or live chat — pick with `type`. */\n async video(\n body: GetVideoData[\"body\"] & { type: \"details\" },\n ): Promise<VideoResponseFor<VideoDetailsData>>;\n async video(\n body: GetVideoData[\"body\"] & { type: \"transcript\" },\n ): Promise<VideoResponseFor<TranscriptResult>>;\n async video(\n body: GetVideoData[\"body\"] & { type: \"comments\" | \"replies\" },\n ): Promise<VideoResponseFor<CommentsData>>;\n async video(\n body: GetVideoData[\"body\"] & { type: \"livechat\" },\n ): Promise<VideoResponseFor<LiveChatData>>;\n async video(body: GetVideoData[\"body\"]): Promise<GetVideoResponse>;\n async video(body: GetVideoData[\"body\"]): Promise<GetVideoResponse> {\n return unwrap(await ops.getVideo({ client: this.client, body }));\n }\n\n /** Search YouTube, optionally filtered by type, sort, date, duration, and features. */\n async search(body: SearchVideosData[\"body\"]): Promise<SearchVideosResponse> {\n return unwrap(await ops.searchVideos({ client: this.client, body }));\n }\n\n /** Channel metadata and content. Switch sections with `tab`. */\n async channel(body: GetChannelData[\"body\"]): Promise<GetChannelResponse> {\n return unwrap(await ops.getChannel({ client: this.client, body }));\n }\n\n /** Playlist items. Page through long playlists with `continuationToken`. */\n async playlist(body: GetPlaylistData[\"body\"]): Promise<GetPlaylistResponse> {\n return unwrap(await ops.getPlaylist({ client: this.client, body }));\n }\n\n /** Search autocomplete suggestions. */\n async suggest(query: GetSuggestionsData[\"query\"]): Promise<GetSuggestionsResponse> {\n return unwrap(await ops.getSuggestions({ client: this.client, query }));\n }\n\n /** Your current credit balance. */\n async credits(): Promise<GetCreditsResponse> {\n return unwrap(await ops.getCredits({ client: this.client }));\n }\n\n /** Recent API request logs. */\n async logs(query?: GetLogsData[\"query\"]): Promise<GetLogsResponse> {\n return unwrap(await ops.getLogs({ client: this.client, query }));\n }\n\n /** Daily credit and request counts. */\n async usage(query?: GetUsageData[\"query\"]): Promise<GetUsageResponse> {\n return unwrap(await ops.getUsage({ client: this.client, query }));\n }\n}\n\nconst RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]);\n\ntype FetchFn = (input: Request | URL | string, init?: RequestInit) => Promise<Response>;\n\n// Wrap a fetch so transient failures (network errors and retryable statuses)\n// are retried with exponential backoff + jitter, honoring `Retry-After`.\n// Every Stophy endpoint is a read, so retrying is always safe.\nfunction withRetries(\n baseFetch: typeof globalThis.fetch,\n maxRetries: number,\n initialDelayMs: number,\n): FetchFn {\n if (maxRetries <= 0) {\n return baseFetch;\n }\n return async (input, init) => {\n for (let attempt = 0; ; attempt++) {\n // Clone so the body survives a retry when `input` is a Request.\n const request = input instanceof Request ? input.clone() : input;\n try {\n const response = await baseFetch(request, init);\n if (attempt < maxRetries && RETRYABLE_STATUS.has(response.status)) {\n await sleep(retryAfterMs(response) ?? backoffMs(attempt, initialDelayMs));\n continue;\n }\n return response;\n } catch (error) {\n if (attempt >= maxRetries) {\n throw error;\n }\n await sleep(backoffMs(attempt, initialDelayMs));\n }\n }\n };\n}\n\nfunction backoffMs(attempt: number, base: number): number {\n const window = base * 2 ** attempt;\n return window / 2 + Math.random() * (window / 2);\n}\n\nfunction retryAfterMs(response: Response): number | null {\n const header = response.headers.get(\"retry-after\");\n if (!header) {\n return null;\n }\n const seconds = Number(header);\n if (!Number.isNaN(seconds)) {\n return seconds * 1000;\n }\n const date = Date.parse(header);\n return Number.isNaN(date) ? null : Math.max(0, date - Date.now());\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// Pull `data` out of a result, or throw a StophyError if the call failed.\nfunction unwrap<T>(result: {\n data?: T;\n error?: unknown;\n response: Response;\n}): T {\n if (result.error !== undefined || result.data === undefined) {\n const err = (result.error ?? {}) as Partial<ErrorResponse>;\n throw new StophyError(err.error ?? `Stophy request failed with status ${result.response.status}`, {\n status: result.response.status,\n code: err.code,\n requestId: result.response.headers.get(\"x-request-id\") ?? undefined,\n details: err.details,\n });\n }\n return result.data;\n}\n\nexport default Stophy;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/generated/client.gen.ts","../src/generated/sdk.gen.ts","../src/errors.ts","../src/transport.ts","../src/methods/account.ts","../src/methods/channel.ts","../src/methods/playlist.ts","../src/methods/search.ts","../src/methods/suggest.ts","../src/methods/video.ts","../src/client.ts"],"names":["createClient","createConfig","client"],"mappings":";;;AAuBO,IAAM,MAAA,GAAS,YAAA;AAAA,EACpB,YAAA,CAA4B;AAAA,IAC1B,OAAA,EAAS;AAAA,GACV;AACH,CAAA;;;AC6BO,IAAM,QAAA,GAAW,CACtB,OAAA,KACG;AACH,EAAA,OAAA,CAAQ,OAAA,CAAQ,MAAA,IAAU,MAAA,EAAe,IAAA,CAIvC;AAAA,IACA,QAAA,EAAU;AAAA,MACR;AAAA,QACE,MAAA,EAAQ,QAAA;AAAA,QACR,IAAA,EAAM;AAAA;AACR,KACF;AAAA,IACA,GAAA,EAAK,WAAA;AAAA,IACL,GAAG,OAAA;AAAA,IACH,OAAA,EAAS;AAAA,MACP,cAAA,EAAgB,kBAAA;AAAA,MAChB,GAAG,OAAA,EAAS;AAAA;AACd,GACD,CAAA;AACH,CAAA;AAMO,IAAM,YAAA,GAAe,CAC1B,OAAA,KACG;AACH,EAAA,OAAA,CAAQ,OAAA,CAAQ,MAAA,IAAU,MAAA,EAAe,IAAA,CAIvC;AAAA,IACA,QAAA,EAAU;AAAA,MACR;AAAA,QACE,MAAA,EAAQ,QAAA;AAAA,QACR,IAAA,EAAM;AAAA;AACR,KACF;AAAA,IACA,GAAA,EAAK,YAAA;AAAA,IACL,GAAG,OAAA;AAAA,IACH,OAAA,EAAS;AAAA,MACP,cAAA,EAAgB,kBAAA;AAAA,MAChB,GAAG,OAAA,EAAS;AAAA;AACd,GACD,CAAA;AACH,CAAA;AAMO,IAAM,UAAA,GAAa,CACxB,OAAA,KACG;AACH,EAAA,OAAA,CAAQ,OAAA,CAAQ,MAAA,IAAU,MAAA,EAAe,IAAA,CAIvC;AAAA,IACA,QAAA,EAAU;AAAA,MACR;AAAA,QACE,MAAA,EAAQ,QAAA;AAAA,QACR,IAAA,EAAM;AAAA;AACR,KACF;AAAA,IACA,GAAA,EAAK,aAAA;AAAA,IACL,GAAG,OAAA;AAAA,IACH,OAAA,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,KAAK,MAAM,CAAA;AAAA,EAC1C;AAAA,EAEA,KAAK,KAAA,EAAwD;AAC5D,IAAA,OAAsB,IAAA,CAAK,IAAA,CAAK,MAAA,EAAQ,KAAK,CAAA;AAAA,EAC9C;AAAA,EAEA,MAAM,KAAA,EAA0D;AAC/D,IAAA,OAAsB,KAAA,CAAM,IAAA,CAAK,MAAA,EAAQ,KAAK,CAAA;AAAA,EAC/C;AACD","file":"index.js","sourcesContent":["// This file is auto-generated by @hey-api/openapi-ts\n\nimport type { ClientOptions } from \"./types.gen\";\nimport {\n type Config,\n type ClientOptions as DefaultClientOptions,\n createClient,\n createConfig,\n} from \"@hey-api/client-fetch\";\n\n/**\n * The `createClientConfig()` function will be called on client initialization\n * and the returned object will become the client's initial configuration.\n *\n * You may want to initialize your client this way instead of calling\n * `setConfig()`. This is useful for example if you're using Next.js\n * to ensure your client always has the correct values.\n */\nexport type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =\n (\n override?: Config<DefaultClientOptions & T>\n ) => Config<Required<DefaultClientOptions> & T>;\n\nexport const client = createClient(\n createConfig<ClientOptions>({\n baseUrl: \"https://api.stophy.dev\",\n })\n);\n","// This file is auto-generated by @hey-api/openapi-ts\n\nimport type {\n Options as ClientOptions,\n TDataShape,\n Client,\n} from \"@hey-api/client-fetch\";\nimport type {\n GetVideoData,\n GetVideoResponse,\n GetVideoError,\n SearchVideosData,\n SearchVideosResponse,\n SearchVideosError,\n GetChannelData,\n GetChannelResponse,\n GetChannelError,\n GetPlaylistData,\n GetPlaylistResponse,\n GetPlaylistError,\n GetSuggestionsData,\n GetSuggestionsResponse,\n GetSuggestionsError,\n GetCreditsData,\n GetCreditsResponse,\n GetCreditsError,\n GetLogsData,\n GetLogsResponse,\n GetLogsError,\n GetUsageData,\n GetUsageResponse,\n GetUsageError,\n} from \"./types.gen\";\nimport { client as _heyApiClient } from \"./client.gen\";\n\nexport type Options<\n TData extends TDataShape = TDataShape,\n ThrowOnError extends boolean = boolean\n> = ClientOptions<TData, ThrowOnError> & {\n /**\n * You can provide a client instance returned by `createClient()` instead of\n * individual options. This might be also useful if you want to implement a\n * custom client.\n */\n client?: Client;\n /**\n * You can pass arbitrary values through the `meta` object. This can be\n * used to access values that aren't defined as part of the SDK function.\n */\n meta?: Record<string, unknown>;\n};\n\n/**\n * Video\n * Fetch video details, transcript, comments, replies, or live chat. Pass type: details for metadata, transcript for timestamped captions, comments for top-level comments, replies for a comment thread (pass the repliesToken from a comment as continuationToken), or livechat for live stream chat messages.\n */\nexport const getVideo = <ThrowOnError extends boolean = false>(\n options: Options<GetVideoData, ThrowOnError>\n) => {\n return (options.client ?? _heyApiClient).post<\n GetVideoResponse,\n GetVideoError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/video\",\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n ...options?.headers,\n },\n });\n};\n\n/**\n * Search\n * Search YouTube with optional filters for content type, sort order, upload date, duration, and features. Returns paginated results.\n */\nexport const searchVideos = <ThrowOnError extends boolean = false>(\n options: Options<SearchVideosData, ThrowOnError>\n) => {\n return (options.client ?? _heyApiClient).post<\n SearchVideosResponse,\n SearchVideosError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/search\",\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n ...options?.headers,\n },\n });\n};\n\n/**\n * Channel\n * Retrieve channel metadata and content by channelUrl. Use the tab field to switch between videos, shorts, playlists, and about info.\n */\nexport const getChannel = <ThrowOnError extends boolean = false>(\n options: Options<GetChannelData, ThrowOnError>\n) => {\n return (options.client ?? _heyApiClient).post<\n GetChannelResponse,\n GetChannelError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/channel\",\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n ...options?.headers,\n },\n });\n};\n\n/**\n * Playlist\n * Retrieve items from a YouTube playlist. Use continuationToken to page through long playlists.\n */\nexport const getPlaylist = <ThrowOnError extends boolean = false>(\n options: Options<GetPlaylistData, ThrowOnError>\n) => {\n return (options.client ?? _heyApiClient).post<\n GetPlaylistResponse,\n GetPlaylistError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/playlist\",\n ...options,\n headers: {\n \"Content-Type\": \"application/json\",\n ...options?.headers,\n },\n });\n};\n\n/**\n * Suggest\n * Get YouTube search autocomplete suggestions for a query.\n */\nexport const getSuggestions = <ThrowOnError extends boolean = false>(\n options: Options<GetSuggestionsData, ThrowOnError>\n) => {\n return (options.client ?? _heyApiClient).get<\n GetSuggestionsResponse,\n GetSuggestionsError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/suggest\",\n ...options,\n });\n};\n\n/**\n * Credits\n * Return the current credit balance for the authenticated API key.\n */\nexport const getCredits = <ThrowOnError extends boolean = false>(\n options?: Options<GetCreditsData, ThrowOnError>\n) => {\n return (options?.client ?? _heyApiClient).get<\n GetCreditsResponse,\n GetCreditsError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/credits\",\n ...options,\n });\n};\n\n/**\n * Logs\n * Return recent API request logs for the authenticated key.\n */\nexport const getLogs = <ThrowOnError extends boolean = false>(\n options?: Options<GetLogsData, ThrowOnError>\n) => {\n return (options?.client ?? _heyApiClient).get<\n GetLogsResponse,\n GetLogsError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/logs\",\n ...options,\n });\n};\n\n/**\n * Usage\n * Return daily credit and request counts for the authenticated key.\n */\nexport const getUsage = <ThrowOnError extends boolean = false>(\n options?: Options<GetUsageData, ThrowOnError>\n) => {\n return (options?.client ?? _heyApiClient).get<\n GetUsageResponse,\n GetUsageError,\n ThrowOnError\n >({\n security: [\n {\n scheme: \"bearer\",\n type: \"http\",\n },\n ],\n url: \"/v1/usage\",\n ...options,\n });\n};\n","import type { ErrorResponse } from \"./generated/types.gen\";\n\n/** Thrown when the Stophy API responds with a non-success status. */\nexport class StophyError extends Error {\n\treadonly code?: ErrorResponse[\"code\"];\n\treadonly status: number;\n\treadonly requestId?: string;\n\treadonly details?: unknown;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: {\n\t\t\tstatus: number;\n\t\t\tcode?: ErrorResponse[\"code\"];\n\t\t\trequestId?: string;\n\t\t\tdetails?: unknown;\n\t\t},\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"StophyError\";\n\t\tthis.status = options.status;\n\t\tthis.code = options.code;\n\t\tthis.requestId = options.requestId;\n\t\tthis.details = options.details;\n\t}\n}\n","import { type Client, createClient, createConfig } from \"@hey-api/client-fetch\";\nimport { StophyError } from \"./errors\";\nimport type { ErrorResponse } from \"./generated/types.gen\";\n\nconst DEFAULT_BASE_URL = \"https://api.stophy.dev\";\nconst RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]);\n\nexport interface TransportOptions {\n\tapiKey: string;\n\tbaseUrl?: string;\n\tfetch?: typeof globalThis.fetch;\n\theaders?: Record<string, string>;\n\tmaxRetries?: number;\n\tretryInitialDelayMs?: number;\n}\n\nexport function createTransport(options: TransportOptions): Client {\n\tconst baseFetch = options.fetch ?? globalThis.fetch;\n\treturn createClient(\n\t\tcreateConfig({\n\t\t\tbaseUrl: options.baseUrl ?? DEFAULT_BASE_URL,\n\t\t\tauth: () => options.apiKey,\n\t\t\theaders: options.headers,\n\t\t\tfetch: withRetries(\n\t\t\t\tbaseFetch,\n\t\t\t\toptions.maxRetries ?? 2,\n\t\t\t\toptions.retryInitialDelayMs ?? 500,\n\t\t\t),\n\t\t}),\n\t);\n}\n\ntype FetchFn = (\n\tinput: Request | URL | string,\n\tinit?: RequestInit,\n) => Promise<Response>;\n\nfunction withRetries(\n\tbaseFetch: typeof globalThis.fetch,\n\tmaxRetries: number,\n\tinitialDelayMs: number,\n): FetchFn {\n\tif (maxRetries <= 0) return baseFetch;\n\n\treturn async (input, init) => {\n\t\tfor (let attempt = 0; ; attempt++) {\n\t\t\tconst request = input instanceof Request ? input.clone() : input;\n\t\t\ttry {\n\t\t\t\tconst response = await baseFetch(request, init);\n\t\t\t\tif (attempt < maxRetries && RETRYABLE_STATUS.has(response.status)) {\n\t\t\t\t\tawait sleep(\n\t\t\t\t\t\tretryAfterMs(response) ?? backoffMs(attempt, initialDelayMs),\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn response;\n\t\t\t} catch (error) {\n\t\t\t\tif (attempt >= maxRetries) throw error;\n\t\t\t\tawait sleep(backoffMs(attempt, initialDelayMs));\n\t\t\t}\n\t\t}\n\t};\n}\n\nfunction backoffMs(attempt: number, base: number): number {\n\tconst window = base * 2 ** attempt;\n\treturn window / 2 + Math.random() * (window / 2);\n}\n\nfunction retryAfterMs(response: Response): number | null {\n\tconst header = response.headers.get(\"retry-after\");\n\tif (!header) return null;\n\tconst seconds = Number(header);\n\tif (!Number.isNaN(seconds)) return seconds * 1000;\n\tconst date = Date.parse(header);\n\treturn Number.isNaN(date) ? null : Math.max(0, date - Date.now());\n}\n\nfunction sleep(ms: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport function unwrap<T>(result: {\n\tdata?: T;\n\terror?: unknown;\n\tresponse: Response;\n}): T {\n\tif (result.error === undefined && result.data !== undefined)\n\t\treturn result.data;\n\n\tconst error = (result.error ?? {}) as Partial<ErrorResponse>;\n\tthrow new StophyError(\n\t\terror.error ??\n\t\t\t`Stophy request failed with status ${result.response.status}`,\n\t\t{\n\t\t\tstatus: result.response.status,\n\t\t\tcode: error.code,\n\t\t\trequestId: result.response.headers.get(\"x-request-id\") ?? undefined,\n\t\t\tdetails: error.details,\n\t\t},\n\t);\n}\n","import type { Client } from \"@hey-api/client-fetch\";\nimport { getCredits, getLogs, getUsage } from \"../generated/sdk.gen\";\nimport type {\n\tGetCreditsResponse,\n\tGetLogsData,\n\tGetLogsResponse,\n\tGetUsageData,\n\tGetUsageResponse,\n} from \"../generated/types.gen\";\nimport { unwrap } from \"../transport\";\n\nexport function credits(client: Client): Promise<GetCreditsResponse> {\n\treturn getCredits({ client }).then(unwrap);\n}\n\nexport function logs(\n\tclient: Client,\n\tquery?: GetLogsData[\"query\"],\n): Promise<GetLogsResponse> {\n\treturn getLogs({ client, query }).then(unwrap);\n}\n\nexport function usage(\n\tclient: Client,\n\tquery?: GetUsageData[\"query\"],\n): Promise<GetUsageResponse> {\n\treturn getUsage({ client, query }).then(unwrap);\n}\n","import type { Client } from \"@hey-api/client-fetch\";\nimport { getChannel } from \"../generated/sdk.gen\";\nimport type {\n\tGetChannelData,\n\tGetChannelResponse,\n} from \"../generated/types.gen\";\nimport { unwrap } from \"../transport\";\n\ntype ChannelBody = GetChannelData[\"body\"];\nexport type ChannelOptions = Omit<ChannelBody, \"channelUrl\">;\n\nexport function channel(\n\tclient: Client,\n\turlOrBody: string | ChannelBody,\n\toptions: ChannelOptions = {},\n): Promise<GetChannelResponse> {\n\tconst body =\n\t\ttypeof urlOrBody === \"string\"\n\t\t\t? { channelUrl: urlOrBody, ...options }\n\t\t\t: urlOrBody;\n\treturn getChannel({ client, body }).then(unwrap);\n}\n","import type { Client } from \"@hey-api/client-fetch\";\nimport { getPlaylist } from \"../generated/sdk.gen\";\nimport type {\n\tGetPlaylistData,\n\tGetPlaylistResponse,\n} from \"../generated/types.gen\";\nimport { unwrap } from \"../transport\";\n\ntype PlaylistBody = GetPlaylistData[\"body\"];\nexport type PlaylistOptions = Omit<PlaylistBody, \"playlistUrl\">;\n\nexport function playlist(\n\tclient: Client,\n\turlOrBody: string | PlaylistBody,\n\toptions: PlaylistOptions = {},\n): Promise<GetPlaylistResponse> {\n\tconst body =\n\t\ttypeof urlOrBody === \"string\"\n\t\t\t? { playlistUrl: urlOrBody, ...options }\n\t\t\t: urlOrBody;\n\treturn getPlaylist({ client, body }).then(unwrap);\n}\n","import type { Client } from \"@hey-api/client-fetch\";\nimport { searchVideos } from \"../generated/sdk.gen\";\nimport type {\n\tSearchVideosData,\n\tSearchVideosResponse,\n} from \"../generated/types.gen\";\nimport { unwrap } from \"../transport\";\n\ntype SearchBody = SearchVideosData[\"body\"];\nexport type SearchOptions = Omit<SearchBody, \"q\">;\n\nexport function search(\n\tclient: Client,\n\tqueryOrBody: string | SearchBody,\n\toptions: SearchOptions = {},\n): Promise<SearchVideosResponse> {\n\tif (typeof queryOrBody === \"string\" && !queryOrBody.trim()) {\n\t\tthrow new Error(\"query cannot be empty\");\n\t}\n\tconst body =\n\t\ttypeof queryOrBody === \"string\"\n\t\t\t? { q: queryOrBody, ...options }\n\t\t\t: queryOrBody;\n\treturn searchVideos({ client, body }).then(unwrap);\n}\n","import type { Client } from \"@hey-api/client-fetch\";\nimport { getSuggestions } from \"../generated/sdk.gen\";\nimport type {\n\tGetSuggestionsData,\n\tGetSuggestionsResponse,\n} from \"../generated/types.gen\";\nimport { unwrap } from \"../transport\";\n\ntype SuggestQuery = GetSuggestionsData[\"query\"];\nexport type SuggestOptions = Omit<SuggestQuery, \"q\">;\n\nexport function suggest(\n\tclient: Client,\n\tqueryOrOptions: string | SuggestQuery,\n\toptions: SuggestOptions = {},\n): Promise<GetSuggestionsResponse> {\n\tif (typeof queryOrOptions === \"string\" && !queryOrOptions.trim()) {\n\t\tthrow new Error(\"query cannot be empty\");\n\t}\n\tconst query =\n\t\ttypeof queryOrOptions === \"string\"\n\t\t\t? { q: queryOrOptions, ...options }\n\t\t\t: queryOrOptions;\n\treturn getSuggestions({ client, query }).then(unwrap);\n}\n","import type { Client } from \"@hey-api/client-fetch\";\nimport { getVideo } from \"../generated/sdk.gen\";\nimport type {\n\tCommentsData,\n\tGetVideoData,\n\tGetVideoResponse,\n\tLiveChatData,\n\tTranscriptResult,\n\tVideoDetailsData,\n} from \"../generated/types.gen\";\nimport { unwrap } from \"../transport\";\n\nexport type VideoResponseFor<T> = Omit<GetVideoResponse, \"data\"> & { data: T };\nexport type CommentsOptions = Pick<\n\tGetVideoData[\"body\"],\n\t\"sortBy\" | \"continuationToken\"\n>;\nexport type LiveChatOptions = Pick<\n\tGetVideoData[\"body\"],\n\t\"chatType\" | \"continuationToken\"\n>;\n\nexport async function video(\n\tclient: Client,\n\tbody: GetVideoData[\"body\"],\n): Promise<GetVideoResponse> {\n\treturn unwrap(await getVideo({ client, body }));\n}\n\nexport function videoDetails(\n\tclient: Client,\n\tvideoUrl: string,\n): Promise<VideoResponseFor<VideoDetailsData>> {\n\treturn video(client, { type: \"details\", videoUrl }) as Promise<\n\t\tVideoResponseFor<VideoDetailsData>\n\t>;\n}\n\nexport function transcript(\n\tclient: Client,\n\tvideoUrl: string,\n): Promise<VideoResponseFor<TranscriptResult>> {\n\treturn video(client, { type: \"transcript\", videoUrl }) as Promise<\n\t\tVideoResponseFor<TranscriptResult>\n\t>;\n}\n\nexport function comments(\n\tclient: Client,\n\tvideoUrl: string,\n\toptions: CommentsOptions = {},\n): Promise<VideoResponseFor<CommentsData>> {\n\treturn video(client, {\n\t\ttype: \"comments\",\n\t\tvideoUrl,\n\t\t...options,\n\t}) as Promise<VideoResponseFor<CommentsData>>;\n}\n\nexport function replies(\n\tclient: Client,\n\tcontinuationToken: string,\n): Promise<VideoResponseFor<CommentsData>> {\n\treturn video(client, {\n\t\ttype: \"replies\",\n\t\tcontinuationToken,\n\t} as GetVideoData[\"body\"]) as Promise<VideoResponseFor<CommentsData>>;\n}\n\nexport function liveChat(\n\tclient: Client,\n\tvideoUrl: string,\n\toptions: LiveChatOptions = {},\n): Promise<VideoResponseFor<LiveChatData>> {\n\treturn video(client, {\n\t\ttype: \"livechat\",\n\t\tvideoUrl,\n\t\t...options,\n\t}) as Promise<VideoResponseFor<LiveChatData>>;\n}\n","import type { Client } from \"@hey-api/client-fetch\";\nimport type {\n\tCommentsData,\n\tGetChannelData,\n\tGetChannelResponse,\n\tGetCreditsResponse,\n\tGetLogsData,\n\tGetLogsResponse,\n\tGetPlaylistData,\n\tGetPlaylistResponse,\n\tGetSuggestionsData,\n\tGetSuggestionsResponse,\n\tGetUsageData,\n\tGetUsageResponse,\n\tGetVideoData,\n\tGetVideoResponse,\n\tLiveChatData,\n\tSearchVideosData,\n\tSearchVideosResponse,\n\tTranscriptResult,\n\tVideoDetailsData,\n} from \"./generated/types.gen\";\nimport * as accountMethods from \"./methods/account\";\nimport { type ChannelOptions, channel as getChannel } from \"./methods/channel\";\nimport {\n\tplaylist as getPlaylist,\n\ttype PlaylistOptions,\n} from \"./methods/playlist\";\nimport { type SearchOptions, search as searchVideos } from \"./methods/search\";\nimport {\n\tsuggest as getSuggestions,\n\ttype SuggestOptions,\n} from \"./methods/suggest\";\nimport type {\n\tCommentsOptions,\n\tLiveChatOptions,\n\tVideoResponseFor,\n} from \"./methods/video\";\nimport * as videoMethods from \"./methods/video\";\nimport { createTransport } from \"./transport\";\n\nexport interface StophyOptions {\n\t/** Defaults to `STOPHY_API_KEY`. */\n\tapiKey?: string;\n\t/** Defaults to `STOPHY_BASE_URL` or `https://api.stophy.dev`. */\n\tbaseUrl?: string;\n\tfetch?: typeof globalThis.fetch;\n\theaders?: Record<string, string>;\n\tmaxRetries?: number;\n\tretryInitialDelayMs?: number;\n}\n\nexport type StophyClientInput = StophyOptions | string;\n\nfunction env(name: string): string | undefined {\n\treturn typeof process === \"undefined\" ? undefined : process.env[name];\n}\n\n/** Typed client for the Stophy API. */\nexport class Stophy {\n\treadonly client: Client;\n\n\tconstructor(input: StophyClientInput = {}) {\n\t\tconst options = typeof input === \"string\" ? { apiKey: input } : input;\n\t\tconst apiKey = options.apiKey?.trim() || env(\"STOPHY_API_KEY\")?.trim();\n\t\tif (!apiKey) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Stophy: provide `apiKey` or set the STOPHY_API_KEY environment variable.\",\n\t\t\t);\n\t\t}\n\n\t\tthis.client = createTransport({\n\t\t\t...options,\n\t\t\tapiKey,\n\t\t\tbaseUrl: options.baseUrl ?? env(\"STOPHY_BASE_URL\"),\n\t\t});\n\t}\n\n\tasync video(\n\t\tbody: GetVideoData[\"body\"] & { type: \"details\" },\n\t): Promise<VideoResponseFor<VideoDetailsData>>;\n\tasync video(\n\t\tbody: GetVideoData[\"body\"] & { type: \"transcript\" },\n\t): Promise<VideoResponseFor<TranscriptResult>>;\n\tasync video(\n\t\tbody: GetVideoData[\"body\"] & { type: \"comments\" | \"replies\" },\n\t): Promise<VideoResponseFor<CommentsData>>;\n\tasync video(\n\t\tbody: GetVideoData[\"body\"] & { type: \"livechat\" },\n\t): Promise<VideoResponseFor<LiveChatData>>;\n\tasync video(body: GetVideoData[\"body\"]): Promise<GetVideoResponse>;\n\tasync video(body: GetVideoData[\"body\"]): Promise<GetVideoResponse> {\n\t\treturn videoMethods.video(this.client, body);\n\t}\n\n\tvideoDetails(videoUrl: string): Promise<VideoResponseFor<VideoDetailsData>> {\n\t\treturn videoMethods.videoDetails(this.client, videoUrl);\n\t}\n\n\ttranscript(videoUrl: string): Promise<VideoResponseFor<TranscriptResult>> {\n\t\treturn videoMethods.transcript(this.client, videoUrl);\n\t}\n\n\tcomments(\n\t\tvideoUrl: string,\n\t\toptions?: CommentsOptions,\n\t): Promise<VideoResponseFor<CommentsData>> {\n\t\treturn videoMethods.comments(this.client, videoUrl, options);\n\t}\n\n\treplies(continuationToken: string): Promise<VideoResponseFor<CommentsData>> {\n\t\treturn videoMethods.replies(this.client, continuationToken);\n\t}\n\n\tliveChat(\n\t\tvideoUrl: string,\n\t\toptions?: LiveChatOptions,\n\t): Promise<VideoResponseFor<LiveChatData>> {\n\t\treturn videoMethods.liveChat(this.client, videoUrl, options);\n\t}\n\n\tasync search(body: SearchVideosData[\"body\"]): Promise<SearchVideosResponse>;\n\tasync search(\n\t\tquery: string,\n\t\toptions?: SearchOptions,\n\t): Promise<SearchVideosResponse>;\n\tasync search(\n\t\tqueryOrBody: string | SearchVideosData[\"body\"],\n\t\toptions?: SearchOptions,\n\t): Promise<SearchVideosResponse> {\n\t\treturn searchVideos(this.client, queryOrBody, options);\n\t}\n\n\tasync channel(body: GetChannelData[\"body\"]): Promise<GetChannelResponse>;\n\tasync channel(\n\t\tchannelUrl: string,\n\t\toptions?: ChannelOptions,\n\t): Promise<GetChannelResponse>;\n\tasync channel(\n\t\turlOrBody: string | GetChannelData[\"body\"],\n\t\toptions?: ChannelOptions,\n\t): Promise<GetChannelResponse> {\n\t\treturn getChannel(this.client, urlOrBody, options);\n\t}\n\n\tasync playlist(body: GetPlaylistData[\"body\"]): Promise<GetPlaylistResponse>;\n\tasync playlist(\n\t\tplaylistUrl: string,\n\t\toptions?: PlaylistOptions,\n\t): Promise<GetPlaylistResponse>;\n\tasync playlist(\n\t\turlOrBody: string | GetPlaylistData[\"body\"],\n\t\toptions?: PlaylistOptions,\n\t): Promise<GetPlaylistResponse> {\n\t\treturn getPlaylist(this.client, urlOrBody, options);\n\t}\n\n\tasync suggest(\n\t\tquery: GetSuggestionsData[\"query\"],\n\t): Promise<GetSuggestionsResponse>;\n\tasync suggest(\n\t\tquery: string,\n\t\toptions?: SuggestOptions,\n\t): Promise<GetSuggestionsResponse>;\n\tasync suggest(\n\t\tqueryOrOptions: string | GetSuggestionsData[\"query\"],\n\t\toptions?: SuggestOptions,\n\t): Promise<GetSuggestionsResponse> {\n\t\treturn getSuggestions(this.client, queryOrOptions, options);\n\t}\n\n\tcredits(): Promise<GetCreditsResponse> {\n\t\treturn accountMethods.credits(this.client);\n\t}\n\n\tlogs(query?: GetLogsData[\"query\"]): Promise<GetLogsResponse> {\n\t\treturn accountMethods.logs(this.client, query);\n\t}\n\n\tusage(query?: GetUsageData[\"query\"]): Promise<GetUsageResponse> {\n\t\treturn accountMethods.usage(this.client, query);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stophy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Official TypeScript SDK for Stophy - The YouTube context API for AI agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://stophy.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/
|
|
10
|
+
"url": "git+https://github.com/stophydotdev/sdk.git",
|
|
11
|
+
"directory": "packages/typescript"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [
|
|
13
14
|
"stophy",
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"build": "tsup",
|
|
35
36
|
"test": "bun test ../../test/typescript",
|
|
36
37
|
"check-types": "tsc --noEmit",
|
|
37
|
-
"prepublishOnly": "
|
|
38
|
+
"prepublishOnly": "bun run generate && bun run build"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@hey-api/openapi-ts": "^0.64.0",
|