@streamfarm/sdk 0.0.0-stage → 0.1.1
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/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +291 -2
- package/dist/cjs/chat.d.ts +51 -0
- package/dist/cjs/chat.js +224 -0
- package/dist/cjs/client.d.ts +44 -0
- package/dist/cjs/client.js +64 -0
- package/dist/cjs/errors.d.ts +86 -0
- package/dist/cjs/errors.js +110 -0
- package/dist/cjs/generated/openapi.d.ts +4127 -0
- package/dist/cjs/generated/openapi.js +7 -0
- package/dist/cjs/http.d.ts +81 -0
- package/dist/cjs/http.js +304 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pagination.d.ts +9 -0
- package/dist/cjs/pagination.js +22 -0
- package/dist/cjs/resources/account.d.ts +32 -0
- package/dist/cjs/resources/account.js +58 -0
- package/dist/cjs/resources/ads.d.ts +25 -0
- package/dist/cjs/resources/ads.js +46 -0
- package/dist/cjs/resources/base.d.ts +12 -0
- package/dist/cjs/resources/base.js +23 -0
- package/dist/cjs/resources/comments.d.ts +27 -0
- package/dist/cjs/resources/comments.js +46 -0
- package/dist/cjs/resources/platforms.d.ts +24 -0
- package/dist/cjs/resources/platforms.js +41 -0
- package/dist/cjs/resources/streams.d.ts +39 -0
- package/dist/cjs/resources/streams.js +76 -0
- package/dist/cjs/resources/studio.d.ts +20 -0
- package/dist/cjs/resources/studio.js +39 -0
- package/dist/cjs/types.d.ts +124 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/esm/chat.d.ts +51 -0
- package/dist/esm/chat.js +220 -0
- package/dist/esm/client.d.ts +44 -0
- package/dist/esm/client.js +60 -0
- package/dist/esm/errors.d.ts +86 -0
- package/dist/esm/errors.js +94 -0
- package/dist/esm/generated/openapi.d.ts +4127 -0
- package/dist/esm/generated/openapi.js +6 -0
- package/dist/esm/http.d.ts +81 -0
- package/dist/esm/http.js +297 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/pagination.d.ts +9 -0
- package/dist/esm/pagination.js +19 -0
- package/dist/esm/resources/account.d.ts +32 -0
- package/dist/esm/resources/account.js +50 -0
- package/dist/esm/resources/ads.d.ts +25 -0
- package/dist/esm/resources/ads.js +41 -0
- package/dist/esm/resources/base.d.ts +12 -0
- package/dist/esm/resources/base.js +19 -0
- package/dist/esm/resources/comments.d.ts +27 -0
- package/dist/esm/resources/comments.js +42 -0
- package/dist/esm/resources/platforms.d.ts +24 -0
- package/dist/esm/resources/platforms.js +37 -0
- package/dist/esm/resources/streams.d.ts +39 -0
- package/dist/esm/resources/streams.js +72 -0
- package/dist/esm/resources/studio.d.ts +20 -0
- package/dist/esm/resources/studio.js +35 -0
- package/dist/esm/types.d.ts +124 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/package.json +75 -4
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ClientOptions, type HttpMethod, type QueryValue, type RequestOptions } from './http.js';
|
|
2
|
+
import { Account, Broadcasts, Connections, Regions, Stats } from './resources/account.js';
|
|
3
|
+
import { AdOverlay, Ads } from './resources/ads.js';
|
|
4
|
+
import { Comments } from './resources/comments.js';
|
|
5
|
+
import { Platforms } from './resources/platforms.js';
|
|
6
|
+
import { Streams } from './resources/streams.js';
|
|
7
|
+
import { Studio } from './resources/studio.js';
|
|
8
|
+
import type { ApiKeyInfo } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* The StreamFarm public API client.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const sf = new StreamFarm(); // the key from STREAMFARM_API_KEY
|
|
14
|
+
* const streams = await sf.streams.list();
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class StreamFarm {
|
|
18
|
+
readonly streams: Streams;
|
|
19
|
+
readonly platforms: Platforms;
|
|
20
|
+
readonly ads: Ads;
|
|
21
|
+
readonly overlay: AdOverlay;
|
|
22
|
+
readonly comments: Comments;
|
|
23
|
+
readonly studio: Studio;
|
|
24
|
+
readonly regions: Regions;
|
|
25
|
+
readonly connections: Connections;
|
|
26
|
+
readonly stats: Stats;
|
|
27
|
+
readonly broadcasts: Broadcasts;
|
|
28
|
+
readonly account: Account;
|
|
29
|
+
private readonly transport;
|
|
30
|
+
constructor(options?: ClientOptions);
|
|
31
|
+
/** The API's base URL the client works with. */
|
|
32
|
+
get baseUrl(): string;
|
|
33
|
+
/** The key the client works with: its name, scopes, streams and expiry. Any key may read it. */
|
|
34
|
+
keyInfo(options?: RequestOptions): Promise<ApiKeyInfo>;
|
|
35
|
+
/**
|
|
36
|
+
* Any request to the API, for what this version of the SDK doesn't know
|
|
37
|
+
* yet: the answer as the API sends it, with the SDK's key, retries and
|
|
38
|
+
* errors. `path` is under the base URL: `/streams/<id>/…`.
|
|
39
|
+
*/
|
|
40
|
+
request<T = unknown>(method: HttpMethod, path: string, init?: {
|
|
41
|
+
query?: Record<string, QueryValue>;
|
|
42
|
+
body?: unknown;
|
|
43
|
+
}, options?: RequestOptions): Promise<T>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamFarm = void 0;
|
|
4
|
+
const http_js_1 = require("./http.js");
|
|
5
|
+
const account_js_1 = require("./resources/account.js");
|
|
6
|
+
const ads_js_1 = require("./resources/ads.js");
|
|
7
|
+
const comments_js_1 = require("./resources/comments.js");
|
|
8
|
+
const platforms_js_1 = require("./resources/platforms.js");
|
|
9
|
+
const streams_js_1 = require("./resources/streams.js");
|
|
10
|
+
const studio_js_1 = require("./resources/studio.js");
|
|
11
|
+
/**
|
|
12
|
+
* The StreamFarm public API client.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const sf = new StreamFarm(); // the key from STREAMFARM_API_KEY
|
|
16
|
+
* const streams = await sf.streams.list();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
class StreamFarm {
|
|
20
|
+
streams;
|
|
21
|
+
platforms;
|
|
22
|
+
ads;
|
|
23
|
+
overlay;
|
|
24
|
+
comments;
|
|
25
|
+
studio;
|
|
26
|
+
regions;
|
|
27
|
+
connections;
|
|
28
|
+
stats;
|
|
29
|
+
broadcasts;
|
|
30
|
+
account;
|
|
31
|
+
transport;
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
this.transport = new http_js_1.Transport(options);
|
|
34
|
+
this.streams = new streams_js_1.Streams(this.transport);
|
|
35
|
+
this.platforms = new platforms_js_1.Platforms(this.transport);
|
|
36
|
+
this.ads = new ads_js_1.Ads(this.transport);
|
|
37
|
+
this.overlay = new ads_js_1.AdOverlay(this.transport);
|
|
38
|
+
this.comments = new comments_js_1.Comments(this.transport);
|
|
39
|
+
this.studio = new studio_js_1.Studio(this.transport);
|
|
40
|
+
this.regions = new account_js_1.Regions(this.transport);
|
|
41
|
+
this.connections = new account_js_1.Connections(this.transport);
|
|
42
|
+
this.stats = new account_js_1.Stats(this.transport);
|
|
43
|
+
this.broadcasts = new account_js_1.Broadcasts(this.transport);
|
|
44
|
+
this.account = new account_js_1.Account(this.transport);
|
|
45
|
+
}
|
|
46
|
+
/** The API's base URL the client works with. */
|
|
47
|
+
get baseUrl() {
|
|
48
|
+
return this.transport.baseUrl;
|
|
49
|
+
}
|
|
50
|
+
/** The key the client works with: its name, scopes, streams and expiry. Any key may read it. */
|
|
51
|
+
async keyInfo(options) {
|
|
52
|
+
return (await this.transport.request({ method: 'GET', path: '/' }, options)).key;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Any request to the API, for what this version of the SDK doesn't know
|
|
56
|
+
* yet: the answer as the API sends it, with the SDK's key, retries and
|
|
57
|
+
* errors. `path` is under the base URL: `/streams/<id>/…`.
|
|
58
|
+
*/
|
|
59
|
+
request(method, path, init = {}, options) {
|
|
60
|
+
const normalized = path.startsWith('/') ? path : `/${path}`;
|
|
61
|
+
return this.transport.request({ method, path: normalized, query: init.query, body: init.body }, options);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.StreamFarm = StreamFarm;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the SDK throws. Everything is a StreamFarmError:
|
|
3
|
+
*
|
|
4
|
+
* - ApiError and its subclasses: the API answered with an error. The class
|
|
5
|
+
* follows the HTTP status, `code` says exactly why (see ErrorCode);
|
|
6
|
+
* - ConnectionError and TimeoutError: no answer came;
|
|
7
|
+
* - WaitTimeoutError: a waiting helper (`streams.waitUntilLive`) gave up.
|
|
8
|
+
*/
|
|
9
|
+
/** The `error.code`s the API answers with (its documentation lists them). New ones may come: compare, don't switch exhaustively. */
|
|
10
|
+
export type ErrorCode = 'bad_request' | 'unauthorized' | 'insufficient_scope' | 'forbidden' | 'not_found' | 'conflict' | 'connection_required' | 'stream_not_live' | 'stream_not_deployed' | 'stream_not_transcoded' | 'paid_promotion_off' | 'ad_on_air' | 'plan_limit' | 'ad_incomplete' | 'ad_text_too_long' | 'rate_limited' | 'internal_error' | 'not_supported' | 'core_unavailable' | 'platform_quota_exceeded' | 'platform_reconnect_required' | 'platform_rate_limited' | 'platform_refused' | 'platform_unavailable' | 'studio_unavailable' | 'invite_limit' | 'studio_server_unavailable' | 'http_error' | (string & {});
|
|
11
|
+
/** The key's request limit, from the answer's X-RateLimit-* headers. */
|
|
12
|
+
export interface RateLimit {
|
|
13
|
+
/** Requests a minute the key may make. */
|
|
14
|
+
limit: number;
|
|
15
|
+
/** Requests left in this minute. */
|
|
16
|
+
remaining: number;
|
|
17
|
+
/** Seconds until the minute starts over. */
|
|
18
|
+
resetSec: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class StreamFarmError extends Error {
|
|
21
|
+
constructor(message: string, options?: {
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export interface ApiErrorInit {
|
|
26
|
+
status: number;
|
|
27
|
+
code: ErrorCode;
|
|
28
|
+
message: string;
|
|
29
|
+
details?: unknown;
|
|
30
|
+
method: string;
|
|
31
|
+
path: string;
|
|
32
|
+
correlationId: string | null;
|
|
33
|
+
rateLimit: RateLimit | null;
|
|
34
|
+
retryAfter?: number | null;
|
|
35
|
+
}
|
|
36
|
+
/** The API answered with an error: `{ error: { code, message, details? } }`. */
|
|
37
|
+
export declare class ApiError extends StreamFarmError {
|
|
38
|
+
/** The HTTP status. */
|
|
39
|
+
readonly status: number;
|
|
40
|
+
/** Why: `plan_limit`, `insufficient_scope`, … */
|
|
41
|
+
readonly code: ErrorCode;
|
|
42
|
+
/** More about it, by code: `{ required }` for `insufficient_scope`, `{ limit, max, current, plan }` for `plan_limit`, … */
|
|
43
|
+
readonly details: unknown;
|
|
44
|
+
/** The request: method and path under the API's base URL. */
|
|
45
|
+
readonly method: string;
|
|
46
|
+
readonly path: string;
|
|
47
|
+
/** X-Correlation-Id of the answer: name it when you write to support. */
|
|
48
|
+
readonly correlationId: string | null;
|
|
49
|
+
readonly rateLimit: RateLimit | null;
|
|
50
|
+
constructor(init: ApiErrorInit);
|
|
51
|
+
}
|
|
52
|
+
/** 401: no key, or it is wrong, revoked or expired. */
|
|
53
|
+
export declare class AuthenticationError extends ApiError {
|
|
54
|
+
}
|
|
55
|
+
/** 403: the key lacks a scope (`insufficient_scope`), may not make streams (`forbidden`), or the tariff doesn't allow it (`plan_limit`). */
|
|
56
|
+
export declare class PermissionError extends ApiError {
|
|
57
|
+
}
|
|
58
|
+
/** 404: there is no such object, or it is outside the key's streams. */
|
|
59
|
+
export declare class NotFoundError extends ApiError {
|
|
60
|
+
}
|
|
61
|
+
/** 409: the state doesn't allow it now (`stream_not_live`, `connection_required`, `ad_on_air`, …). */
|
|
62
|
+
export declare class ConflictError extends ApiError {
|
|
63
|
+
}
|
|
64
|
+
/** 400 and 422: the request was refused as it is (`bad_request`, `ad_incomplete`, `not_supported`, …). */
|
|
65
|
+
export declare class ValidationError extends ApiError {
|
|
66
|
+
}
|
|
67
|
+
/** 429: over the key's request limit. */
|
|
68
|
+
export declare class RateLimitError extends ApiError {
|
|
69
|
+
/** Seconds to wait before trying again, from Retry-After. */
|
|
70
|
+
readonly retryAfter: number | null;
|
|
71
|
+
constructor(init: ApiErrorInit);
|
|
72
|
+
}
|
|
73
|
+
/** 5xx: the API, the region's media server, the studio's room server or a platform failed. */
|
|
74
|
+
export declare class ServerError extends ApiError {
|
|
75
|
+
}
|
|
76
|
+
/** No answer: DNS, TLS, the connection dropped. `cause` holds what fetch threw. */
|
|
77
|
+
export declare class ConnectionError extends StreamFarmError {
|
|
78
|
+
}
|
|
79
|
+
/** No answer within the request's timeout. */
|
|
80
|
+
export declare class TimeoutError extends ConnectionError {
|
|
81
|
+
}
|
|
82
|
+
/** A waiting helper ran out of time (`streams.waitUntilLive`). */
|
|
83
|
+
export declare class WaitTimeoutError extends StreamFarmError {
|
|
84
|
+
}
|
|
85
|
+
/** The ApiError subclass for an HTTP status. */
|
|
86
|
+
export declare function apiErrorFor(init: ApiErrorInit): ApiError;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What the SDK throws. Everything is a StreamFarmError:
|
|
4
|
+
*
|
|
5
|
+
* - ApiError and its subclasses: the API answered with an error. The class
|
|
6
|
+
* follows the HTTP status, `code` says exactly why (see ErrorCode);
|
|
7
|
+
* - ConnectionError and TimeoutError: no answer came;
|
|
8
|
+
* - WaitTimeoutError: a waiting helper (`streams.waitUntilLive`) gave up.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.WaitTimeoutError = exports.TimeoutError = exports.ConnectionError = exports.ServerError = exports.RateLimitError = exports.ValidationError = exports.ConflictError = exports.NotFoundError = exports.PermissionError = exports.AuthenticationError = exports.ApiError = exports.StreamFarmError = void 0;
|
|
12
|
+
exports.apiErrorFor = apiErrorFor;
|
|
13
|
+
class StreamFarmError extends Error {
|
|
14
|
+
constructor(message, options) {
|
|
15
|
+
super(message, options);
|
|
16
|
+
this.name = new.target.name;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.StreamFarmError = StreamFarmError;
|
|
20
|
+
/** The API answered with an error: `{ error: { code, message, details? } }`. */
|
|
21
|
+
class ApiError extends StreamFarmError {
|
|
22
|
+
/** The HTTP status. */
|
|
23
|
+
status;
|
|
24
|
+
/** Why: `plan_limit`, `insufficient_scope`, … */
|
|
25
|
+
code;
|
|
26
|
+
/** More about it, by code: `{ required }` for `insufficient_scope`, `{ limit, max, current, plan }` for `plan_limit`, … */
|
|
27
|
+
details;
|
|
28
|
+
/** The request: method and path under the API's base URL. */
|
|
29
|
+
method;
|
|
30
|
+
path;
|
|
31
|
+
/** X-Correlation-Id of the answer: name it when you write to support. */
|
|
32
|
+
correlationId;
|
|
33
|
+
rateLimit;
|
|
34
|
+
constructor(init) {
|
|
35
|
+
super(`${init.status} ${init.code}: ${init.message} (${init.method} ${init.path})`);
|
|
36
|
+
this.status = init.status;
|
|
37
|
+
this.code = init.code;
|
|
38
|
+
this.details = init.details;
|
|
39
|
+
this.method = init.method;
|
|
40
|
+
this.path = init.path;
|
|
41
|
+
this.correlationId = init.correlationId;
|
|
42
|
+
this.rateLimit = init.rateLimit;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ApiError = ApiError;
|
|
46
|
+
/** 401: no key, or it is wrong, revoked or expired. */
|
|
47
|
+
class AuthenticationError extends ApiError {
|
|
48
|
+
}
|
|
49
|
+
exports.AuthenticationError = AuthenticationError;
|
|
50
|
+
/** 403: the key lacks a scope (`insufficient_scope`), may not make streams (`forbidden`), or the tariff doesn't allow it (`plan_limit`). */
|
|
51
|
+
class PermissionError extends ApiError {
|
|
52
|
+
}
|
|
53
|
+
exports.PermissionError = PermissionError;
|
|
54
|
+
/** 404: there is no such object, or it is outside the key's streams. */
|
|
55
|
+
class NotFoundError extends ApiError {
|
|
56
|
+
}
|
|
57
|
+
exports.NotFoundError = NotFoundError;
|
|
58
|
+
/** 409: the state doesn't allow it now (`stream_not_live`, `connection_required`, `ad_on_air`, …). */
|
|
59
|
+
class ConflictError extends ApiError {
|
|
60
|
+
}
|
|
61
|
+
exports.ConflictError = ConflictError;
|
|
62
|
+
/** 400 and 422: the request was refused as it is (`bad_request`, `ad_incomplete`, `not_supported`, …). */
|
|
63
|
+
class ValidationError extends ApiError {
|
|
64
|
+
}
|
|
65
|
+
exports.ValidationError = ValidationError;
|
|
66
|
+
/** 429: over the key's request limit. */
|
|
67
|
+
class RateLimitError extends ApiError {
|
|
68
|
+
/** Seconds to wait before trying again, from Retry-After. */
|
|
69
|
+
retryAfter;
|
|
70
|
+
constructor(init) {
|
|
71
|
+
super(init);
|
|
72
|
+
this.retryAfter = init.retryAfter ?? null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.RateLimitError = RateLimitError;
|
|
76
|
+
/** 5xx: the API, the region's media server, the studio's room server or a platform failed. */
|
|
77
|
+
class ServerError extends ApiError {
|
|
78
|
+
}
|
|
79
|
+
exports.ServerError = ServerError;
|
|
80
|
+
/** No answer: DNS, TLS, the connection dropped. `cause` holds what fetch threw. */
|
|
81
|
+
class ConnectionError extends StreamFarmError {
|
|
82
|
+
}
|
|
83
|
+
exports.ConnectionError = ConnectionError;
|
|
84
|
+
/** No answer within the request's timeout. */
|
|
85
|
+
class TimeoutError extends ConnectionError {
|
|
86
|
+
}
|
|
87
|
+
exports.TimeoutError = TimeoutError;
|
|
88
|
+
/** A waiting helper ran out of time (`streams.waitUntilLive`). */
|
|
89
|
+
class WaitTimeoutError extends StreamFarmError {
|
|
90
|
+
}
|
|
91
|
+
exports.WaitTimeoutError = WaitTimeoutError;
|
|
92
|
+
/** The ApiError subclass for an HTTP status. */
|
|
93
|
+
function apiErrorFor(init) {
|
|
94
|
+
const { status } = init;
|
|
95
|
+
if (status === 401)
|
|
96
|
+
return new AuthenticationError(init);
|
|
97
|
+
if (status === 403)
|
|
98
|
+
return new PermissionError(init);
|
|
99
|
+
if (status === 404)
|
|
100
|
+
return new NotFoundError(init);
|
|
101
|
+
if (status === 409)
|
|
102
|
+
return new ConflictError(init);
|
|
103
|
+
if (status === 400 || status === 422)
|
|
104
|
+
return new ValidationError(init);
|
|
105
|
+
if (status === 429)
|
|
106
|
+
return new RateLimitError(init);
|
|
107
|
+
if (status >= 500)
|
|
108
|
+
return new ServerError(init);
|
|
109
|
+
return new ApiError(init);
|
|
110
|
+
}
|