@restless-stream/core 0.1.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.
@@ -0,0 +1,361 @@
1
+ type StreamSnippetLanguage = 'javascript' | 'python' | 'java' | 'ruby' | 'php' | 'csharp' | 'go' | 'rust';
2
+ type StreamApiKeyLocation = 'header' | 'urlParam';
3
+ interface StreamSnippetOptions {
4
+ language?: StreamSnippetLanguage;
5
+ includeAllLanguages?: boolean;
6
+ apiKeyLocation?: StreamApiKeyLocation;
7
+ }
8
+ interface StreamConnectionSnippetsInput extends StreamSnippetOptions {
9
+ streamId?: string;
10
+ websocketUrl?: string;
11
+ sseUrl?: string;
12
+ }
13
+ interface StreamSnippetLanguageOption {
14
+ label: string;
15
+ value: string;
16
+ }
17
+ interface StreamSnippetSet {
18
+ curl: string;
19
+ wget: string;
20
+ sse: string;
21
+ websocket: string;
22
+ }
23
+ interface StreamSnippetPayload {
24
+ availableLanguages: StreamSnippetLanguageOption[];
25
+ selectedLanguage: string;
26
+ selectedSnippets: StreamSnippetSet;
27
+ snippetsByLanguage?: Record<string, StreamSnippetSet>;
28
+ }
29
+ interface StreamRuntimeUrls {
30
+ sseUrl: string;
31
+ websocketUrl: string;
32
+ }
33
+ interface ConnectionSnippetsResponse {
34
+ runtime: StreamRuntimeUrls;
35
+ snippets: StreamSnippetPayload;
36
+ }
37
+
38
+ interface DirectSetupInput extends StreamSnippetOptions {
39
+ method: HTTPMethod;
40
+ url: string;
41
+ headers?: JsonObject;
42
+ body?: JsonObject;
43
+ payloadMode?: StreamPayloadMode;
44
+ jqFilter?: string;
45
+ pollingInterval?: number;
46
+ pollingStrategies?: PollingStrategy[];
47
+ }
48
+ interface DirectCommandSet {
49
+ curl: string;
50
+ wget: string;
51
+ }
52
+ interface DirectSetupResponse {
53
+ commands: {
54
+ header: DirectCommandSet;
55
+ urlParam: DirectCommandSet;
56
+ };
57
+ runtime: {
58
+ auth: {
59
+ apiKeyLocation: StreamApiKeyLocation;
60
+ headerExample: string;
61
+ };
62
+ directSseUrl: string;
63
+ directWebsocketUrl: string;
64
+ };
65
+ snippets: StreamSnippetPayload;
66
+ streamConfig: {
67
+ targetUrl: string;
68
+ method: HTTPMethod;
69
+ headers?: JsonObject | null;
70
+ body?: JsonObject | null;
71
+ jqFilter?: string | null;
72
+ payloadMode?: StreamPayloadMode | null;
73
+ pollingInterval?: number | null;
74
+ pollingStrategies?: PollingStrategy[] | null;
75
+ };
76
+ }
77
+ interface DirectSessionInput {
78
+ dedupeKey: string;
79
+ method: HTTPMethod;
80
+ url: string;
81
+ headers?: JsonObject;
82
+ body?: JsonObject;
83
+ payloadMode?: StreamPayloadMode;
84
+ jqFilter?: string;
85
+ pollingInterval?: number;
86
+ pollingStrategies?: PollingStrategy[];
87
+ }
88
+ interface DirectSessionResponse {
89
+ sessionId: string;
90
+ wsUrl: string;
91
+ sseUrl: string;
92
+ expiresAt: string;
93
+ created: boolean;
94
+ dedupeKey: string;
95
+ }
96
+ interface DirectRuntimeUrlInput {
97
+ url: string;
98
+ method?: HTTPMethod;
99
+ headers?: JsonObject;
100
+ body?: JsonObject;
101
+ jqFilter?: string;
102
+ pollingInterval?: number;
103
+ pollingStrategies?: PollingStrategy[];
104
+ payloadMode?: StreamPayloadMode;
105
+ apiKey?: string;
106
+ }
107
+
108
+ type StreamStatus = 'ACTIVE' | 'INACTIVE';
109
+ type StreamPayloadMode = 'FULL_DATA' | 'JSON_PATCH';
110
+ interface PollingStrategy {
111
+ startTime: string;
112
+ endTime: string;
113
+ intervalSeconds: number;
114
+ }
115
+ interface PaginationInfo {
116
+ hasNextPage: boolean;
117
+ }
118
+ interface Stream {
119
+ id: string;
120
+ businessId: string;
121
+ name: string;
122
+ description?: string | null;
123
+ status: StreamStatus;
124
+ method: HTTPMethod;
125
+ url: string;
126
+ headers?: JsonObject | null;
127
+ body?: JsonObject | null;
128
+ payloadMode: StreamPayloadMode;
129
+ jqFilter?: string | null;
130
+ hmacSignatureEnabled: boolean;
131
+ pollingInterval: number;
132
+ pollingStrategies?: PollingStrategy[] | null;
133
+ createdAt: string;
134
+ updatedAt: string;
135
+ wsUrl: string;
136
+ sseUrl: string;
137
+ }
138
+ interface StreamsResponse {
139
+ streams: Stream[];
140
+ paginationInfo: PaginationInfo;
141
+ }
142
+ interface BaseActionResponse {
143
+ id: string;
144
+ affected: boolean;
145
+ }
146
+ interface StreamCreditUsageChargeTypeBreakdown {
147
+ chargeType: string;
148
+ creditsUsed: number;
149
+ }
150
+ interface DailyStreamCreditUsage {
151
+ date: string;
152
+ creditsUsed: number;
153
+ chargeTypeBreakdown: StreamCreditUsageChargeTypeBreakdown[];
154
+ }
155
+ interface StreamCreditUsageStats {
156
+ totalBurnedLastWeek: number;
157
+ totalBurnedLastMonth: number;
158
+ dailyUsage: DailyStreamCreditUsage[];
159
+ }
160
+ interface StreamWriteInput {
161
+ name: string;
162
+ description: string;
163
+ status: StreamStatus;
164
+ method: HTTPMethod;
165
+ url: string;
166
+ apiKey?: string;
167
+ headers?: JsonObject | null;
168
+ body?: JsonObject | null;
169
+ payloadMode: StreamPayloadMode;
170
+ jqFilter?: string | null;
171
+ hmacSignatureEnabled?: boolean | null;
172
+ pollingInterval: number;
173
+ pollingStrategies?: PollingStrategy[] | null;
174
+ }
175
+ interface StreamUpdateInput {
176
+ apiKey?: string;
177
+ name?: string;
178
+ description?: string | null;
179
+ status?: StreamStatus;
180
+ method?: HTTPMethod;
181
+ url?: string;
182
+ headers?: JsonObject | null;
183
+ body?: JsonObject | null;
184
+ payloadMode?: StreamPayloadMode;
185
+ jqFilter?: string | null;
186
+ hmacSignatureEnabled?: boolean | null;
187
+ pollingInterval?: number;
188
+ pollingStrategies?: PollingStrategy[] | null;
189
+ }
190
+ interface ListStreamsInput {
191
+ limit?: number;
192
+ offset?: number;
193
+ }
194
+
195
+ type RuntimeIdentifier = {
196
+ streamId: string;
197
+ sessionId?: never;
198
+ } | {
199
+ sessionId: string;
200
+ streamId?: never;
201
+ };
202
+ interface RuntimeUrlOptions {
203
+ cursor?: number | string;
204
+ since?: number | string;
205
+ }
206
+ interface StreamEventMeta {
207
+ timestamp: string;
208
+ attempt_id: string;
209
+ status?: number;
210
+ latency_ms: number;
211
+ payload_mode_fallback?: StreamPayloadMode;
212
+ }
213
+ interface StreamUpdateEvent<TData = unknown> {
214
+ type: 'update';
215
+ meta: StreamEventMeta;
216
+ data: TData;
217
+ signature?: string;
218
+ }
219
+ interface StreamErrorEvent {
220
+ type: 'error';
221
+ meta?: Partial<StreamEventMeta>;
222
+ error: {
223
+ code: string;
224
+ message: string;
225
+ };
226
+ }
227
+ type StreamEvent<TData = unknown> = StreamUpdateEvent<TData> | StreamErrorEvent;
228
+ interface SseMessage<TData = unknown> {
229
+ id?: string;
230
+ event?: string;
231
+ retry?: number;
232
+ data: string;
233
+ parsed?: TData;
234
+ }
235
+ interface SseIterableOptions {
236
+ url: string;
237
+ headers?: Record<string, string>;
238
+ signal?: AbortSignal;
239
+ reconnect?: boolean;
240
+ reconnectDelayMs?: number;
241
+ maxReconnectDelayMs?: number;
242
+ cursor?: number | string;
243
+ since?: number | string;
244
+ fetch?: typeof fetch;
245
+ }
246
+ interface SubscribeSseOptions extends Omit<SseIterableOptions, 'fetch' | 'headers' | 'url'> {
247
+ sseUrl: string;
248
+ headers?: Record<string, string>;
249
+ allowApiKeyInUrl?: boolean;
250
+ }
251
+ interface DirectSubscribeSseOptions extends Omit<SubscribeSseOptions, 'sseUrl'>, RuntimeUrlOptions {
252
+ }
253
+ interface DirectSubscribeWebSocketOptions extends Omit<WebSocketIterableOptions, 'url'>, RuntimeUrlOptions {
254
+ }
255
+ interface WebSocketIterableOptions {
256
+ url: string;
257
+ protocols?: string | string[];
258
+ signal?: AbortSignal;
259
+ WebSocket?: WebSocketConstructor;
260
+ }
261
+ type WebSocketConstructor = new (url: string | URL, protocols?: string | string[]) => WebSocketLike;
262
+ interface WebSocketLike {
263
+ readonly readyState: number;
264
+ onopen: ((event: Event) => void) | null;
265
+ onmessage: ((event: MessageEvent) => void) | null;
266
+ onerror: ((event: Event) => void) | null;
267
+ onclose: ((event: CloseEvent) => void) | null;
268
+ close(code?: number, reason?: string): void;
269
+ }
270
+ type DirectRuntimeOptionsInput = DirectRuntimeUrlInput;
271
+
272
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
273
+ type JsonObject = Record<string, unknown>;
274
+
275
+ interface RestlessClientOptions {
276
+ apiBaseUrl?: string;
277
+ streamBaseUrl?: string;
278
+ apiKey?: string;
279
+ fetch?: typeof fetch;
280
+ headers?: Record<string, string>;
281
+ }
282
+ type RestlessClientConfig = RestlessClientOptions;
283
+ type RestlessStreamEvent<TData = unknown> = StreamEvent<TData>;
284
+
285
+ interface RestlessClient {
286
+ readonly apiBaseUrl: string;
287
+ readonly streamBaseUrl: string;
288
+ readonly apiKey: string | undefined;
289
+ streams: RestlessStreamsClient;
290
+ direct: RestlessDirectClient;
291
+ urls: RestlessUrlBuilder;
292
+ listStreams(input?: ListStreamsInput): Promise<StreamsResponse>;
293
+ getStream(id: string): Promise<Stream>;
294
+ createStream(input: StreamWriteInput): Promise<Stream>;
295
+ updateStream(id: string, input: StreamUpdateInput): Promise<Stream>;
296
+ startStream(id: string): Promise<Stream>;
297
+ stopStream(id: string): Promise<Stream>;
298
+ deleteStream(id: string): Promise<BaseActionResponse>;
299
+ validateApiKey(apiKey?: string): Promise<BaseActionResponse>;
300
+ creditUsageStats(id: string): Promise<StreamCreditUsageStats>;
301
+ connectionSnippets(input: StreamConnectionSnippetsInput): Promise<ConnectionSnippetsResponse>;
302
+ runtimeHeaders(apiKey?: string): Record<string, string>;
303
+ sse<TData = StreamEvent>(url: string, options?: Omit<SseIterableOptions, 'url' | 'headers' | 'fetch'>): AsyncIterable<SseMessage<TData>>;
304
+ subscribeSse<TData = unknown>(options: SubscribeSseOptions): AsyncIterable<StreamEvent<TData>>;
305
+ websocket<TData = StreamEvent>(url: string, options?: Omit<WebSocketIterableOptions, 'url'>): AsyncIterable<TData | string>;
306
+ subscribeWebSocket<TData = StreamEvent>(url: string, options?: Omit<WebSocketIterableOptions, 'url'>): AsyncIterable<TData | string>;
307
+ }
308
+ interface RestlessStreamsClient {
309
+ list(input?: ListStreamsInput): Promise<StreamsResponse>;
310
+ get(id: string): Promise<Stream>;
311
+ create(input: StreamWriteInput): Promise<Stream>;
312
+ update(id: string, input: StreamUpdateInput): Promise<Stream>;
313
+ start(id: string): Promise<Stream>;
314
+ stop(id: string): Promise<Stream>;
315
+ delete(id: string): Promise<BaseActionResponse>;
316
+ validateApiKey(apiKey?: string): Promise<BaseActionResponse>;
317
+ creditUsageStats(id: string): Promise<StreamCreditUsageStats>;
318
+ connectionSnippets(input: StreamConnectionSnippetsInput): Promise<ConnectionSnippetsResponse>;
319
+ subscribeSse<TData = unknown>(options: SubscribeSseOptions): AsyncIterable<StreamEvent<TData>>;
320
+ subscribeWebSocket<TData = StreamEvent>(url: string, options?: Omit<WebSocketIterableOptions, 'url'>): AsyncIterable<TData | string>;
321
+ }
322
+ interface RestlessDirectClient {
323
+ setup(input: DirectSetupInput): Promise<DirectSetupResponse>;
324
+ createSession(input: DirectSessionInput): Promise<DirectSessionResponse>;
325
+ subscribeSse<TData = unknown>(input: DirectRuntimeUrlInput, options?: DirectSubscribeSseOptions): AsyncIterable<StreamEvent<TData>>;
326
+ subscribeWebSocket<TData = StreamEvent>(input: DirectRuntimeUrlInput, options?: DirectSubscribeWebSocketOptions): AsyncIterable<TData | string>;
327
+ }
328
+ interface RestlessUrlBuilder {
329
+ sse(identifier: RuntimeIdentifier, options?: RuntimeUrlOptions): string;
330
+ websocket(identifier: RuntimeIdentifier, options?: RuntimeUrlOptions): string;
331
+ directSse(input: DirectRuntimeUrlInput, options?: RuntimeUrlOptions): string;
332
+ directWebSocket(input: DirectRuntimeUrlInput, options?: RuntimeUrlOptions): string;
333
+ }
334
+
335
+ declare const DEFAULT_API_BASE_URL = "https://api.restlessapi.stream";
336
+ declare const DEFAULT_STREAM_BASE_URL = "https://stream.restlessapi.stream";
337
+ declare const createRestlessClient: (options?: RestlessClientOptions) => RestlessClient;
338
+
339
+ declare class RestlessApiError extends Error {
340
+ readonly status: number;
341
+ readonly statusText: string;
342
+ readonly body: unknown;
343
+ readonly headers: Headers;
344
+ constructor(response: Response, body: unknown, message?: string);
345
+ }
346
+
347
+ declare function streamSse<TData = unknown>(options: SseIterableOptions): AsyncIterable<SseMessage<TData>>;
348
+ declare function parseSseStream<TData = unknown>(body: ReadableStream<Uint8Array>): AsyncIterable<SseMessage<TData>>;
349
+
350
+ declare function streamWebSocket<TData = unknown>(options: WebSocketIterableOptions): AsyncIterable<TData | string>;
351
+
352
+ declare const normalizeBaseUrl: (baseUrl: string) => string;
353
+ declare const toWebSocketStreamUrl: (sseUrl: string) => string;
354
+ declare const buildSseUrl: (baseUrl: string | undefined, identifier: RuntimeIdentifier, options?: RuntimeUrlOptions) => string;
355
+ declare const buildWebSocketUrl: (baseUrl: string | undefined, identifier: RuntimeIdentifier, options?: RuntimeUrlOptions) => string;
356
+ declare const buildDirectSseUrl: (baseUrl: string | undefined, input: DirectRuntimeUrlInput, options?: RuntimeUrlOptions) => string;
357
+ declare const buildDirectWebSocketUrl: (baseUrl: string | undefined, input: DirectRuntimeUrlInput, options?: RuntimeUrlOptions) => string;
358
+ declare const appendDirectQueryParams: (params: URLSearchParams, input: DirectRuntimeUrlInput) => void;
359
+ declare const withRuntimeCursor: (url: string, options: RuntimeUrlOptions) => string;
360
+
361
+ export { type BaseActionResponse, type ConnectionSnippetsResponse, DEFAULT_API_BASE_URL, DEFAULT_STREAM_BASE_URL, type DailyStreamCreditUsage, type DirectCommandSet, type DirectRuntimeOptionsInput, type DirectRuntimeUrlInput, type DirectSessionInput, type DirectSessionResponse, type DirectSetupInput, type DirectSetupResponse, type DirectSubscribeSseOptions, type DirectSubscribeWebSocketOptions, type HTTPMethod, type JsonObject, type ListStreamsInput, type PaginationInfo, type PollingStrategy, RestlessApiError, type RestlessClient, type RestlessClientConfig, type RestlessClientOptions, type RestlessDirectClient, type RestlessStreamEvent, type RestlessStreamsClient, type RestlessUrlBuilder, type RuntimeIdentifier, type RuntimeUrlOptions, type SseIterableOptions, type SseMessage, type Stream, type StreamApiKeyLocation, type StreamConnectionSnippetsInput, type StreamCreditUsageChargeTypeBreakdown, type StreamCreditUsageStats, type StreamErrorEvent, type StreamEvent, type StreamEventMeta, type StreamPayloadMode, type StreamRuntimeUrls, type StreamSnippetLanguage, type StreamSnippetLanguageOption, type StreamSnippetOptions, type StreamSnippetPayload, type StreamSnippetSet, type StreamStatus, type StreamUpdateEvent, type StreamUpdateInput, type StreamWriteInput, type StreamsResponse, type SubscribeSseOptions, type WebSocketConstructor, type WebSocketIterableOptions, type WebSocketLike, appendDirectQueryParams, buildDirectSseUrl, buildDirectWebSocketUrl, buildSseUrl, buildWebSocketUrl, createRestlessClient, normalizeBaseUrl, parseSseStream, streamSse, streamWebSocket, toWebSocketStreamUrl, withRuntimeCursor };