@gigadrive/sdk 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 +177 -0
- package/dist/index.d.mts +2523 -1
- package/dist/index.d.ts +2523 -1
- package/dist/index.js +2148 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2089 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2524 @@
|
|
|
1
|
+
/** The result of a credential provider's token fetch. */
|
|
2
|
+
interface TokenResult {
|
|
3
|
+
/** The access token to use in API requests. */
|
|
4
|
+
accessToken: string;
|
|
5
|
+
/** Epoch milliseconds when the token expires, or `null` for tokens that never expire (e.g. static bearer tokens). */
|
|
6
|
+
expiresAt: number | null;
|
|
7
|
+
/** A refresh token for obtaining new access tokens, if the provider supports token rotation. */
|
|
8
|
+
refreshToken?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A strategy for obtaining access tokens. The SDK ships with four built-in
|
|
12
|
+
* providers (see {@link resolveCredentialProvider} for automatic selection),
|
|
13
|
+
* but you can implement this interface for custom auth flows.
|
|
14
|
+
*/
|
|
15
|
+
interface CredentialProvider {
|
|
16
|
+
/** A string identifying the provider type (e.g. `"oauth2-client-credentials"`, `"bearer"`). */
|
|
17
|
+
readonly type: string;
|
|
18
|
+
/** Fetch a new access token. May perform network requests (e.g. OAuth2 token exchange). */
|
|
19
|
+
getToken(): Promise<TokenResult>;
|
|
20
|
+
}
|
|
1
21
|
|
|
2
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Manages the access-token lifecycle: caching, automatic expiry detection,
|
|
24
|
+
* proactive refresh, and concurrent-call deduplication.
|
|
25
|
+
*
|
|
26
|
+
* When multiple API requests fire simultaneously with an expired token, only
|
|
27
|
+
* a single refresh call is made — all concurrent callers await the same
|
|
28
|
+
* pending Promise. This prevents a "thundering herd" of token requests.
|
|
29
|
+
*
|
|
30
|
+
* @internal Used internally by {@link HttpClient}. Not part of the public API.
|
|
31
|
+
*/
|
|
32
|
+
declare class TokenManager {
|
|
33
|
+
private readonly provider;
|
|
34
|
+
private cachedToken;
|
|
35
|
+
private expiresAt;
|
|
36
|
+
private pendingRefresh;
|
|
37
|
+
constructor(provider: CredentialProvider);
|
|
38
|
+
/**
|
|
39
|
+
* Returns a valid access token. Uses the cached token if still valid,
|
|
40
|
+
* otherwise fetches a new one from the credential provider.
|
|
41
|
+
*
|
|
42
|
+
* Concurrent calls are deduplicated — only one refresh runs at a time.
|
|
43
|
+
*/
|
|
44
|
+
getToken(): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Invalidates the cached token. The next `getToken()` call will trigger a refresh.
|
|
47
|
+
*/
|
|
48
|
+
invalidate(): void;
|
|
49
|
+
private refresh;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A paginated API response. List endpoints return this shape.
|
|
54
|
+
*
|
|
55
|
+
* @typeParam T - The type of each item in the list.
|
|
56
|
+
*/
|
|
57
|
+
interface Paginated<T> {
|
|
58
|
+
/** The items on the current page. */
|
|
59
|
+
items: T[];
|
|
60
|
+
/** The total number of items across all pages. */
|
|
61
|
+
total: number;
|
|
62
|
+
/** An opaque cursor for the next page, present on cursor-paginated endpoints when more items remain. */
|
|
63
|
+
nextCursor?: string;
|
|
64
|
+
}
|
|
65
|
+
/** A value that can be serialized into a query-string parameter. `undefined` values are omitted. */
|
|
66
|
+
type QueryValue = string | number | boolean | undefined;
|
|
67
|
+
/** Common pagination query parameters accepted by list endpoints. */
|
|
68
|
+
interface ListQuery {
|
|
69
|
+
/** 1-indexed page number (for page/`perPage`-style pagination). */
|
|
70
|
+
page?: number;
|
|
71
|
+
/** Maximum number of items per page. */
|
|
72
|
+
perPage?: number;
|
|
73
|
+
/** Opaque cursor for cursor-based pagination (from a previous response's `nextCursor`). */
|
|
74
|
+
cursor?: string;
|
|
75
|
+
}
|
|
76
|
+
/** @internal */
|
|
77
|
+
interface RequestOptions {
|
|
78
|
+
query?: Record<string, QueryValue>;
|
|
79
|
+
body?: unknown;
|
|
80
|
+
headers?: Record<string, string>;
|
|
81
|
+
/** Abort signal to cancel the request (and any 401-refresh retry). */
|
|
82
|
+
signal?: AbortSignal;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Low-level HTTP client used internally by all resource classes. Handles
|
|
86
|
+
* authentication header injection, JSON serialization, error mapping, and
|
|
87
|
+
* automatic retry on 401 responses.
|
|
88
|
+
*
|
|
89
|
+
* You do not need to use this class directly — interact with the API through
|
|
90
|
+
* the resource properties on {@link GigadriveClient} instead.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
declare class HttpClient {
|
|
95
|
+
private readonly baseUrl;
|
|
96
|
+
private readonly tokenManager;
|
|
97
|
+
private readonly fetchFn;
|
|
98
|
+
constructor(baseUrl: string, tokenManager: TokenManager, fetchFn: typeof globalThis.fetch);
|
|
99
|
+
/** @internal */
|
|
100
|
+
get<T>(path: string, options?: Pick<RequestOptions, 'query' | 'signal'>): Promise<T>;
|
|
101
|
+
/** @internal */
|
|
102
|
+
post<T>(path: string, body?: unknown, options?: Pick<RequestOptions, 'headers' | 'query' | 'signal'>): Promise<T>;
|
|
103
|
+
/** @internal */
|
|
104
|
+
put<T>(path: string, body?: unknown, options?: Pick<RequestOptions, 'headers' | 'query' | 'signal'>): Promise<T>;
|
|
105
|
+
/** @internal */
|
|
106
|
+
patch<T>(path: string, body?: unknown, options?: Pick<RequestOptions, 'headers' | 'query' | 'signal'>): Promise<T>;
|
|
107
|
+
/** @internal */
|
|
108
|
+
delete<T>(path: string, options?: Pick<RequestOptions, 'query' | 'signal'>): Promise<T>;
|
|
109
|
+
/** @internal */
|
|
110
|
+
postRaw<T>(path: string, body: string | ArrayBuffer | Uint8Array | ReadableStream | Blob | FormData, headers?: Record<string, string>): Promise<T>;
|
|
111
|
+
/**
|
|
112
|
+
* Make an authenticated request and return the raw `Response` without parsing
|
|
113
|
+
* the body. Used for streamed (SSE) and binary responses.
|
|
114
|
+
*
|
|
115
|
+
* @throws {@link ApiError} if the response status is not OK.
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
requestStream(method: string, path: string, options?: RequestOptions): Promise<Response>;
|
|
119
|
+
/**
|
|
120
|
+
* Make a raw fetch request to an arbitrary URL (e.g. presigned upload URLs
|
|
121
|
+
* or resumable upload endpoints). No auth header is injected and the base URL
|
|
122
|
+
* is not prepended.
|
|
123
|
+
*
|
|
124
|
+
* @param url - The full URL to fetch.
|
|
125
|
+
* @param init - Standard `RequestInit` options.
|
|
126
|
+
* @returns The raw `Response` object.
|
|
127
|
+
* @throws {@link ApiError} if the response status is not OK.
|
|
128
|
+
*
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
fetchRaw(url: string, init: RequestInit): Promise<Response>;
|
|
132
|
+
private request;
|
|
133
|
+
/** Perform the request with auth injection and a single 401 refresh-retry. */
|
|
134
|
+
private fetchWithAuth;
|
|
135
|
+
private handleResponse;
|
|
136
|
+
private toApiError;
|
|
137
|
+
private buildUrl;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Base class for all API resource classes. Provides access to the shared
|
|
142
|
+
* HTTP client for making authenticated API requests.
|
|
143
|
+
*
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
declare class BaseResource {
|
|
147
|
+
protected readonly httpClient: HttpClient;
|
|
148
|
+
constructor(httpClient: HttpClient);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Types for the AI Gateway runtime endpoints (`/ai/v1`). The chat/responses
|
|
153
|
+
* shapes are OpenAI-compatible; additional fields are passed through, so request
|
|
154
|
+
* types include an index signature and responses surface the common fields.
|
|
155
|
+
*/
|
|
156
|
+
/** Provider routing preferences accepted by inference endpoints. */
|
|
157
|
+
interface ProviderRouting {
|
|
158
|
+
/** Preferred provider order (e.g. `["openai", "anthropic"]`). */
|
|
159
|
+
order?: string[];
|
|
160
|
+
/** Whether the gateway may fall back to other providers. */
|
|
161
|
+
allow_fallbacks?: boolean;
|
|
162
|
+
/** Require zero-data-retention capable routing. */
|
|
163
|
+
require_zdr?: boolean;
|
|
164
|
+
/** Restrict routing to exactly the providers in `order`. */
|
|
165
|
+
restrict_to_order?: boolean;
|
|
166
|
+
}
|
|
167
|
+
/** A text or multi-part content part in a chat message. */
|
|
168
|
+
type ChatCompletionContentPart = {
|
|
169
|
+
type: 'text';
|
|
170
|
+
text: string;
|
|
171
|
+
} | {
|
|
172
|
+
type: 'image_url';
|
|
173
|
+
image_url: {
|
|
174
|
+
url: string;
|
|
175
|
+
detail?: 'auto' | 'low' | 'high';
|
|
176
|
+
};
|
|
177
|
+
} | {
|
|
178
|
+
type: 'file';
|
|
179
|
+
file: {
|
|
180
|
+
filename?: string;
|
|
181
|
+
file_data?: string;
|
|
182
|
+
file_id?: string;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
/** A message in a chat completion request or response. */
|
|
186
|
+
interface ChatCompletionMessage {
|
|
187
|
+
/** The role of the message author (e.g. `"system"`, `"user"`, `"assistant"`). */
|
|
188
|
+
role: string;
|
|
189
|
+
/** The message content — plain text or an array of content parts. */
|
|
190
|
+
content: string | ChatCompletionContentPart[] | null;
|
|
191
|
+
/** Additional OpenAI-compatible fields (e.g. `tool_calls`) are passed through. */
|
|
192
|
+
[key: string]: unknown;
|
|
193
|
+
}
|
|
194
|
+
/** Request for an OpenAI-compatible chat completion. */
|
|
195
|
+
interface ChatCompletionRequest {
|
|
196
|
+
/** The model ID (e.g. `"openai/gpt-4o"`). */
|
|
197
|
+
model: string;
|
|
198
|
+
/** The conversation messages. */
|
|
199
|
+
messages: ChatCompletionMessage[];
|
|
200
|
+
/** Sampling temperature (0–2). */
|
|
201
|
+
temperature?: number;
|
|
202
|
+
/** Nucleus sampling parameter (0–1). */
|
|
203
|
+
top_p?: number;
|
|
204
|
+
/** Maximum number of tokens to generate. */
|
|
205
|
+
max_tokens?: number;
|
|
206
|
+
/** Whether to stream the response. Prefer {@link AiGatewayResource.chatCompletionsStream}. */
|
|
207
|
+
stream?: boolean;
|
|
208
|
+
/** Tool/function definitions. */
|
|
209
|
+
tools?: unknown[];
|
|
210
|
+
/** Tool choice strategy. */
|
|
211
|
+
tool_choice?: unknown;
|
|
212
|
+
/** Provider routing preferences. */
|
|
213
|
+
provider?: ProviderRouting;
|
|
214
|
+
/** Additional OpenAI-compatible parameters are passed through. */
|
|
215
|
+
[key: string]: unknown;
|
|
216
|
+
}
|
|
217
|
+
/** Token usage statistics. */
|
|
218
|
+
interface ChatCompletionUsage {
|
|
219
|
+
prompt_tokens: number;
|
|
220
|
+
completion_tokens: number;
|
|
221
|
+
total_tokens: number;
|
|
222
|
+
}
|
|
223
|
+
/** A single completion choice. */
|
|
224
|
+
interface ChatCompletionChoice {
|
|
225
|
+
index: number;
|
|
226
|
+
message: ChatCompletionMessage;
|
|
227
|
+
finish_reason: string | null;
|
|
228
|
+
}
|
|
229
|
+
/** Response from an OpenAI-compatible chat completion. */
|
|
230
|
+
interface ChatCompletionResponse {
|
|
231
|
+
id: string;
|
|
232
|
+
object: string;
|
|
233
|
+
created: number;
|
|
234
|
+
model: string;
|
|
235
|
+
choices: ChatCompletionChoice[];
|
|
236
|
+
usage?: ChatCompletionUsage;
|
|
237
|
+
system_fingerprint?: string;
|
|
238
|
+
/** Estimated cost of the request in micros of USD, when available. */
|
|
239
|
+
cost_micros?: number;
|
|
240
|
+
[key: string]: unknown;
|
|
241
|
+
}
|
|
242
|
+
/** A streamed chat completion chunk (`stream: true`). */
|
|
243
|
+
interface ChatCompletionChunk {
|
|
244
|
+
id: string;
|
|
245
|
+
object: string;
|
|
246
|
+
created: number;
|
|
247
|
+
model: string;
|
|
248
|
+
choices: Array<{
|
|
249
|
+
index: number;
|
|
250
|
+
delta: {
|
|
251
|
+
role?: string;
|
|
252
|
+
content?: string | null;
|
|
253
|
+
[key: string]: unknown;
|
|
254
|
+
};
|
|
255
|
+
finish_reason: string | null;
|
|
256
|
+
}>;
|
|
257
|
+
[key: string]: unknown;
|
|
258
|
+
}
|
|
259
|
+
/** Request for the Open Responses-compatible endpoint. */
|
|
260
|
+
interface ResponsesRequest {
|
|
261
|
+
model: string;
|
|
262
|
+
/** Provider routing preferences. */
|
|
263
|
+
provider?: ProviderRouting;
|
|
264
|
+
/** Whether to stream the response. */
|
|
265
|
+
stream?: boolean;
|
|
266
|
+
/** Additional Responses-compatible parameters are passed through. */
|
|
267
|
+
[key: string]: unknown;
|
|
268
|
+
}
|
|
269
|
+
/** Response from the Open Responses-compatible endpoint. */
|
|
270
|
+
interface ResponsesResponse {
|
|
271
|
+
id: string;
|
|
272
|
+
object: string;
|
|
273
|
+
status: string;
|
|
274
|
+
[key: string]: unknown;
|
|
275
|
+
}
|
|
276
|
+
/** Capability flags for an AI model. */
|
|
277
|
+
interface AiModelCapabilities {
|
|
278
|
+
chat: boolean;
|
|
279
|
+
streaming: boolean;
|
|
280
|
+
tools: boolean;
|
|
281
|
+
vision: boolean;
|
|
282
|
+
json_mode: boolean;
|
|
283
|
+
}
|
|
284
|
+
/** Display metadata for a routing provider that can serve a model. */
|
|
285
|
+
interface AiModelRoutingProvider {
|
|
286
|
+
id: string;
|
|
287
|
+
name: string;
|
|
288
|
+
logoUrl?: string;
|
|
289
|
+
supportsZdr: boolean;
|
|
290
|
+
}
|
|
291
|
+
/** An AI model available through the gateway. */
|
|
292
|
+
interface AiModel {
|
|
293
|
+
/** Model identifier to pass to inference endpoints (e.g. `"openai/gpt-4o"`). */
|
|
294
|
+
id: string;
|
|
295
|
+
/** Human-readable model name. */
|
|
296
|
+
name: string;
|
|
297
|
+
/** Primary provider family/owner. */
|
|
298
|
+
provider: string;
|
|
299
|
+
/** Logo URL for the primary provider, if available. */
|
|
300
|
+
providerLogoUrl?: string;
|
|
301
|
+
/** Capability flags. */
|
|
302
|
+
capabilities: AiModelCapabilities;
|
|
303
|
+
/** Supported input/output modalities, if declared. */
|
|
304
|
+
modalities?: {
|
|
305
|
+
input: string[];
|
|
306
|
+
output: string[];
|
|
307
|
+
};
|
|
308
|
+
/** Maximum combined input+output context window in tokens. */
|
|
309
|
+
contextWindow: number;
|
|
310
|
+
/** Maximum output tokens the gateway will request. */
|
|
311
|
+
maxOutputTokens: number;
|
|
312
|
+
/** Product-facing model summary, if configured. */
|
|
313
|
+
description?: string;
|
|
314
|
+
/** Provider route IDs that can serve this model. */
|
|
315
|
+
routingProviders: string[];
|
|
316
|
+
/** Display metadata for each routing provider. */
|
|
317
|
+
routingProviderDetails: AiModelRoutingProvider[];
|
|
318
|
+
/** Provider route IDs that support zero-data-retention. */
|
|
319
|
+
zdrProviders: string[];
|
|
320
|
+
}
|
|
321
|
+
/** Request for text-to-speech synthesis. */
|
|
322
|
+
interface SpeechRequest {
|
|
323
|
+
model: string;
|
|
324
|
+
/** The text to synthesize. */
|
|
325
|
+
input: string;
|
|
326
|
+
/** The voice to use. */
|
|
327
|
+
voice: string;
|
|
328
|
+
/** Output audio format. */
|
|
329
|
+
response_format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';
|
|
330
|
+
/** Playback speed (0.25–4.0). */
|
|
331
|
+
speed?: number;
|
|
332
|
+
/** Provider routing preferences. */
|
|
333
|
+
provider?: ProviderRouting;
|
|
334
|
+
[key: string]: unknown;
|
|
335
|
+
}
|
|
336
|
+
/** Request for speech-to-text transcription. */
|
|
337
|
+
interface TranscriptionRequest {
|
|
338
|
+
model: string;
|
|
339
|
+
/** The audio file to transcribe. */
|
|
340
|
+
file: Blob | Uint8Array | ArrayBuffer;
|
|
341
|
+
/** Filename to send with the file part. */
|
|
342
|
+
filename?: string;
|
|
343
|
+
/** Spoken language hint (ISO-639-1). */
|
|
344
|
+
language?: string;
|
|
345
|
+
/** Optional prompt to guide transcription. */
|
|
346
|
+
prompt?: string;
|
|
347
|
+
/** Sampling temperature. */
|
|
348
|
+
temperature?: number;
|
|
349
|
+
/** Response format. */
|
|
350
|
+
response_format?: string;
|
|
351
|
+
/** Additional fields are appended to the multipart form. */
|
|
352
|
+
[key: string]: unknown;
|
|
353
|
+
}
|
|
354
|
+
/** Response from a transcription request. */
|
|
355
|
+
interface TranscriptionResponse {
|
|
356
|
+
text: string;
|
|
357
|
+
language?: string;
|
|
358
|
+
duration?: number;
|
|
359
|
+
segments?: unknown[];
|
|
360
|
+
[key: string]: unknown;
|
|
361
|
+
}
|
|
362
|
+
/** Request for video generation. */
|
|
363
|
+
interface VideoGenerationRequest {
|
|
364
|
+
model: string;
|
|
365
|
+
prompt: string;
|
|
366
|
+
duration?: number;
|
|
367
|
+
resolution?: string;
|
|
368
|
+
fps?: number;
|
|
369
|
+
provider?: ProviderRouting;
|
|
370
|
+
[key: string]: unknown;
|
|
371
|
+
}
|
|
372
|
+
/** Response from a video generation request. */
|
|
373
|
+
interface VideoGenerationResponse {
|
|
374
|
+
id: string;
|
|
375
|
+
status: string;
|
|
376
|
+
video?: {
|
|
377
|
+
url: string;
|
|
378
|
+
duration?: number;
|
|
379
|
+
};
|
|
380
|
+
created_at?: number;
|
|
381
|
+
expires_at?: number;
|
|
382
|
+
[key: string]: unknown;
|
|
383
|
+
}
|
|
384
|
+
/** Response from listing video models. */
|
|
385
|
+
interface VideoModelList {
|
|
386
|
+
object: string;
|
|
387
|
+
data: Array<Record<string, unknown>>;
|
|
388
|
+
}
|
|
389
|
+
/** Per-request options for gateway calls (custom headers such as `X-Gigadrive-*`). */
|
|
390
|
+
interface GatewayRequestOptions {
|
|
391
|
+
/** Additional request headers (e.g. `X-Gigadrive-Application-Id`, `X-Gigadrive-End-User-Id`). */
|
|
392
|
+
headers?: Record<string, string>;
|
|
393
|
+
}
|
|
394
|
+
/** A gateway result paired with its raw response and surfaced metadata headers. */
|
|
395
|
+
interface GatewayResult<T> {
|
|
396
|
+
/** The parsed response body. */
|
|
397
|
+
data: T;
|
|
398
|
+
/** The raw `Response`, for reading additional headers. */
|
|
399
|
+
response: Response;
|
|
400
|
+
/** The `X-Gigadrive-Request-Id` header, if present. */
|
|
401
|
+
requestId?: string;
|
|
402
|
+
/** The `X-Gigadrive-Cost-Micros` header parsed as a number, if present. */
|
|
403
|
+
costMicros?: number;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** Text-to-speech and speech-to-text endpoints. */
|
|
407
|
+
declare class AiGatewayAudioResource extends BaseResource {
|
|
408
|
+
/**
|
|
409
|
+
* Synthesize speech from text. Returns the raw audio bytes.
|
|
410
|
+
*
|
|
411
|
+
* @returns The audio content as an `ArrayBuffer` (format per `response_format`).
|
|
412
|
+
*/
|
|
413
|
+
speech(data: SpeechRequest, options?: GatewayRequestOptions): Promise<ArrayBuffer>;
|
|
414
|
+
/**
|
|
415
|
+
* Transcribe an audio file to text. The file is sent as multipart form data.
|
|
416
|
+
*/
|
|
417
|
+
transcriptions(data: TranscriptionRequest, options?: GatewayRequestOptions): Promise<TranscriptionResponse>;
|
|
418
|
+
}
|
|
419
|
+
/** Video generation endpoints. */
|
|
420
|
+
declare class AiGatewayVideosResource extends BaseResource {
|
|
421
|
+
/** Generate a video from a prompt. */
|
|
422
|
+
generations(data: VideoGenerationRequest, options?: GatewayRequestOptions): Promise<VideoGenerationResponse>;
|
|
423
|
+
/** List the video models available through the gateway. */
|
|
424
|
+
listModels(): Promise<VideoModelList>;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Interact with the Gigadrive AI Gateway — an OpenAI-compatible API that routes
|
|
428
|
+
* requests to multiple AI providers. Accessed via {@link GigadriveClient.aiGateway}.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```ts
|
|
432
|
+
* // Chat completion
|
|
433
|
+
* const res = await client.aiGateway.chatCompletions({
|
|
434
|
+
* model: 'openai/gpt-4o',
|
|
435
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
436
|
+
* });
|
|
437
|
+
* console.log(res.choices[0].message.content);
|
|
438
|
+
*
|
|
439
|
+
* // Streamed chat completion
|
|
440
|
+
* for await (const chunk of client.aiGateway.chatCompletionsStream({
|
|
441
|
+
* model: 'openai/gpt-4o',
|
|
442
|
+
* messages: [{ role: 'user', content: 'Write a haiku.' }],
|
|
443
|
+
* })) {
|
|
444
|
+
* process.stdout.write(chunk.choices[0]?.delta.content ?? '');
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare class AiGatewayResource extends BaseResource {
|
|
449
|
+
/** Text-to-speech and speech-to-text. */
|
|
450
|
+
readonly audio: AiGatewayAudioResource;
|
|
451
|
+
/** Video generation. */
|
|
452
|
+
readonly videos: AiGatewayVideosResource;
|
|
453
|
+
constructor(httpClient: HttpClient);
|
|
454
|
+
/**
|
|
455
|
+
* Create a chat completion using the OpenAI-compatible endpoint.
|
|
456
|
+
*
|
|
457
|
+
* @param data - The chat completion request (model, messages, options, provider routing).
|
|
458
|
+
* @param options - Custom headers (e.g. `X-Gigadrive-Application-Id`).
|
|
459
|
+
*/
|
|
460
|
+
chatCompletions(data: ChatCompletionRequest, options?: GatewayRequestOptions): Promise<ChatCompletionResponse>;
|
|
461
|
+
/**
|
|
462
|
+
* Like {@link chatCompletions}, but also returns the raw response and the
|
|
463
|
+
* gateway request-id / cost headers.
|
|
464
|
+
*/
|
|
465
|
+
chatCompletionsWithResponse(data: ChatCompletionRequest, options?: GatewayRequestOptions): Promise<GatewayResult<ChatCompletionResponse>>;
|
|
466
|
+
/**
|
|
467
|
+
* Stream a chat completion as Server-Sent Events. Yields each chunk as it
|
|
468
|
+
* arrives and ends when the gateway closes the stream.
|
|
469
|
+
*/
|
|
470
|
+
chatCompletionsStream(data: ChatCompletionRequest, options?: GatewayRequestOptions): AsyncGenerator<ChatCompletionChunk>;
|
|
471
|
+
/**
|
|
472
|
+
* Create a response using the Open Responses-compatible endpoint.
|
|
473
|
+
*/
|
|
474
|
+
responses(data: ResponsesRequest, options?: GatewayRequestOptions): Promise<ResponsesResponse>;
|
|
475
|
+
/**
|
|
476
|
+
* Stream a response using the Open Responses-compatible endpoint.
|
|
477
|
+
*/
|
|
478
|
+
responsesStream(data: ResponsesRequest, options?: GatewayRequestOptions): AsyncGenerator<unknown>;
|
|
479
|
+
/**
|
|
480
|
+
* List all AI models available through the gateway.
|
|
481
|
+
*/
|
|
482
|
+
listModels(): Promise<Paginated<AiModel>>;
|
|
483
|
+
/**
|
|
484
|
+
* Get details for a specific AI model by its ID.
|
|
485
|
+
*
|
|
486
|
+
* @param modelId - The model identifier (e.g. `"openai/gpt-4o"`).
|
|
487
|
+
*/
|
|
488
|
+
getModel(modelId: string): Promise<AiModel>;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** An environment variable attached to an organization, application, or environment. */
|
|
492
|
+
interface EnvVar {
|
|
493
|
+
/** Unique identifier. */
|
|
494
|
+
id: string;
|
|
495
|
+
/** The variable name (e.g. `DATABASE_URL`). */
|
|
496
|
+
key: string;
|
|
497
|
+
/** The variable value. `null` when {@link sensitive} is `true` and the value is hidden from API responses. */
|
|
498
|
+
value: string | null;
|
|
499
|
+
/** When `true`, the value is redacted in API responses to protect secrets. */
|
|
500
|
+
sensitive: boolean;
|
|
501
|
+
/** The scope level at which this variable is defined. */
|
|
502
|
+
scope: 'organization' | 'application' | 'environment';
|
|
503
|
+
/** The environment ID, if this variable is scoped to a specific environment. */
|
|
504
|
+
environmentId: string | null;
|
|
505
|
+
/** The human-readable environment name, if scoped to a specific environment. */
|
|
506
|
+
environmentName: string | null;
|
|
507
|
+
/** ISO 8601 timestamp of when the variable was created. */
|
|
508
|
+
createdAt: string;
|
|
509
|
+
/** ISO 8601 timestamp of when the variable was last updated. */
|
|
510
|
+
updatedAt: string;
|
|
511
|
+
}
|
|
512
|
+
/** Input for creating a new environment variable. */
|
|
513
|
+
interface CreateEnvVarInput {
|
|
514
|
+
/** The variable name (e.g. `DATABASE_URL`). Must be unique within its scope. */
|
|
515
|
+
key: string;
|
|
516
|
+
/** The variable value. */
|
|
517
|
+
value: string;
|
|
518
|
+
/** Mark the variable as sensitive to hide its value in API responses. */
|
|
519
|
+
sensitive?: boolean;
|
|
520
|
+
/** The scope level. Defaults to the parent resource's scope. */
|
|
521
|
+
scope?: 'organization' | 'application' | 'environment';
|
|
522
|
+
/** The environment ID, when creating an environment-scoped variable. */
|
|
523
|
+
environmentId?: string;
|
|
524
|
+
}
|
|
525
|
+
/** Input for updating an existing environment variable. All fields are optional — only provided fields are changed. */
|
|
526
|
+
interface UpdateEnvVarInput {
|
|
527
|
+
/** New variable name. */
|
|
528
|
+
key?: string;
|
|
529
|
+
/** New variable value. */
|
|
530
|
+
value?: string;
|
|
531
|
+
/** Change the sensitive flag. */
|
|
532
|
+
sensitive?: boolean;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Manage environment variables scoped to an application.
|
|
537
|
+
* Accessed via `client.applications.envVars`.
|
|
538
|
+
*/
|
|
539
|
+
declare class ApplicationEnvVarsResource extends BaseResource {
|
|
540
|
+
/**
|
|
541
|
+
* List all environment variables for an application.
|
|
542
|
+
*
|
|
543
|
+
* @param applicationId - The application ID (UUID).
|
|
544
|
+
* @returns A paginated list of environment variables.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* const { items } = await client.applications.envVars.list('app-id');
|
|
549
|
+
* for (const v of items) {
|
|
550
|
+
* console.log(`${v.key}=${v.sensitive ? '***' : v.value}`);
|
|
551
|
+
* }
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
list(applicationId: string, query?: ListQuery): Promise<Paginated<EnvVar>>;
|
|
555
|
+
/**
|
|
556
|
+
* Create a new environment variable for an application.
|
|
557
|
+
*
|
|
558
|
+
* @param applicationId - The application ID (UUID).
|
|
559
|
+
* @param data - The variable key, value, and optional settings.
|
|
560
|
+
* @returns The newly created environment variable.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```ts
|
|
564
|
+
* const envVar = await client.applications.envVars.create('app-id', {
|
|
565
|
+
* key: 'DATABASE_URL',
|
|
566
|
+
* value: 'postgres://...',
|
|
567
|
+
* sensitive: true,
|
|
568
|
+
* });
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
create(applicationId: string, data: CreateEnvVarInput): Promise<EnvVar>;
|
|
572
|
+
/**
|
|
573
|
+
* Update an existing environment variable. Only the fields you provide
|
|
574
|
+
* will be changed; omitted fields are left unchanged.
|
|
575
|
+
*
|
|
576
|
+
* @param applicationId - The application ID (UUID).
|
|
577
|
+
* @param envVarId - The environment variable ID (UUID).
|
|
578
|
+
* @param data - The fields to update.
|
|
579
|
+
* @returns The updated environment variable.
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```ts
|
|
583
|
+
* await client.applications.envVars.update('app-id', 'var-id', {
|
|
584
|
+
* value: 'postgres://new-host/db',
|
|
585
|
+
* });
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
update(applicationId: string, envVarId: string, data: UpdateEnvVarInput): Promise<EnvVar>;
|
|
589
|
+
/**
|
|
590
|
+
* Permanently delete an environment variable.
|
|
591
|
+
*
|
|
592
|
+
* @param applicationId - The application ID (UUID).
|
|
593
|
+
* @param envVarId - The environment variable ID (UUID).
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* await client.applications.envVars.delete('app-id', 'var-id');
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
delete(applicationId: string, envVarId: string): Promise<void>;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** A nested reference to the application that served a request. */
|
|
604
|
+
interface NetworkRequestApplicationRef {
|
|
605
|
+
id: string;
|
|
606
|
+
name: string;
|
|
607
|
+
}
|
|
608
|
+
/** A nested reference to the deployment that served a request. */
|
|
609
|
+
interface NetworkRequestDeploymentRef {
|
|
610
|
+
id: string;
|
|
611
|
+
status: string;
|
|
612
|
+
}
|
|
613
|
+
/** A nested reference to the function route that handled a request. */
|
|
614
|
+
interface NetworkRequestFunctionRef {
|
|
615
|
+
id: string;
|
|
616
|
+
name: string | null;
|
|
617
|
+
path: string;
|
|
618
|
+
region: string | null;
|
|
619
|
+
}
|
|
620
|
+
/** A nested reference to the static asset that served a request. */
|
|
621
|
+
interface NetworkRequestAssetRef {
|
|
622
|
+
id: string;
|
|
623
|
+
path: string;
|
|
624
|
+
objectKey: string;
|
|
625
|
+
}
|
|
626
|
+
/** A nested reference to the storage bucket involved in a request. */
|
|
627
|
+
interface NetworkRequestBucketRef {
|
|
628
|
+
id: string;
|
|
629
|
+
name: string;
|
|
630
|
+
slug: string;
|
|
631
|
+
}
|
|
632
|
+
/** A nested reference to the storage object involved in a request. */
|
|
633
|
+
interface NetworkRequestObjectRef {
|
|
634
|
+
id: string;
|
|
635
|
+
key: string;
|
|
636
|
+
contentType: string | null;
|
|
637
|
+
}
|
|
638
|
+
/** The HTTP request details captured for a network request. */
|
|
639
|
+
interface NetworkRequestDetails {
|
|
640
|
+
method: string;
|
|
641
|
+
hostname: string;
|
|
642
|
+
path: string;
|
|
643
|
+
query: string | null;
|
|
644
|
+
protocol: string | null;
|
|
645
|
+
country: string | null;
|
|
646
|
+
userAgent: string | null;
|
|
647
|
+
referer: string | null;
|
|
648
|
+
}
|
|
649
|
+
/** The HTTP response details captured for a network request. */
|
|
650
|
+
interface NetworkResponseDetails {
|
|
651
|
+
status: number | null;
|
|
652
|
+
cacheStatus: 'hit' | 'miss' | 'bypass' | 'revalidated' | 'stale' | 'updating' | null;
|
|
653
|
+
cacheHit: boolean | null;
|
|
654
|
+
region: string | null;
|
|
655
|
+
edgeLocation: string | null;
|
|
656
|
+
}
|
|
657
|
+
/** Byte and timing metrics for a network request. */
|
|
658
|
+
interface NetworkRequestMetrics {
|
|
659
|
+
requestBodyBytes: number | null;
|
|
660
|
+
responseBodyBytes: number | null;
|
|
661
|
+
bytesSent: number | null;
|
|
662
|
+
durationMs: number | null;
|
|
663
|
+
}
|
|
664
|
+
/** A single observed request served through the Gigadrive Network edge (summary form). */
|
|
665
|
+
interface NetworkRequestSummary {
|
|
666
|
+
id: string;
|
|
667
|
+
application: NetworkRequestApplicationRef;
|
|
668
|
+
deployment: NetworkRequestDeploymentRef | null;
|
|
669
|
+
deploymentFunction: NetworkRequestFunctionRef | null;
|
|
670
|
+
deploymentAsset: NetworkRequestAssetRef | null;
|
|
671
|
+
storageBucket: NetworkRequestBucketRef | null;
|
|
672
|
+
storageObject: NetworkRequestObjectRef | null;
|
|
673
|
+
request: NetworkRequestDetails;
|
|
674
|
+
response: NetworkResponseDetails;
|
|
675
|
+
metrics: NetworkRequestMetrics;
|
|
676
|
+
startedAt: string;
|
|
677
|
+
completedAt: string | null;
|
|
678
|
+
}
|
|
679
|
+
/** A full network request record, including sanitized request/response headers. */
|
|
680
|
+
interface NetworkRequest extends NetworkRequestSummary {
|
|
681
|
+
/** Sanitized request headers captured for debugging. */
|
|
682
|
+
requestHeaders: Record<string, string>;
|
|
683
|
+
/** Sanitized response headers captured for debugging. */
|
|
684
|
+
responseHeaders: Record<string, string>;
|
|
685
|
+
}
|
|
686
|
+
/** Query filters for listing application requests. All fields are optional. */
|
|
687
|
+
interface ListRequestsQuery {
|
|
688
|
+
/** Filter to requests served by one deployment. */
|
|
689
|
+
deploymentId?: string;
|
|
690
|
+
/** Filter to requests served by one function route. */
|
|
691
|
+
deploymentFunctionId?: string;
|
|
692
|
+
/** Filter to requests served by one static asset route. */
|
|
693
|
+
deploymentAssetId?: string;
|
|
694
|
+
/** Filter to storage delivery requests for one bucket. */
|
|
695
|
+
storageBucketId?: string;
|
|
696
|
+
/** Filter to storage delivery requests for one object. */
|
|
697
|
+
storageObjectId?: string;
|
|
698
|
+
/** Only include requests that started at or after this ISO 8601 timestamp. */
|
|
699
|
+
from?: string;
|
|
700
|
+
/** Only include requests that started before or at this ISO 8601 timestamp. */
|
|
701
|
+
to?: string;
|
|
702
|
+
/** Maximum number of records to return. */
|
|
703
|
+
limit?: number;
|
|
704
|
+
/** Opaque cursor from a previous response's `nextCursor`. */
|
|
705
|
+
cursor?: string;
|
|
706
|
+
/** Filter by HTTP method (e.g. `"GET"`). */
|
|
707
|
+
method?: string;
|
|
708
|
+
/** Filter by exact HTTP status code. */
|
|
709
|
+
status?: number;
|
|
710
|
+
/** Filter by status family (`2`, `3`, `4`, or `5`). */
|
|
711
|
+
statusFamily?: number;
|
|
712
|
+
/** Filter by request hostname. */
|
|
713
|
+
hostname?: string;
|
|
714
|
+
/** Filter to requests whose path starts with this prefix. */
|
|
715
|
+
pathPrefix?: string;
|
|
716
|
+
/** Filter by ISO 3166-1 alpha-2 country code. */
|
|
717
|
+
country?: string;
|
|
718
|
+
/** Filter by origin region. */
|
|
719
|
+
region?: string;
|
|
720
|
+
/** Filter by edge location. */
|
|
721
|
+
edgeLocation?: string;
|
|
722
|
+
/** Filter by CDN cache state. */
|
|
723
|
+
cacheStatus?: string;
|
|
724
|
+
/** Filter by whether the response was served from cache. */
|
|
725
|
+
cacheHit?: boolean;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Read observed traffic (request logs) for an application. Accessed via
|
|
729
|
+
* `client.applications.requests`.
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```ts
|
|
733
|
+
* // Recent 5xx responses for a deployment
|
|
734
|
+
* const { items } = await client.applications.requests.list('app-id', {
|
|
735
|
+
* deploymentId: 'dep-id',
|
|
736
|
+
* statusFamily: 5,
|
|
737
|
+
* limit: 100,
|
|
738
|
+
* });
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
declare class ApplicationRequestsResource extends BaseResource {
|
|
742
|
+
/**
|
|
743
|
+
* List requests for an application, with rich filtering and cursor pagination.
|
|
744
|
+
*
|
|
745
|
+
* @param applicationId - The application ID (UUID).
|
|
746
|
+
* @param query - Optional filters and pagination.
|
|
747
|
+
* @returns A page of request summaries.
|
|
748
|
+
*/
|
|
749
|
+
list(applicationId: string, query?: ListRequestsQuery): Promise<Paginated<NetworkRequestSummary>>;
|
|
750
|
+
/**
|
|
751
|
+
* Get a single request by ID, including sanitized request/response headers.
|
|
752
|
+
*
|
|
753
|
+
* @param applicationId - The application ID (UUID).
|
|
754
|
+
* @param requestId - The request record ID (UUID).
|
|
755
|
+
* @returns The full request record.
|
|
756
|
+
*/
|
|
757
|
+
get(applicationId: string, requestId: string): Promise<NetworkRequest>;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Resolves the various accepted upload inputs (in-memory bytes, a Node.js file
|
|
762
|
+
* path, or a Node.js readable stream) into the concrete values the upload flow
|
|
763
|
+
* needs: the object tus-js-client consumes, the byte size, an inferred content
|
|
764
|
+
* type, and the required checksums.
|
|
765
|
+
*
|
|
766
|
+
* @internal
|
|
767
|
+
*/
|
|
768
|
+
|
|
769
|
+
/** A minimal Node.js `Readable`-like shape (avoids depending on `node:stream` types). */
|
|
770
|
+
interface NodeReadableLike {
|
|
771
|
+
on(event: string, listener: (...args: unknown[]) => void): unknown;
|
|
772
|
+
pipe?: unknown;
|
|
773
|
+
read?: unknown;
|
|
774
|
+
}
|
|
775
|
+
/** In-memory data accepted by the upload helpers. `Buffer` is a `Uint8Array`. */
|
|
776
|
+
type UploadData = Blob | ArrayBuffer | Uint8Array;
|
|
777
|
+
/** The tus-js-client file input union. */
|
|
778
|
+
type TusFile = File | Blob | Uint8Array | NodeReadableLike;
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Thin, injectable wrapper around `tus-js-client` that performs the resumable
|
|
782
|
+
* byte upload. Isolated here so the upload flow can be unit-tested with a fake
|
|
783
|
+
* transport (no real network I/O) and so abort/resume behaviour lives in one
|
|
784
|
+
* place.
|
|
785
|
+
*
|
|
786
|
+
* @internal
|
|
787
|
+
*/
|
|
788
|
+
|
|
789
|
+
/** A persistence backend for resumable upload fingerprints (matches tus-js-client's `UrlStorage`). */
|
|
790
|
+
interface UploadUrlStorage {
|
|
791
|
+
findAllUploads(): Promise<unknown[]>;
|
|
792
|
+
findUploadsByFingerprint(fingerprint: string): Promise<unknown[]>;
|
|
793
|
+
removeUpload(urlStorageKey: string): Promise<void>;
|
|
794
|
+
addUpload(fingerprint: string, upload: unknown): Promise<string>;
|
|
795
|
+
}
|
|
796
|
+
/** Parameters for a single byte upload. */
|
|
797
|
+
interface TusUploadParams {
|
|
798
|
+
/** The file/data passed to tus-js-client. */
|
|
799
|
+
data: TusFile;
|
|
800
|
+
/** Signed upload URL (already includes the short-lived upload token). */
|
|
801
|
+
uploadUrl: string;
|
|
802
|
+
/** Total upload size in bytes. */
|
|
803
|
+
uploadSize: number;
|
|
804
|
+
/** Headers to send with each request (must include `Tus-Resumable`). */
|
|
805
|
+
headers: Record<string, string>;
|
|
806
|
+
/** Maximum chunk size in bytes. Required for streamed inputs. */
|
|
807
|
+
chunkSize?: number;
|
|
808
|
+
/** Retry backoff in milliseconds. `null`/`[]` disables retries. */
|
|
809
|
+
retryDelays?: number[] | null;
|
|
810
|
+
/** Progress callback. */
|
|
811
|
+
onProgress?: (bytesSent: number, bytesTotal: number) => void;
|
|
812
|
+
/** Abort signal to cancel the upload. */
|
|
813
|
+
signal?: AbortSignal;
|
|
814
|
+
/** Persist a resumable fingerprint so the upload can resume later. */
|
|
815
|
+
resume?: boolean;
|
|
816
|
+
/** Custom storage for resumable fingerprints (defaults to the tus-js-client default for the runtime). */
|
|
817
|
+
urlStorage?: UploadUrlStorage;
|
|
818
|
+
}
|
|
819
|
+
/** Performs a single resumable byte upload. Resolves on success, rejects on error/abort. */
|
|
820
|
+
type UploadTransport = (params: TusUploadParams) => Promise<void>;
|
|
821
|
+
/** Options shared by the high-level upload entry points. */
|
|
822
|
+
interface RunUploadOptions {
|
|
823
|
+
/** Maximum chunk size in bytes. */
|
|
824
|
+
chunkSize?: number;
|
|
825
|
+
/** Retry backoff in milliseconds. `null`/`[]` disables retries. */
|
|
826
|
+
retryDelays?: number[] | null;
|
|
827
|
+
/** Progress callback. */
|
|
828
|
+
onProgress?: (bytesSent: number, bytesTotal: number) => void;
|
|
829
|
+
/** Abort signal to cancel the upload. */
|
|
830
|
+
signal?: AbortSignal;
|
|
831
|
+
/** Persist a resumable fingerprint so the upload can resume later. */
|
|
832
|
+
resume?: boolean;
|
|
833
|
+
/** Custom storage for resumable fingerprints. */
|
|
834
|
+
urlStorage?: UploadUrlStorage;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** A storage bucket belonging to an application. Buckets hold objects (files). */
|
|
838
|
+
interface StorageBucket {
|
|
839
|
+
/** Unique identifier (UUID). */
|
|
840
|
+
id: string;
|
|
841
|
+
/** The application this bucket belongs to. */
|
|
842
|
+
applicationId: string;
|
|
843
|
+
/** Human-readable bucket name. */
|
|
844
|
+
name: string;
|
|
845
|
+
/** Globally unique, hostname-safe label used to build the bucket's serving hostname. */
|
|
846
|
+
slug: string;
|
|
847
|
+
/** `"public"` buckets serve objects through the CDN hostname; `"private"` buckets require signed access URLs. */
|
|
848
|
+
visibility: 'public' | 'private';
|
|
849
|
+
/** The hostname clients use to read public objects or signed private-object URLs. */
|
|
850
|
+
cdnHostname: string;
|
|
851
|
+
/** The application environment this bucket is scoped to. */
|
|
852
|
+
environmentId: string;
|
|
853
|
+
/** ISO 8601 creation timestamp. */
|
|
854
|
+
createdAt: string;
|
|
855
|
+
/** ISO 8601 last-updated timestamp. */
|
|
856
|
+
updatedAt: string;
|
|
857
|
+
}
|
|
858
|
+
/** Input for creating a new storage bucket. */
|
|
859
|
+
interface CreateStorageBucketInput {
|
|
860
|
+
/** Human-readable name for the bucket. */
|
|
861
|
+
name: string;
|
|
862
|
+
/** The application environment to scope this bucket to. */
|
|
863
|
+
environmentId: string;
|
|
864
|
+
/** Optional hostname-safe slug used in the generated serving hostname. Auto-generated when omitted. */
|
|
865
|
+
slug?: string;
|
|
866
|
+
/** Bucket visibility. Defaults to `"private"`. */
|
|
867
|
+
visibility?: 'public' | 'private';
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Manage storage buckets for an application.
|
|
871
|
+
* Accessed via `client.applications.storage.buckets`.
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```ts
|
|
875
|
+
* // Create a public bucket
|
|
876
|
+
* const bucket = await client.applications.storage.buckets.create('app-id', {
|
|
877
|
+
* name: 'User Uploads',
|
|
878
|
+
* environmentId: 'env-id',
|
|
879
|
+
* visibility: 'public',
|
|
880
|
+
* });
|
|
881
|
+
*
|
|
882
|
+
* // List all buckets
|
|
883
|
+
* const { items } = await client.applications.storage.buckets.list('app-id');
|
|
884
|
+
* ```
|
|
885
|
+
*/
|
|
886
|
+
declare class StorageBucketsResource extends BaseResource {
|
|
887
|
+
/**
|
|
888
|
+
* List all storage buckets for an application.
|
|
889
|
+
*
|
|
890
|
+
* @param applicationId - The application ID (UUID).
|
|
891
|
+
* @param query - Optional pagination parameters.
|
|
892
|
+
* @returns A paginated list of storage buckets.
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* ```ts
|
|
896
|
+
* const { items, total } = await client.applications.storage.buckets.list('app-id');
|
|
897
|
+
* console.log(`${total} buckets found`);
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
900
|
+
list(applicationId: string, query?: ListQuery): Promise<Paginated<StorageBucket>>;
|
|
901
|
+
/**
|
|
902
|
+
* Create a new storage bucket.
|
|
903
|
+
*
|
|
904
|
+
* @param applicationId - The application ID (UUID).
|
|
905
|
+
* @param data - Bucket name, environment, and optional slug/visibility.
|
|
906
|
+
* @returns The newly created bucket.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* ```ts
|
|
910
|
+
* const bucket = await client.applications.storage.buckets.create('app-id', {
|
|
911
|
+
* name: 'Assets',
|
|
912
|
+
* environmentId: 'env-id',
|
|
913
|
+
* visibility: 'public',
|
|
914
|
+
* });
|
|
915
|
+
* console.log(`Bucket CDN: https://${bucket.cdnHostname}`);
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
create(applicationId: string, data: CreateStorageBucketInput): Promise<StorageBucket>;
|
|
919
|
+
/**
|
|
920
|
+
* Get a storage bucket by ID.
|
|
921
|
+
*
|
|
922
|
+
* @param applicationId - The application ID (UUID).
|
|
923
|
+
* @param bucketId - The bucket ID (UUID).
|
|
924
|
+
* @returns The bucket details.
|
|
925
|
+
*
|
|
926
|
+
* @example
|
|
927
|
+
* ```ts
|
|
928
|
+
* const bucket = await client.applications.storage.buckets.get('app-id', 'bucket-id');
|
|
929
|
+
* console.log(`${bucket.name} (${bucket.visibility})`);
|
|
930
|
+
* ```
|
|
931
|
+
*/
|
|
932
|
+
get(applicationId: string, bucketId: string): Promise<StorageBucket>;
|
|
933
|
+
/**
|
|
934
|
+
* Permanently delete a storage bucket and all its objects.
|
|
935
|
+
*
|
|
936
|
+
* @param applicationId - The application ID (UUID).
|
|
937
|
+
* @param bucketId - The bucket ID (UUID).
|
|
938
|
+
*
|
|
939
|
+
* @example
|
|
940
|
+
* ```ts
|
|
941
|
+
* await client.applications.storage.buckets.delete('app-id', 'bucket-id');
|
|
942
|
+
* ```
|
|
943
|
+
*/
|
|
944
|
+
delete(applicationId: string, bucketId: string): Promise<void>;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/** A file (object) stored in a storage bucket. */
|
|
948
|
+
interface StorageObject {
|
|
949
|
+
/** Unique identifier (UUID). */
|
|
950
|
+
id: string;
|
|
951
|
+
/** The bucket this object belongs to. */
|
|
952
|
+
bucketId: string;
|
|
953
|
+
/** The application this object belongs to. */
|
|
954
|
+
applicationId: string;
|
|
955
|
+
/** The upload session that created this object, or `null` for imported objects. */
|
|
956
|
+
uploadSessionId: string | null;
|
|
957
|
+
/** The object key (path) within the bucket (e.g. `"images/photo.jpg"`). */
|
|
958
|
+
key: string;
|
|
959
|
+
/** MIME content type (e.g. `"image/jpeg"`), or `null` if not set. */
|
|
960
|
+
contentType: string | null;
|
|
961
|
+
/** File size in bytes. */
|
|
962
|
+
contentLength: number;
|
|
963
|
+
/** SHA-1 checksum of the file contents, if available. */
|
|
964
|
+
checksumSha1: string | null;
|
|
965
|
+
/** SHA-256 checksum of the file contents, if available. */
|
|
966
|
+
checksumSha256: string | null;
|
|
967
|
+
/** MD5 checksum of the file contents, if available. */
|
|
968
|
+
checksumMd5: string | null;
|
|
969
|
+
/** ISO 8601 timestamp of when the upload was finalized. */
|
|
970
|
+
uploadedAt: string;
|
|
971
|
+
/** ISO 8601 creation timestamp. */
|
|
972
|
+
createdAt: string;
|
|
973
|
+
/** ISO 8601 last-updated timestamp. */
|
|
974
|
+
updatedAt: string;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Access URL details for a storage object. For public buckets, the URL is a
|
|
978
|
+
* stable CDN URL. For private buckets, the URL is time-limited and signed.
|
|
979
|
+
*/
|
|
980
|
+
interface StorageObjectAccess {
|
|
981
|
+
/** `"public"` for stable CDN URLs, `"signed"` for time-limited signed URLs. */
|
|
982
|
+
accessType: 'public' | 'signed';
|
|
983
|
+
/** The URL to access the object. */
|
|
984
|
+
url: string;
|
|
985
|
+
/** ISO 8601 expiry timestamp for signed URLs. `null` for public URLs. */
|
|
986
|
+
expiresAt: string | null;
|
|
987
|
+
}
|
|
988
|
+
/** Query parameters for listing objects in a bucket. */
|
|
989
|
+
interface ListStorageObjectsQuery {
|
|
990
|
+
/** Only return objects whose key starts with this prefix. */
|
|
991
|
+
prefix?: string;
|
|
992
|
+
/** Group keys by this delimiter into `commonPrefixes` (virtual folders). Defaults to `"/"`. */
|
|
993
|
+
delimiter?: string;
|
|
994
|
+
/** Opaque cursor from a previous response's `nextCursor`. */
|
|
995
|
+
cursor?: string;
|
|
996
|
+
/** Maximum number of objects to return (1–1000, default 200). */
|
|
997
|
+
limit?: number;
|
|
998
|
+
}
|
|
999
|
+
/** A page of storage objects, including any common (folder) prefixes. */
|
|
1000
|
+
interface StorageObjectList extends Paginated<StorageObject> {
|
|
1001
|
+
/** Virtual "folder" prefixes at the current level when a delimiter is used. */
|
|
1002
|
+
commonPrefixes: string[];
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Read and delete objects in storage buckets, and generate access URLs.
|
|
1006
|
+
* Accessed via `client.applications.storage.objects`.
|
|
1007
|
+
*
|
|
1008
|
+
* Objects are addressed by their object ID (UUID). If you only have the object
|
|
1009
|
+
* key, use {@link getByKey} to resolve it, or read the `id` from a listing.
|
|
1010
|
+
*
|
|
1011
|
+
* To upload objects, use `client.applications.storage.upload()`.
|
|
1012
|
+
*
|
|
1013
|
+
* @example
|
|
1014
|
+
* ```ts
|
|
1015
|
+
* // List all objects in a bucket
|
|
1016
|
+
* const { items } = await client.applications.storage.objects.list('app-id', 'bucket-id');
|
|
1017
|
+
* for (const obj of items) {
|
|
1018
|
+
* console.log(`${obj.key} (${obj.contentLength} bytes)`);
|
|
1019
|
+
* }
|
|
1020
|
+
*
|
|
1021
|
+
* // Get a signed download URL for a private object
|
|
1022
|
+
* const { url } = await client.applications.storage.objects.getAccessUrl('app-id', 'bucket-id', 'object-id');
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
declare class StorageObjectsResource extends BaseResource {
|
|
1026
|
+
/**
|
|
1027
|
+
* List objects in a storage bucket, optionally filtered by key prefix and
|
|
1028
|
+
* grouped into virtual folders by a delimiter.
|
|
1029
|
+
*
|
|
1030
|
+
* @param applicationId - The application ID (UUID).
|
|
1031
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1032
|
+
* @param query - Optional prefix/delimiter/cursor/limit parameters.
|
|
1033
|
+
* @returns A page of objects plus any common (folder) prefixes and a `nextCursor`.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* ```ts
|
|
1037
|
+
* // List the "images/" folder, one level deep
|
|
1038
|
+
* const { items, commonPrefixes, nextCursor } = await client.applications.storage.objects.list(
|
|
1039
|
+
* 'app-id', 'bucket-id', { prefix: 'images/', limit: 100 },
|
|
1040
|
+
* );
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
list(applicationId: string, bucketId: string, query?: ListStorageObjectsQuery): Promise<StorageObjectList>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Get metadata for a specific object by its object ID.
|
|
1046
|
+
*
|
|
1047
|
+
* @param applicationId - The application ID (UUID).
|
|
1048
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1049
|
+
* @param objectId - The object ID (UUID) — not the object key. Use {@link getByKey} to resolve a key.
|
|
1050
|
+
* @returns The object metadata.
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```ts
|
|
1054
|
+
* const obj = await client.applications.storage.objects.get('app-id', 'bucket-id', 'object-id');
|
|
1055
|
+
* console.log(`${obj.key}: ${obj.contentLength} bytes, type: ${obj.contentType}`);
|
|
1056
|
+
* ```
|
|
1057
|
+
*/
|
|
1058
|
+
get(applicationId: string, bucketId: string, objectId: string): Promise<StorageObject>;
|
|
1059
|
+
/**
|
|
1060
|
+
* Resolve an object by its key (path) instead of its ID. Convenience over
|
|
1061
|
+
* {@link list} — lists with the key as the prefix and returns the exact match,
|
|
1062
|
+
* paging through results until found, or `null` if no object with that key
|
|
1063
|
+
* exists. (The API has no get-by-key endpoint.)
|
|
1064
|
+
*
|
|
1065
|
+
* @param applicationId - The application ID (UUID).
|
|
1066
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1067
|
+
* @param key - The object key/path (e.g. `"images/photo.jpg"`).
|
|
1068
|
+
* @returns The matching object, or `null` if not found.
|
|
1069
|
+
*/
|
|
1070
|
+
getByKey(applicationId: string, bucketId: string, key: string): Promise<StorageObject | null>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Permanently delete an object from a storage bucket.
|
|
1073
|
+
*
|
|
1074
|
+
* @param applicationId - The application ID (UUID).
|
|
1075
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1076
|
+
* @param objectId - The object ID (UUID) — not the object key.
|
|
1077
|
+
*
|
|
1078
|
+
* @example
|
|
1079
|
+
* ```ts
|
|
1080
|
+
* await client.applications.storage.objects.delete('app-id', 'bucket-id', 'object-id');
|
|
1081
|
+
* ```
|
|
1082
|
+
*/
|
|
1083
|
+
delete(applicationId: string, bucketId: string, objectId: string): Promise<void>;
|
|
1084
|
+
/**
|
|
1085
|
+
* Get an access URL for a storage object. For objects in public buckets,
|
|
1086
|
+
* returns a stable CDN URL. For private buckets, returns a time-limited
|
|
1087
|
+
* signed URL.
|
|
1088
|
+
*
|
|
1089
|
+
* @param applicationId - The application ID (UUID).
|
|
1090
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1091
|
+
* @param objectId - The object ID (UUID) — not the object key.
|
|
1092
|
+
* @param options - Optional `expiresInSeconds` for signed URLs (60–86400).
|
|
1093
|
+
* @returns The access URL and its type/expiry.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```ts
|
|
1097
|
+
* const access = await client.applications.storage.objects.getAccessUrl('app-id', 'bucket-id', 'object-id', {
|
|
1098
|
+
* expiresInSeconds: 3600,
|
|
1099
|
+
* });
|
|
1100
|
+
* if (access.accessType === 'signed') {
|
|
1101
|
+
* console.log(`Signed URL expires at ${access.expiresAt}`);
|
|
1102
|
+
* }
|
|
1103
|
+
* console.log(`Download: ${access.url}`);
|
|
1104
|
+
* ```
|
|
1105
|
+
*/
|
|
1106
|
+
getAccessUrl(applicationId: string, bucketId: string, objectId: string, options?: {
|
|
1107
|
+
expiresInSeconds?: number;
|
|
1108
|
+
}): Promise<StorageObjectAccess>;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Represents an upload session for a storage object. Upload sessions track the
|
|
1113
|
+
* lifecycle of a file upload from creation through completion.
|
|
1114
|
+
*/
|
|
1115
|
+
interface StorageUploadSession {
|
|
1116
|
+
/** Unique identifier (UUID). */
|
|
1117
|
+
id: string;
|
|
1118
|
+
/** The bucket this upload targets. */
|
|
1119
|
+
bucketId: string;
|
|
1120
|
+
/** The application this upload belongs to. */
|
|
1121
|
+
applicationId: string;
|
|
1122
|
+
/** The object key/path the file will be stored at (e.g. `"images/photo.jpg"`). */
|
|
1123
|
+
key: string;
|
|
1124
|
+
/** MIME content type declared at creation, or `null` if not specified. */
|
|
1125
|
+
contentType: string | null;
|
|
1126
|
+
/** Expected file size in bytes declared at creation, or `null`. */
|
|
1127
|
+
contentLength: number | null;
|
|
1128
|
+
/** SHA-1 checksum for server-side verification, if provided. */
|
|
1129
|
+
checksumSha1: string | null;
|
|
1130
|
+
/** SHA-256 checksum for server-side verification, if provided. */
|
|
1131
|
+
checksumSha256: string | null;
|
|
1132
|
+
/** MD5 checksum for server-side verification, if provided. */
|
|
1133
|
+
checksumMd5: string | null;
|
|
1134
|
+
/**
|
|
1135
|
+
* Current session state:
|
|
1136
|
+
* - `"pending"` — Session created, awaiting the first bytes.
|
|
1137
|
+
* - `"ready"` — Receiving file data.
|
|
1138
|
+
* - `"completed"` — Upload verified and storage object created.
|
|
1139
|
+
* - `"failed"` — Upload failed or was rejected.
|
|
1140
|
+
* - `"expired"` — Session exceeded its expiration time.
|
|
1141
|
+
*/
|
|
1142
|
+
state: 'pending' | 'ready' | 'completed' | 'failed' | 'expired';
|
|
1143
|
+
/** ISO 8601 timestamp when this session (and its upload URL) expires. */
|
|
1144
|
+
expiresAt: string;
|
|
1145
|
+
/** ISO 8601 timestamp when the upload was finalized, or `null`. */
|
|
1146
|
+
uploadedAt: string | null;
|
|
1147
|
+
/** ISO 8601 creation timestamp. */
|
|
1148
|
+
createdAt: string;
|
|
1149
|
+
/** ISO 8601 last-updated timestamp. */
|
|
1150
|
+
updatedAt: string;
|
|
1151
|
+
}
|
|
1152
|
+
/** Input for creating a new upload session. */
|
|
1153
|
+
interface CreateUploadSessionInput {
|
|
1154
|
+
/** The object key/path the file will be stored at (e.g. `"images/photo.jpg"`). 1–1024 characters. */
|
|
1155
|
+
key: string;
|
|
1156
|
+
/** File size in bytes. Required. */
|
|
1157
|
+
contentLength: number;
|
|
1158
|
+
/** Lowercase hex SHA-256 checksum (64 chars) of the content. Required for server-side verification. */
|
|
1159
|
+
checksumSha256: string;
|
|
1160
|
+
/** MIME content type of the file (e.g. `"image/jpeg"`). */
|
|
1161
|
+
contentType?: string;
|
|
1162
|
+
/** Optional lowercase hex SHA-1 checksum (40 chars). */
|
|
1163
|
+
checksumSha1?: string;
|
|
1164
|
+
/** Optional lowercase hex MD5 checksum (32 chars). */
|
|
1165
|
+
checksumMd5?: string;
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Response from creating an upload session. Contains both the session metadata
|
|
1169
|
+
* and the resumable upload instructions (signed URL + headers).
|
|
1170
|
+
*/
|
|
1171
|
+
interface CreateUploadSessionResponse {
|
|
1172
|
+
/** The created upload session. */
|
|
1173
|
+
session: StorageUploadSession;
|
|
1174
|
+
/** Resumable upload instructions — use these to send the file data. */
|
|
1175
|
+
upload: {
|
|
1176
|
+
/** The HTTP method for the byte upload (resumable upload protocol). */
|
|
1177
|
+
method: 'PATCH';
|
|
1178
|
+
/** Signed upload URL. Send your file data here. */
|
|
1179
|
+
url: string;
|
|
1180
|
+
/** Required headers to include with the upload request. */
|
|
1181
|
+
headers: Record<string, string>;
|
|
1182
|
+
/** The URL where the object will be accessible after upload (CDN URL for public buckets). */
|
|
1183
|
+
publicObjectUrl: string;
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
/** A byte source for uploading directly to a known signed URL. */
|
|
1187
|
+
interface UploadByteSource {
|
|
1188
|
+
/** In-memory data (`File`/`Blob`/`Buffer`/`Uint8Array`/`ArrayBuffer`). */
|
|
1189
|
+
data?: UploadData;
|
|
1190
|
+
/** A filesystem path to stream from (Node.js only). */
|
|
1191
|
+
path?: string;
|
|
1192
|
+
/** A readable stream (Node.js only). Requires `contentLength`. */
|
|
1193
|
+
stream?: NodeReadableLike;
|
|
1194
|
+
/** Byte size — required for `stream` inputs, computed otherwise. */
|
|
1195
|
+
contentLength?: number;
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Manage upload sessions and upload bytes to a signed upload URL using the
|
|
1199
|
+
* resumable upload protocol. Accessed via
|
|
1200
|
+
* `client.applications.storage.uploadSessions`.
|
|
1201
|
+
*
|
|
1202
|
+
* For most use cases, prefer the high-level `client.applications.storage.upload()`
|
|
1203
|
+
* which creates the session, computes the required checksum, uploads the bytes,
|
|
1204
|
+
* and returns the public URL.
|
|
1205
|
+
*/
|
|
1206
|
+
declare class StorageUploadSessionsResource extends BaseResource {
|
|
1207
|
+
private readonly transport;
|
|
1208
|
+
constructor(httpClient: ConstructorParameters<typeof BaseResource>[0], transport?: UploadTransport);
|
|
1209
|
+
/**
|
|
1210
|
+
* List upload sessions for a bucket.
|
|
1211
|
+
*
|
|
1212
|
+
* @param applicationId - The application ID (UUID).
|
|
1213
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1214
|
+
* @param query - Optional pagination parameters.
|
|
1215
|
+
* @returns A paginated list of upload sessions.
|
|
1216
|
+
*/
|
|
1217
|
+
list(applicationId: string, bucketId: string, query?: ListQuery): Promise<Paginated<StorageUploadSession>>;
|
|
1218
|
+
/**
|
|
1219
|
+
* Create an upload session. Returns the session metadata and a signed upload
|
|
1220
|
+
* URL for sending file data. This is the low-level method — for most use
|
|
1221
|
+
* cases prefer `client.applications.storage.upload()` which also computes the
|
|
1222
|
+
* required SHA-256 checksum for you.
|
|
1223
|
+
*
|
|
1224
|
+
* @param applicationId - The application ID (UUID).
|
|
1225
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1226
|
+
* @param data - Object key, content length, SHA-256 checksum, and optional content type / extra checksums.
|
|
1227
|
+
* @returns The session and resumable upload instructions (URL, method, headers).
|
|
1228
|
+
*/
|
|
1229
|
+
create(applicationId: string, bucketId: string, data: CreateUploadSessionInput): Promise<CreateUploadSessionResponse>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Get an upload session by ID. Use this to track server-side processing after
|
|
1232
|
+
* an upload (poll until `state === 'completed'`).
|
|
1233
|
+
*
|
|
1234
|
+
* @param applicationId - The application ID (UUID).
|
|
1235
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1236
|
+
* @param sessionId - The upload session ID (UUID).
|
|
1237
|
+
* @returns The current session state.
|
|
1238
|
+
*/
|
|
1239
|
+
get(applicationId: string, bucketId: string, sessionId: string): Promise<StorageUploadSession>;
|
|
1240
|
+
/**
|
|
1241
|
+
* Upload bytes directly to a pre-existing signed upload URL — for example, a
|
|
1242
|
+
* URL returned by {@link create} or handed to your client by a backend. Skips
|
|
1243
|
+
* session creation and checksum computation.
|
|
1244
|
+
*
|
|
1245
|
+
* @param url - A signed upload URL.
|
|
1246
|
+
* @param source - The bytes to upload.
|
|
1247
|
+
* @param options - Chunk size, retry config, progress, abort signal, resume,
|
|
1248
|
+
* and any required `headers` returned with the upload session.
|
|
1249
|
+
* @throws {@link UploadError} if the upload fails after all retries.
|
|
1250
|
+
*/
|
|
1251
|
+
uploadToUrl(url: string, source: UploadByteSource, options?: RunUploadOptions & {
|
|
1252
|
+
headers?: Record<string, string>;
|
|
1253
|
+
}): Promise<void>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Resume an interrupted upload to a previously issued signed upload URL. The
|
|
1256
|
+
* resumable protocol negotiates the current offset and continues from there.
|
|
1257
|
+
*
|
|
1258
|
+
* @param url - The signed upload URL from the original {@link create} call.
|
|
1259
|
+
* @param source - The full bytes to upload (the same content as the original).
|
|
1260
|
+
* @param options - Chunk size, retry config, progress, abort signal.
|
|
1261
|
+
*/
|
|
1262
|
+
resumeFromUrl(url: string, source: UploadByteSource, options?: RunUploadOptions & {
|
|
1263
|
+
headers?: Record<string, string>;
|
|
1264
|
+
}): Promise<void>;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/** Options controlling whether and how to wait for an upload to finalize server-side. */
|
|
1268
|
+
interface WaitForCompletionOptions {
|
|
1269
|
+
/** Maximum time to wait in milliseconds. Default: 60000. */
|
|
1270
|
+
timeoutMs?: number;
|
|
1271
|
+
/** How often to poll the session state, in milliseconds. Default: 1000. */
|
|
1272
|
+
pollIntervalMs?: number;
|
|
1273
|
+
}
|
|
1274
|
+
/** Input for the high-level {@link ApplicationStorageResource.upload | upload()} method. */
|
|
1275
|
+
interface UploadFileInput {
|
|
1276
|
+
/** The application ID (UUID). */
|
|
1277
|
+
applicationId: string;
|
|
1278
|
+
/** The target bucket ID (UUID). */
|
|
1279
|
+
bucketId: string;
|
|
1280
|
+
/** The object key/path in the bucket (e.g. `"images/logo.png"`). */
|
|
1281
|
+
key: string;
|
|
1282
|
+
/** In-memory data (browser `File`/`Blob`, Node `Buffer`, `Uint8Array`, `ArrayBuffer`). */
|
|
1283
|
+
data?: UploadData;
|
|
1284
|
+
/** A filesystem path to upload from (Node.js only). Size, checksum, and content type are derived automatically. */
|
|
1285
|
+
path?: string;
|
|
1286
|
+
/** A readable stream to upload from (Node.js only). Requires `contentLength` and `checksumSha256`. */
|
|
1287
|
+
stream?: NodeReadableLike;
|
|
1288
|
+
/** MIME content type. Inferred from `key` when omitted. */
|
|
1289
|
+
contentType?: string;
|
|
1290
|
+
/** Byte size. Required for `stream`; computed otherwise. */
|
|
1291
|
+
contentLength?: number;
|
|
1292
|
+
/** Pre-computed SHA-256 (skips hashing). Required for `stream`. */
|
|
1293
|
+
checksumSha256?: string;
|
|
1294
|
+
/** Also send a SHA-1 checksum. */
|
|
1295
|
+
checksumSha1?: string;
|
|
1296
|
+
/** Also send an MD5 checksum (Node.js only unless provided). */
|
|
1297
|
+
checksumMd5?: string;
|
|
1298
|
+
/** Maximum chunk size in bytes (for very large files / streams). */
|
|
1299
|
+
chunkSize?: number;
|
|
1300
|
+
/** Retry backoff in milliseconds; `null`/`[]` disables retries. */
|
|
1301
|
+
retryDelays?: number[] | null;
|
|
1302
|
+
/** Progress callback invoked during the byte upload. */
|
|
1303
|
+
onProgress?: (bytesSent: number, bytesTotal: number) => void;
|
|
1304
|
+
/** Abort signal to cancel the upload. */
|
|
1305
|
+
signal?: AbortSignal;
|
|
1306
|
+
/** Persist a resumable fingerprint so the upload can be resumed later. */
|
|
1307
|
+
resume?: boolean;
|
|
1308
|
+
/** Custom storage backend for resumable fingerprints. */
|
|
1309
|
+
urlStorage?: UploadUrlStorage;
|
|
1310
|
+
/** Wait until the object is finalized server-side before resolving. Pass options to tune polling. */
|
|
1311
|
+
waitForCompletion?: boolean | WaitForCompletionOptions;
|
|
1312
|
+
}
|
|
1313
|
+
/** Result of a successful upload. */
|
|
1314
|
+
interface UploadFileResult {
|
|
1315
|
+
/** The upload session. When `waitForCompletion` was set, `state` is `"completed"`. */
|
|
1316
|
+
session: StorageUploadSession;
|
|
1317
|
+
/** The public/CDN URL of the uploaded object. */
|
|
1318
|
+
url: string;
|
|
1319
|
+
/** The finalized storage object — present only when `waitForCompletion` was set. */
|
|
1320
|
+
object?: StorageObject;
|
|
1321
|
+
}
|
|
1322
|
+
/** Options for {@link ApplicationStorageResource.uploadBatch | uploadBatch()}. */
|
|
1323
|
+
interface UploadBatchOptions {
|
|
1324
|
+
/** Maximum number of concurrent uploads. Default: 4. */
|
|
1325
|
+
concurrency?: number;
|
|
1326
|
+
/** Called after each file settles, with the number completed and the total. */
|
|
1327
|
+
onProgress?: (completed: number, total: number) => void;
|
|
1328
|
+
}
|
|
1329
|
+
/** The outcome of one file within a batch upload. Errors are isolated per file. */
|
|
1330
|
+
interface UploadBatchItemResult {
|
|
1331
|
+
/** The input that produced this result. */
|
|
1332
|
+
input: UploadFileInput;
|
|
1333
|
+
/** The successful result, if the upload succeeded. */
|
|
1334
|
+
result?: UploadFileResult;
|
|
1335
|
+
/** The error, if this upload failed. */
|
|
1336
|
+
error?: unknown;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Namespace for all storage operations on an application: bucket management,
|
|
1340
|
+
* object listing/access, low-level upload sessions, and the high-level
|
|
1341
|
+
* {@link upload} / {@link uploadBatch} helpers.
|
|
1342
|
+
*
|
|
1343
|
+
* Accessed via `client.applications.storage`.
|
|
1344
|
+
*
|
|
1345
|
+
* @example
|
|
1346
|
+
* ```ts
|
|
1347
|
+
* // High-level upload (Node.js, from a path — checksum/size/content-type inferred)
|
|
1348
|
+
* const { url } = await client.applications.storage.upload({
|
|
1349
|
+
* applicationId: 'app-id',
|
|
1350
|
+
* bucketId: 'bucket-id',
|
|
1351
|
+
* key: 'photos/cat.jpg',
|
|
1352
|
+
* path: './cat.jpg',
|
|
1353
|
+
* });
|
|
1354
|
+
*
|
|
1355
|
+
* // Browser upload from a file input, with progress and abort
|
|
1356
|
+
* const controller = new AbortController();
|
|
1357
|
+
* const { url } = await client.applications.storage.upload({
|
|
1358
|
+
* applicationId: 'app-id',
|
|
1359
|
+
* bucketId: 'bucket-id',
|
|
1360
|
+
* key: `uploads/${file.name}`,
|
|
1361
|
+
* data: file,
|
|
1362
|
+
* onProgress: (sent, total) => console.log(`${Math.round((sent / total) * 100)}%`),
|
|
1363
|
+
* signal: controller.signal,
|
|
1364
|
+
* });
|
|
1365
|
+
* ```
|
|
1366
|
+
*/
|
|
1367
|
+
declare class ApplicationStorageResource {
|
|
1368
|
+
/** Create, list, get, and delete storage buckets. */
|
|
1369
|
+
readonly buckets: StorageBucketsResource;
|
|
1370
|
+
/** List, get, delete objects, and generate access URLs. */
|
|
1371
|
+
readonly objects: StorageObjectsResource;
|
|
1372
|
+
/** Low-level upload sessions and direct-to-URL byte uploads. */
|
|
1373
|
+
readonly uploadSessions: StorageUploadSessionsResource;
|
|
1374
|
+
private readonly transport;
|
|
1375
|
+
constructor(httpClient: HttpClient, transport?: UploadTransport);
|
|
1376
|
+
/**
|
|
1377
|
+
* Upload a file to a storage bucket. Handles the full flow: computes the
|
|
1378
|
+
* required SHA-256 checksum, creates an upload session, uploads the bytes with
|
|
1379
|
+
* automatic retries (and optional progress/abort/resume), and returns the
|
|
1380
|
+
* public URL.
|
|
1381
|
+
*
|
|
1382
|
+
* Accepts browser `File`/`Blob`, Node `Buffer`/`Uint8Array`/`ArrayBuffer`, a
|
|
1383
|
+
* Node filesystem `path`, or a Node readable `stream` (with `contentLength`
|
|
1384
|
+
* and `checksumSha256`). The content type is inferred from `key` when omitted.
|
|
1385
|
+
*
|
|
1386
|
+
* @param input - What and where to upload, plus optional transfer options.
|
|
1387
|
+
* @returns The upload session and public object URL (and the finalized object when `waitForCompletion` is set).
|
|
1388
|
+
* @throws {@link UploadError} if the byte upload fails.
|
|
1389
|
+
* @throws {@link UploadSessionExpiredError} if the session expires mid-upload.
|
|
1390
|
+
*
|
|
1391
|
+
* @example
|
|
1392
|
+
* ```ts
|
|
1393
|
+
* const { session, url, object } = await client.applications.storage.upload({
|
|
1394
|
+
* applicationId, bucketId, key: 'reports/q1.pdf', path: './q1.pdf',
|
|
1395
|
+
* waitForCompletion: true,
|
|
1396
|
+
* });
|
|
1397
|
+
* console.log(object?.contentLength, 'bytes available at', url);
|
|
1398
|
+
* ```
|
|
1399
|
+
*/
|
|
1400
|
+
upload(input: UploadFileInput): Promise<UploadFileResult>;
|
|
1401
|
+
/**
|
|
1402
|
+
* Upload many files concurrently. Each file is uploaded independently; a
|
|
1403
|
+
* failure for one file does not abort the others — inspect each item's
|
|
1404
|
+
* `error`/`result`.
|
|
1405
|
+
*
|
|
1406
|
+
* @param inputs - The files to upload.
|
|
1407
|
+
* @param options - Concurrency limit and an aggregated progress callback.
|
|
1408
|
+
* @returns One result per input, in the same order.
|
|
1409
|
+
*
|
|
1410
|
+
* @example
|
|
1411
|
+
* ```ts
|
|
1412
|
+
* const results = await client.applications.storage.uploadBatch(
|
|
1413
|
+
* files.map((f) => ({ applicationId, bucketId, key: `uploads/${f.name}`, data: f })),
|
|
1414
|
+
* { concurrency: 6, onProgress: (done, total) => console.log(`${done}/${total}`) },
|
|
1415
|
+
* );
|
|
1416
|
+
* const failed = results.filter((r) => r.error);
|
|
1417
|
+
* ```
|
|
1418
|
+
*/
|
|
1419
|
+
uploadBatch(inputs: UploadFileInput[], options?: UploadBatchOptions): Promise<UploadBatchItemResult[]>;
|
|
1420
|
+
/**
|
|
1421
|
+
* Poll an upload session until the object is finalized server-side.
|
|
1422
|
+
*
|
|
1423
|
+
* @param applicationId - The application ID (UUID).
|
|
1424
|
+
* @param bucketId - The bucket ID (UUID).
|
|
1425
|
+
* @param sessionId - The upload session ID (UUID).
|
|
1426
|
+
* @param options - Timeout and polling interval.
|
|
1427
|
+
* @returns The completed session.
|
|
1428
|
+
* @throws {@link UploadError} if the session fails, expires, or the timeout elapses.
|
|
1429
|
+
*/
|
|
1430
|
+
waitForCompletion(applicationId: string, bucketId: string, sessionId: string, options?: WaitForCompletionOptions): Promise<StorageUploadSession>;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/** A `*.gigadrive.app` hostname assigned to an application or deployment. */
|
|
1434
|
+
interface Hostname {
|
|
1435
|
+
/** Unique identifier (UUID). */
|
|
1436
|
+
id: string;
|
|
1437
|
+
/** The fully-qualified hostname (e.g. `"my-app.gigadrive.app"`). */
|
|
1438
|
+
hostname: string;
|
|
1439
|
+
/** The kind of hostname: `"DEPLOYMENT"`, `"BRANCH"`, or `"APP"`. */
|
|
1440
|
+
type: 'DEPLOYMENT' | 'BRANCH' | 'APP';
|
|
1441
|
+
/** Whether this hostname currently routes traffic. */
|
|
1442
|
+
active: boolean;
|
|
1443
|
+
/** The deployment this hostname points to, if any. */
|
|
1444
|
+
deploymentId: string | null;
|
|
1445
|
+
/** The branch this hostname is associated with, if any. */
|
|
1446
|
+
branchId: string | null;
|
|
1447
|
+
/** Who created the hostname: `"system"` (automatic) or `"user"`. */
|
|
1448
|
+
source: 'system' | 'user';
|
|
1449
|
+
/** ISO 8601 creation timestamp. */
|
|
1450
|
+
createdAt: string;
|
|
1451
|
+
}
|
|
1452
|
+
/** A paginated list of application hostnames, plus the production label. */
|
|
1453
|
+
interface ApplicationHostnameList extends Paginated<Hostname> {
|
|
1454
|
+
/** The application's production hostname label (`{label}.gigadrive.app`), or `null` if none is set. */
|
|
1455
|
+
label: string | null;
|
|
1456
|
+
}
|
|
1457
|
+
/** The result of checking whether a production hostname label is available. */
|
|
1458
|
+
interface HostnameAvailability {
|
|
1459
|
+
/** Whether the label is allowed and globally available. */
|
|
1460
|
+
available: boolean;
|
|
1461
|
+
/** When {@link available} is `false`, a human-readable reason (e.g. the label is reserved or already taken). */
|
|
1462
|
+
reason?: string;
|
|
1463
|
+
}
|
|
1464
|
+
/** The result of setting an application's production hostname. */
|
|
1465
|
+
interface SetProductionHostnameResult {
|
|
1466
|
+
/** The normalized production label that was saved. */
|
|
1467
|
+
label: string;
|
|
1468
|
+
/** The resulting `{label}.gigadrive.app` hostname. */
|
|
1469
|
+
hostname: string;
|
|
1470
|
+
/**
|
|
1471
|
+
* Whether the hostname now routes traffic. `false` when the label is reserved
|
|
1472
|
+
* but no active production deployment exists yet — the URL becomes live after
|
|
1473
|
+
* the next production deployment.
|
|
1474
|
+
*/
|
|
1475
|
+
live: boolean;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
/** One bucket of an AI Gateway usage breakdown (by model, provider, or user). */
|
|
1479
|
+
interface AiGatewayUsageBreakdown {
|
|
1480
|
+
/** Bucket label (a model, provider, or user identifier). */
|
|
1481
|
+
label: string;
|
|
1482
|
+
/** Number of requests in this bucket. */
|
|
1483
|
+
requests: number;
|
|
1484
|
+
/** Total tokens in this bucket. */
|
|
1485
|
+
tokens: number;
|
|
1486
|
+
/** Input tokens in this bucket. */
|
|
1487
|
+
inputTokens: number;
|
|
1488
|
+
/** Output tokens in this bucket. */
|
|
1489
|
+
outputTokens: number;
|
|
1490
|
+
/** Billable cost in micros of USD for this bucket. */
|
|
1491
|
+
costMicros: number;
|
|
1492
|
+
}
|
|
1493
|
+
/** Aggregated AI Gateway usage over a time range, with breakdowns. */
|
|
1494
|
+
interface AiGatewayUsageSummary {
|
|
1495
|
+
summary: {
|
|
1496
|
+
requestCount: number;
|
|
1497
|
+
successCount: number;
|
|
1498
|
+
errorCount: number;
|
|
1499
|
+
inputTokens: number;
|
|
1500
|
+
outputTokens: number;
|
|
1501
|
+
totalTokens: number;
|
|
1502
|
+
billableCostMicros: number;
|
|
1503
|
+
avgLatencyMs: number;
|
|
1504
|
+
};
|
|
1505
|
+
byModel: AiGatewayUsageBreakdown[];
|
|
1506
|
+
byProvider: AiGatewayUsageBreakdown[];
|
|
1507
|
+
byUser: AiGatewayUsageBreakdown[];
|
|
1508
|
+
}
|
|
1509
|
+
/** One provider attempt recorded while routing an AI Gateway request. */
|
|
1510
|
+
interface AiGatewayProviderAttempt {
|
|
1511
|
+
provider: string;
|
|
1512
|
+
error?: string;
|
|
1513
|
+
statusCode?: number;
|
|
1514
|
+
tag?: string;
|
|
1515
|
+
}
|
|
1516
|
+
/** A single AI Gateway request event with full telemetry. */
|
|
1517
|
+
interface AiGatewayRequestEvent {
|
|
1518
|
+
id: string;
|
|
1519
|
+
requestId: string;
|
|
1520
|
+
traceId: string | null;
|
|
1521
|
+
billingSubjectType: 'organization' | 'application';
|
|
1522
|
+
organizationId: string;
|
|
1523
|
+
applicationId: string | null;
|
|
1524
|
+
actorId: string | null;
|
|
1525
|
+
actorType: string;
|
|
1526
|
+
apiKeyId: string | null;
|
|
1527
|
+
authenticatedUserId: string | null;
|
|
1528
|
+
callerEndUserId: string | null;
|
|
1529
|
+
modelRequested: string;
|
|
1530
|
+
modelServed: string | null;
|
|
1531
|
+
provider: string | null;
|
|
1532
|
+
providerAttempts: AiGatewayProviderAttempt[] | null;
|
|
1533
|
+
status: 'pending' | 'success' | 'error' | 'cancelled';
|
|
1534
|
+
errorCode: string | null;
|
|
1535
|
+
errorType: string | null;
|
|
1536
|
+
inputTokens: number;
|
|
1537
|
+
outputTokens: number;
|
|
1538
|
+
cachedInputTokens: number;
|
|
1539
|
+
totalTokens: number;
|
|
1540
|
+
usageSource: 'provider' | 'estimated' | 'none';
|
|
1541
|
+
providerCostMicros: number;
|
|
1542
|
+
billableCostMicros: number;
|
|
1543
|
+
streaming: boolean;
|
|
1544
|
+
latencyMs: number | null;
|
|
1545
|
+
metadata: Record<string, string> | null;
|
|
1546
|
+
startedAt: string;
|
|
1547
|
+
completedAt: string | null;
|
|
1548
|
+
createdAt: string;
|
|
1549
|
+
updatedAt: string;
|
|
1550
|
+
}
|
|
1551
|
+
/** An AI Gateway spend/usage budget. */
|
|
1552
|
+
interface AiGatewayBudget {
|
|
1553
|
+
id: string;
|
|
1554
|
+
organizationId: string;
|
|
1555
|
+
/** Application-specific target, or `null` for organization-wide. */
|
|
1556
|
+
applicationId: string | null;
|
|
1557
|
+
/** User-specific target, or `null` for all users. */
|
|
1558
|
+
userId: string | null;
|
|
1559
|
+
period: 'day' | 'month';
|
|
1560
|
+
maxCostMicros: number | null;
|
|
1561
|
+
maxRequests: number | null;
|
|
1562
|
+
maxTokens: number | null;
|
|
1563
|
+
maxRequestCostMicros: number | null;
|
|
1564
|
+
enabled: boolean;
|
|
1565
|
+
createdAt: string;
|
|
1566
|
+
updatedAt: string;
|
|
1567
|
+
}
|
|
1568
|
+
/** Input for one budget when replacing the budget set. */
|
|
1569
|
+
interface AiGatewayBudgetInput {
|
|
1570
|
+
applicationId?: string;
|
|
1571
|
+
userId?: string;
|
|
1572
|
+
period?: 'day' | 'month';
|
|
1573
|
+
maxCostMicros?: number | null;
|
|
1574
|
+
maxRequests?: number | null;
|
|
1575
|
+
maxTokens?: number | null;
|
|
1576
|
+
maxRequestCostMicros?: number | null;
|
|
1577
|
+
enabled?: boolean;
|
|
1578
|
+
}
|
|
1579
|
+
/** An AI Gateway governance policy. */
|
|
1580
|
+
interface AiGatewayPolicy {
|
|
1581
|
+
id: string;
|
|
1582
|
+
organizationId: string;
|
|
1583
|
+
/** Application-specific target, or `null` for organization-wide. */
|
|
1584
|
+
applicationId: string | null;
|
|
1585
|
+
/** Allowed model IDs, or `null` to allow all. */
|
|
1586
|
+
allowedModels: string[] | null;
|
|
1587
|
+
/** Allowed provider IDs, or `null` to allow all. */
|
|
1588
|
+
allowedProviders: string[] | null;
|
|
1589
|
+
requireZdr: boolean;
|
|
1590
|
+
allowFallbacks: boolean;
|
|
1591
|
+
maxOutputTokens: number | null;
|
|
1592
|
+
createdAt: string;
|
|
1593
|
+
updatedAt: string;
|
|
1594
|
+
}
|
|
1595
|
+
/** Input for creating or updating an AI Gateway policy. */
|
|
1596
|
+
interface AiGatewayPolicyInput {
|
|
1597
|
+
applicationId?: string;
|
|
1598
|
+
allowedModels?: string[] | null;
|
|
1599
|
+
allowedProviders?: string[] | null;
|
|
1600
|
+
requireZdr?: boolean;
|
|
1601
|
+
allowFallbacks?: boolean;
|
|
1602
|
+
maxOutputTokens?: number | null;
|
|
1603
|
+
}
|
|
1604
|
+
/** Query for usage summary. */
|
|
1605
|
+
interface AiGatewayUsageQuery {
|
|
1606
|
+
/** Only include usage at or after this ISO 8601 timestamp. */
|
|
1607
|
+
from?: string;
|
|
1608
|
+
/** Only include usage before or at this ISO 8601 timestamp. */
|
|
1609
|
+
to?: string;
|
|
1610
|
+
/** Restrict to one application. */
|
|
1611
|
+
applicationId?: string;
|
|
1612
|
+
}
|
|
1613
|
+
/** Query for the request-event log and CSV export. */
|
|
1614
|
+
interface AiGatewayRequestsQuery extends AiGatewayUsageQuery {
|
|
1615
|
+
model?: string;
|
|
1616
|
+
provider?: string;
|
|
1617
|
+
status?: 'pending' | 'success' | 'error' | 'cancelled';
|
|
1618
|
+
requestId?: string;
|
|
1619
|
+
authenticatedUserId?: string;
|
|
1620
|
+
callerEndUserId?: string;
|
|
1621
|
+
limit?: number;
|
|
1622
|
+
cursor?: string;
|
|
1623
|
+
}
|
|
1624
|
+
/** AI Gateway usage analytics for an organization. */
|
|
1625
|
+
declare class AiGatewayUsageResource extends BaseResource {
|
|
1626
|
+
/** Get an aggregated usage summary with breakdowns by model, provider, and user. */
|
|
1627
|
+
summary(organizationId: string, query?: AiGatewayUsageQuery): Promise<AiGatewayUsageSummary>;
|
|
1628
|
+
/** List request-level usage events. */
|
|
1629
|
+
requests(organizationId: string, query?: AiGatewayRequestsQuery): Promise<Paginated<AiGatewayRequestEvent>>;
|
|
1630
|
+
/** Export request-level usage events as CSV text. */
|
|
1631
|
+
export(organizationId: string, query?: AiGatewayRequestsQuery): Promise<string>;
|
|
1632
|
+
}
|
|
1633
|
+
/** AI Gateway budgets for an organization. */
|
|
1634
|
+
declare class AiGatewayBudgetsResource extends BaseResource {
|
|
1635
|
+
/** List all budgets for an organization. */
|
|
1636
|
+
list(organizationId: string): Promise<{
|
|
1637
|
+
items: AiGatewayBudget[];
|
|
1638
|
+
}>;
|
|
1639
|
+
/**
|
|
1640
|
+
* Replace the organization's entire budget set. Pass an empty array to clear
|
|
1641
|
+
* all budgets.
|
|
1642
|
+
*/
|
|
1643
|
+
replace(organizationId: string, budgets: AiGatewayBudgetInput[]): Promise<{
|
|
1644
|
+
items: AiGatewayBudget[];
|
|
1645
|
+
}>;
|
|
1646
|
+
}
|
|
1647
|
+
/** AI Gateway governance policies for an organization. */
|
|
1648
|
+
declare class AiGatewayPoliciesResource extends BaseResource {
|
|
1649
|
+
/**
|
|
1650
|
+
* Get the governance policy for an organization, or for a specific
|
|
1651
|
+
* application when `applicationId` is provided. Returns `null` if no policy is set.
|
|
1652
|
+
*/
|
|
1653
|
+
get(organizationId: string, options?: {
|
|
1654
|
+
applicationId?: string;
|
|
1655
|
+
}): Promise<AiGatewayPolicy | null>;
|
|
1656
|
+
/** Create or update an AI Gateway policy. */
|
|
1657
|
+
put(organizationId: string, data: AiGatewayPolicyInput): Promise<AiGatewayPolicy>;
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Organization-scoped AI Gateway governance: usage analytics, budgets, and
|
|
1661
|
+
* model/provider policies. Accessed via `client.organizations.aiGateway`.
|
|
1662
|
+
*/
|
|
1663
|
+
declare class OrganizationAiGatewayResource {
|
|
1664
|
+
/** Usage analytics (summary, request log, CSV export). */
|
|
1665
|
+
readonly usage: AiGatewayUsageResource;
|
|
1666
|
+
/** Spend/usage budgets. */
|
|
1667
|
+
readonly budgets: AiGatewayBudgetsResource;
|
|
1668
|
+
/** Model/provider governance policies. */
|
|
1669
|
+
readonly policies: AiGatewayPoliciesResource;
|
|
1670
|
+
constructor(httpClient: HttpClient);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* Manage environment variables scoped to an organization.
|
|
1675
|
+
* Accessed via `client.organizations.envVars`.
|
|
1676
|
+
*/
|
|
1677
|
+
declare class OrganizationEnvVarsResource extends BaseResource {
|
|
1678
|
+
/**
|
|
1679
|
+
* List all environment variables for an organization.
|
|
1680
|
+
*
|
|
1681
|
+
* @param organizationId - The organization ID (UUID).
|
|
1682
|
+
* @returns A paginated list of environment variables.
|
|
1683
|
+
*
|
|
1684
|
+
* @example
|
|
1685
|
+
* ```ts
|
|
1686
|
+
* const { items } = await client.organizations.envVars.list('org-id');
|
|
1687
|
+
* for (const v of items) {
|
|
1688
|
+
* console.log(`${v.key}=${v.sensitive ? '***' : v.value}`);
|
|
1689
|
+
* }
|
|
1690
|
+
* ```
|
|
1691
|
+
*/
|
|
1692
|
+
list(organizationId: string, query?: ListQuery): Promise<Paginated<EnvVar>>;
|
|
1693
|
+
/**
|
|
1694
|
+
* Create a new environment variable for an organization.
|
|
1695
|
+
*
|
|
1696
|
+
* @param organizationId - The organization ID (UUID).
|
|
1697
|
+
* @param data - The variable key, value, and optional settings.
|
|
1698
|
+
* @returns The newly created environment variable.
|
|
1699
|
+
*
|
|
1700
|
+
* @example
|
|
1701
|
+
* ```ts
|
|
1702
|
+
* const envVar = await client.organizations.envVars.create('org-id', {
|
|
1703
|
+
* key: 'STRIPE_SECRET',
|
|
1704
|
+
* value: 'sk_live_...',
|
|
1705
|
+
* sensitive: true,
|
|
1706
|
+
* });
|
|
1707
|
+
* ```
|
|
1708
|
+
*/
|
|
1709
|
+
create(organizationId: string, data: CreateEnvVarInput): Promise<EnvVar>;
|
|
1710
|
+
/**
|
|
1711
|
+
* Update an existing environment variable. Only the fields you provide
|
|
1712
|
+
* will be changed; omitted fields are left unchanged.
|
|
1713
|
+
*
|
|
1714
|
+
* @param organizationId - The organization ID (UUID).
|
|
1715
|
+
* @param envVarId - The environment variable ID (UUID).
|
|
1716
|
+
* @param data - The fields to update.
|
|
1717
|
+
* @returns The updated environment variable.
|
|
1718
|
+
*
|
|
1719
|
+
* @example
|
|
1720
|
+
* ```ts
|
|
1721
|
+
* await client.organizations.envVars.update('org-id', 'var-id', {
|
|
1722
|
+
* value: 'new-value',
|
|
1723
|
+
* });
|
|
1724
|
+
* ```
|
|
1725
|
+
*/
|
|
1726
|
+
update(organizationId: string, envVarId: string, data: UpdateEnvVarInput): Promise<EnvVar>;
|
|
1727
|
+
/**
|
|
1728
|
+
* Permanently delete an environment variable.
|
|
1729
|
+
*
|
|
1730
|
+
* @param organizationId - The organization ID (UUID).
|
|
1731
|
+
* @param envVarId - The environment variable ID (UUID).
|
|
1732
|
+
*
|
|
1733
|
+
* @example
|
|
1734
|
+
* ```ts
|
|
1735
|
+
* await client.organizations.envVars.delete('org-id', 'var-id');
|
|
1736
|
+
* ```
|
|
1737
|
+
*/
|
|
1738
|
+
delete(organizationId: string, envVarId: string): Promise<void>;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
/** A Gigadrive Network organization. */
|
|
1742
|
+
interface Organization {
|
|
1743
|
+
/** Unique identifier (UUID). */
|
|
1744
|
+
id: string;
|
|
1745
|
+
/** Display name of the organization. */
|
|
1746
|
+
name: string;
|
|
1747
|
+
/** URL-safe slug (e.g. `gigadrive`). */
|
|
1748
|
+
slug: string;
|
|
1749
|
+
/** Avatar / logo URL. */
|
|
1750
|
+
imageUrl: string;
|
|
1751
|
+
/** ISO 8601 creation timestamp. */
|
|
1752
|
+
createdAt: string;
|
|
1753
|
+
/** ISO 8601 last-updated timestamp. */
|
|
1754
|
+
updatedAt: string;
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Manage organizations. Accessed via {@link GigadriveClient.organizations}.
|
|
1758
|
+
*
|
|
1759
|
+
* @example
|
|
1760
|
+
* ```ts
|
|
1761
|
+
* const { items: orgs } = await client.organizations.list();
|
|
1762
|
+
* console.log(orgs.map((o) => o.name));
|
|
1763
|
+
* ```
|
|
1764
|
+
*/
|
|
1765
|
+
declare class OrganizationsResource extends BaseResource {
|
|
1766
|
+
/**
|
|
1767
|
+
* Manage environment variables scoped to an organization.
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```ts
|
|
1771
|
+
* // List all env vars for an organization
|
|
1772
|
+
* const { items } = await client.organizations.envVars.list('org-id');
|
|
1773
|
+
*
|
|
1774
|
+
* // Create a new env var
|
|
1775
|
+
* await client.organizations.envVars.create('org-id', {
|
|
1776
|
+
* key: 'ANALYTICS_KEY',
|
|
1777
|
+
* value: 'ak_live_...',
|
|
1778
|
+
* sensitive: true,
|
|
1779
|
+
* });
|
|
1780
|
+
* ```
|
|
1781
|
+
*/
|
|
1782
|
+
readonly envVars: OrganizationEnvVarsResource;
|
|
1783
|
+
/**
|
|
1784
|
+
* AI Gateway governance for an organization: usage analytics, budgets, and
|
|
1785
|
+
* model/provider policies.
|
|
1786
|
+
*
|
|
1787
|
+
* @example
|
|
1788
|
+
* ```ts
|
|
1789
|
+
* const usage = await client.organizations.aiGateway.usage.summary('org-id', { from: '2026-06-01' });
|
|
1790
|
+
* console.log(usage.summary.totalTokens);
|
|
1791
|
+
* ```
|
|
1792
|
+
*/
|
|
1793
|
+
readonly aiGateway: OrganizationAiGatewayResource;
|
|
1794
|
+
constructor(...args: ConstructorParameters<typeof BaseResource>);
|
|
1795
|
+
/**
|
|
1796
|
+
* List organizations the authenticated actor has access to.
|
|
1797
|
+
*
|
|
1798
|
+
* @param query - Optional pagination.
|
|
1799
|
+
* @returns A paginated list of organizations.
|
|
1800
|
+
*
|
|
1801
|
+
* @example
|
|
1802
|
+
* ```ts
|
|
1803
|
+
* const { items, total } = await client.organizations.list();
|
|
1804
|
+
* console.log(`Found ${total} organizations`);
|
|
1805
|
+
* ```
|
|
1806
|
+
*/
|
|
1807
|
+
list(query?: ListQuery): Promise<Paginated<Organization>>;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
/** A Gigadrive Network application, belonging to an {@link Organization}. */
|
|
1811
|
+
interface Application {
|
|
1812
|
+
/** Unique identifier (UUID). */
|
|
1813
|
+
id: string;
|
|
1814
|
+
/** The organization this application belongs to. */
|
|
1815
|
+
organization: Organization;
|
|
1816
|
+
/** Display name of the application. */
|
|
1817
|
+
name: string;
|
|
1818
|
+
/** Avatar / logo URL. */
|
|
1819
|
+
imageUrl: string;
|
|
1820
|
+
/** ISO 8601 creation timestamp. */
|
|
1821
|
+
createdAt: string;
|
|
1822
|
+
/** ISO 8601 last-updated timestamp. */
|
|
1823
|
+
updatedAt: string;
|
|
1824
|
+
}
|
|
1825
|
+
/** Query filters for listing applications. */
|
|
1826
|
+
interface ListApplicationsQuery extends ListQuery {
|
|
1827
|
+
/** Only return applications belonging to this organization. */
|
|
1828
|
+
organizationId?: string;
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Manage applications. Accessed via {@link GigadriveClient.applications}.
|
|
1832
|
+
*
|
|
1833
|
+
* @example
|
|
1834
|
+
* ```ts
|
|
1835
|
+
* const { items: apps } = await client.applications.list();
|
|
1836
|
+
* console.log(apps.map((a) => `${a.name} (${a.organization.name})`));
|
|
1837
|
+
* ```
|
|
1838
|
+
*/
|
|
1839
|
+
declare class ApplicationsResource extends BaseResource {
|
|
1840
|
+
/**
|
|
1841
|
+
* Manage environment variables scoped to an application.
|
|
1842
|
+
*
|
|
1843
|
+
* @example
|
|
1844
|
+
* ```ts
|
|
1845
|
+
* await client.applications.envVars.create('app-id', {
|
|
1846
|
+
* key: 'DATABASE_URL',
|
|
1847
|
+
* value: 'postgres://...',
|
|
1848
|
+
* sensitive: true,
|
|
1849
|
+
* });
|
|
1850
|
+
* ```
|
|
1851
|
+
*/
|
|
1852
|
+
readonly envVars: ApplicationEnvVarsResource;
|
|
1853
|
+
/**
|
|
1854
|
+
* Manage storage buckets, objects, and file uploads for an application.
|
|
1855
|
+
*
|
|
1856
|
+
* @example
|
|
1857
|
+
* ```ts
|
|
1858
|
+
* // Upload a file
|
|
1859
|
+
* const { url } = await client.applications.storage.upload({
|
|
1860
|
+
* applicationId: 'app-id',
|
|
1861
|
+
* bucketId: 'bucket-id',
|
|
1862
|
+
* key: 'images/logo.png',
|
|
1863
|
+
* data: fileData,
|
|
1864
|
+
* });
|
|
1865
|
+
*
|
|
1866
|
+
* // List objects in a bucket
|
|
1867
|
+
* const { items } = await client.applications.storage.objects.list('app-id', 'bucket-id');
|
|
1868
|
+
* ```
|
|
1869
|
+
*/
|
|
1870
|
+
readonly storage: ApplicationStorageResource;
|
|
1871
|
+
/**
|
|
1872
|
+
* Read observed traffic (request logs) for an application.
|
|
1873
|
+
*
|
|
1874
|
+
* @example
|
|
1875
|
+
* ```ts
|
|
1876
|
+
* const { items } = await client.applications.requests.list('app-id', { statusFamily: 5 });
|
|
1877
|
+
* ```
|
|
1878
|
+
*/
|
|
1879
|
+
readonly requests: ApplicationRequestsResource;
|
|
1880
|
+
constructor(...args: ConstructorParameters<typeof BaseResource>);
|
|
1881
|
+
/**
|
|
1882
|
+
* List applications the authenticated actor has access to.
|
|
1883
|
+
*
|
|
1884
|
+
* Requires the `network:applications:read` scope.
|
|
1885
|
+
*
|
|
1886
|
+
* @param query - Optional organization filter and pagination.
|
|
1887
|
+
* @returns A paginated list of applications.
|
|
1888
|
+
*
|
|
1889
|
+
* @example
|
|
1890
|
+
* ```ts
|
|
1891
|
+
* const { items, total } = await client.applications.list({ organizationId: 'org-id' });
|
|
1892
|
+
* console.log(`Found ${total} applications`);
|
|
1893
|
+
* ```
|
|
1894
|
+
*/
|
|
1895
|
+
list(query?: ListApplicationsQuery): Promise<Paginated<Application>>;
|
|
1896
|
+
/**
|
|
1897
|
+
* List the `*.gigadrive.app` hostnames for an application (production alias
|
|
1898
|
+
* and per-branch aliases).
|
|
1899
|
+
*
|
|
1900
|
+
* @param applicationId - The application ID (UUID).
|
|
1901
|
+
* @returns The hostnames plus the production hostname `label`.
|
|
1902
|
+
*
|
|
1903
|
+
* @example
|
|
1904
|
+
* ```ts
|
|
1905
|
+
* const { items, label } = await client.applications.hostnames('app-id');
|
|
1906
|
+
* console.log(`Production: ${label}.gigadrive.app`);
|
|
1907
|
+
* ```
|
|
1908
|
+
*/
|
|
1909
|
+
hostnames(applicationId: string): Promise<ApplicationHostnameList>;
|
|
1910
|
+
/**
|
|
1911
|
+
* Check whether a candidate production hostname label is allowed and globally
|
|
1912
|
+
* available before setting it with {@link setProductionHostname}.
|
|
1913
|
+
*
|
|
1914
|
+
* Requires the `network:applications:read` scope.
|
|
1915
|
+
*
|
|
1916
|
+
* @param applicationId - The application ID (UUID).
|
|
1917
|
+
* @param label - The candidate production hostname label (e.g. `"my-app"`).
|
|
1918
|
+
* @returns Whether the label is available, plus a `reason` when it is not.
|
|
1919
|
+
*
|
|
1920
|
+
* @example
|
|
1921
|
+
* ```ts
|
|
1922
|
+
* const { available, reason } = await client.applications.checkHostnameAvailability('app-id', 'my-app');
|
|
1923
|
+
* if (!available) console.log(`Unavailable: ${reason}`);
|
|
1924
|
+
* ```
|
|
1925
|
+
*/
|
|
1926
|
+
checkHostnameAvailability(applicationId: string, label: string): Promise<HostnameAvailability>;
|
|
1927
|
+
/**
|
|
1928
|
+
* Set the application's production hostname. The production alias
|
|
1929
|
+
* `{label}.gigadrive.app` is re-pointed to the latest production deployment.
|
|
1930
|
+
*
|
|
1931
|
+
* Requires the `network:applications:write` scope. Deployment- and
|
|
1932
|
+
* function-scoped tokens cannot change the production hostname.
|
|
1933
|
+
*
|
|
1934
|
+
* @param applicationId - The application ID (UUID).
|
|
1935
|
+
* @param label - The production hostname label (e.g. `"my-app"`). It is
|
|
1936
|
+
* normalized (slugified) server-side.
|
|
1937
|
+
* @returns The saved label, the resulting hostname, and whether it is live yet.
|
|
1938
|
+
*
|
|
1939
|
+
* @example
|
|
1940
|
+
* ```ts
|
|
1941
|
+
* const { hostname, live } = await client.applications.setProductionHostname('app-id', 'my-app');
|
|
1942
|
+
* console.log(live ? `Live at ${hostname}` : `Reserved ${hostname} (deploy to go live)`);
|
|
1943
|
+
* ```
|
|
1944
|
+
*/
|
|
1945
|
+
setProductionHostname(applicationId: string, label: string): Promise<SetProductionHostnameResult>;
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
/**
|
|
1949
|
+
* The lifecycle status of a deployment.
|
|
1950
|
+
* - `"PENDING"` — Created, waiting for artifact upload.
|
|
1951
|
+
* - `"QUEUED"` — Queued for processing.
|
|
1952
|
+
* - `"STARTING"` — Processing is starting.
|
|
1953
|
+
* - `"BUILDING"` — Build pipeline is running.
|
|
1954
|
+
* - `"PROVISIONING"` — Infrastructure is being provisioned.
|
|
1955
|
+
* - `"ACTIVE"` — Successfully deployed and serving traffic.
|
|
1956
|
+
* - `"FAILED"` — Build or provisioning failed.
|
|
1957
|
+
*/
|
|
1958
|
+
type DeploymentStatus = 'PENDING' | 'QUEUED' | 'STARTING' | 'BUILDING' | 'PROVISIONING' | 'ACTIVE' | 'FAILED';
|
|
1959
|
+
/** The severity level of a deployment log entry. */
|
|
1960
|
+
type DeploymentLogType = 'INFO' | 'ERROR' | 'WARN';
|
|
1961
|
+
/** A deployment of an application to the Gigadrive Network. */
|
|
1962
|
+
interface Deployment {
|
|
1963
|
+
/** Unique identifier (UUID). */
|
|
1964
|
+
id: string;
|
|
1965
|
+
/** The application this deployment belongs to. */
|
|
1966
|
+
applicationId: string;
|
|
1967
|
+
/** Current lifecycle status. */
|
|
1968
|
+
status: DeploymentStatus;
|
|
1969
|
+
/** ISO 8601 creation timestamp. */
|
|
1970
|
+
createdAt: string;
|
|
1971
|
+
/** ISO 8601 last-updated timestamp. */
|
|
1972
|
+
updatedAt: string;
|
|
1973
|
+
}
|
|
1974
|
+
/** A single log entry from a deployment's build or provisioning pipeline. */
|
|
1975
|
+
interface DeploymentLog {
|
|
1976
|
+
/** Unique identifier. */
|
|
1977
|
+
id: string;
|
|
1978
|
+
/** The log message text. */
|
|
1979
|
+
message: string;
|
|
1980
|
+
/** Severity level: `"INFO"`, `"ERROR"`, or `"WARN"`. */
|
|
1981
|
+
type: DeploymentLogType;
|
|
1982
|
+
/** ISO 8601 timestamp of when this log entry was created. */
|
|
1983
|
+
createdAt: string;
|
|
1984
|
+
}
|
|
1985
|
+
/** A paginated page of deployment log entries. */
|
|
1986
|
+
interface DeploymentLogPage {
|
|
1987
|
+
/** Total number of log entries for this deployment. */
|
|
1988
|
+
totalItems: number;
|
|
1989
|
+
/** Maximum number of entries per page. */
|
|
1990
|
+
limit: number;
|
|
1991
|
+
/** Number of entries skipped (for pagination). */
|
|
1992
|
+
offset: number;
|
|
1993
|
+
/** The log entries on this page. */
|
|
1994
|
+
items: DeploymentLog[];
|
|
1995
|
+
}
|
|
1996
|
+
/** Input for creating a new deployment. */
|
|
1997
|
+
interface CreateDeploymentInput {
|
|
1998
|
+
/** The application to deploy. */
|
|
1999
|
+
applicationId: string;
|
|
2000
|
+
/** Optional git source for the deployment. When omitted, the deployment expects an artifact upload. */
|
|
2001
|
+
gitSource?: {
|
|
2002
|
+
/** The git ref to deploy (e.g. `"main"`, `"v1.0.0"`). */
|
|
2003
|
+
ref: string;
|
|
2004
|
+
/** A specific commit SHA to deploy. If omitted, the HEAD of the ref is used. */
|
|
2005
|
+
sha?: string;
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
/** Query filters for listing deployments. All fields are optional. */
|
|
2009
|
+
interface ListDeploymentsQuery {
|
|
2010
|
+
/** Filter by organization ID. */
|
|
2011
|
+
organizationId?: string;
|
|
2012
|
+
/** Filter by application ID. */
|
|
2013
|
+
applicationId?: string;
|
|
2014
|
+
/** Filter by deployment status. */
|
|
2015
|
+
status?: DeploymentStatus;
|
|
2016
|
+
}
|
|
2017
|
+
/** Query parameters for fetching deployment logs. */
|
|
2018
|
+
interface ListDeploymentLogsQuery {
|
|
2019
|
+
/** Number of log entries to skip (for pagination). */
|
|
2020
|
+
offset?: number;
|
|
2021
|
+
/** Maximum number of log entries to return per page. */
|
|
2022
|
+
limit?: number;
|
|
2023
|
+
/** Only return log entries created after this ISO 8601 timestamp. Useful for tailing logs. */
|
|
2024
|
+
'createdAt[gt]'?: string;
|
|
2025
|
+
}
|
|
2026
|
+
/** Result from starting a multipart deployment upload. */
|
|
2027
|
+
interface StartUploadResult {
|
|
2028
|
+
/** The multipart upload ID. Pass this to subsequent `getPresignedUrl` and `completeUpload` calls. */
|
|
2029
|
+
uploadId: string;
|
|
2030
|
+
}
|
|
2031
|
+
/** A presigned URL for uploading a single part of a multipart deployment upload. */
|
|
2032
|
+
interface PresignedUrlResult {
|
|
2033
|
+
/** The presigned URL to PUT the part data to. */
|
|
2034
|
+
url: string;
|
|
2035
|
+
}
|
|
2036
|
+
/** A successfully uploaded part, used to complete the multipart upload. */
|
|
2037
|
+
interface UploadPart {
|
|
2038
|
+
/** The 1-based part number. */
|
|
2039
|
+
partNumber: number;
|
|
2040
|
+
/** The ETag returned by the storage provider after uploading this part. */
|
|
2041
|
+
etag: string;
|
|
2042
|
+
}
|
|
2043
|
+
/**
|
|
2044
|
+
* Manage deployments — create, monitor, upload artifacts, and read logs.
|
|
2045
|
+
* Accessed via {@link GigadriveClient.deployments}.
|
|
2046
|
+
*
|
|
2047
|
+
* ## Deployment lifecycle
|
|
2048
|
+
*
|
|
2049
|
+
* 1. **Create** a deployment with {@link create}.
|
|
2050
|
+
* 2. **Upload** build artifacts using the multipart upload flow
|
|
2051
|
+
* ({@link startUpload} → {@link getPresignedUrl} → {@link uploadPart} → {@link completeUpload}).
|
|
2052
|
+
* 3. **Monitor** the build with {@link get} and {@link getLogs}.
|
|
2053
|
+
*
|
|
2054
|
+
* @example
|
|
2055
|
+
* ```ts
|
|
2056
|
+
* // Create a deployment
|
|
2057
|
+
* const deployment = await client.deployments.create({ applicationId: 'app-id' });
|
|
2058
|
+
*
|
|
2059
|
+
* // Check status
|
|
2060
|
+
* const updated = await client.deployments.get(deployment.id);
|
|
2061
|
+
* console.log(`Status: ${updated.status}`);
|
|
2062
|
+
*
|
|
2063
|
+
* // Read build logs
|
|
2064
|
+
* const logs = await client.deployments.getLogs(deployment.id, { limit: 50 });
|
|
2065
|
+
* for (const entry of logs.items) {
|
|
2066
|
+
* console.log(`[${entry.type}] ${entry.message}`);
|
|
2067
|
+
* }
|
|
2068
|
+
* ```
|
|
2069
|
+
*/
|
|
2070
|
+
declare class DeploymentsResource extends BaseResource {
|
|
2071
|
+
/**
|
|
2072
|
+
* List deployments, optionally filtered by organization, application, or status.
|
|
2073
|
+
*
|
|
2074
|
+
* Requires the `network:deployments:read` scope.
|
|
2075
|
+
*
|
|
2076
|
+
* @param query - Optional filters.
|
|
2077
|
+
* @returns A paginated list of deployments.
|
|
2078
|
+
*
|
|
2079
|
+
* @example
|
|
2080
|
+
* ```ts
|
|
2081
|
+
* // All deployments for an application
|
|
2082
|
+
* const { items } = await client.deployments.list({ applicationId: 'app-id' });
|
|
2083
|
+
*
|
|
2084
|
+
* // Only active deployments
|
|
2085
|
+
* const { items } = await client.deployments.list({ status: 'ACTIVE' });
|
|
2086
|
+
* ```
|
|
2087
|
+
*/
|
|
2088
|
+
list(query?: ListDeploymentsQuery): Promise<Paginated<Deployment>>;
|
|
2089
|
+
/**
|
|
2090
|
+
* Get a deployment by ID, including its current status.
|
|
2091
|
+
*
|
|
2092
|
+
* @param deploymentId - The deployment ID (UUID).
|
|
2093
|
+
* @returns The deployment with its current status.
|
|
2094
|
+
*
|
|
2095
|
+
* @example
|
|
2096
|
+
* ```ts
|
|
2097
|
+
* const deployment = await client.deployments.get('deployment-id');
|
|
2098
|
+
* if (deployment.status === 'ACTIVE') {
|
|
2099
|
+
* console.log('Deployment is live!');
|
|
2100
|
+
* }
|
|
2101
|
+
* ```
|
|
2102
|
+
*/
|
|
2103
|
+
get(deploymentId: string): Promise<Deployment>;
|
|
2104
|
+
/**
|
|
2105
|
+
* Create a new deployment. The deployment starts in `"PENDING"` status,
|
|
2106
|
+
* waiting for artifact upload. Use the multipart upload methods
|
|
2107
|
+
* ({@link startUpload}, {@link getPresignedUrl}, {@link uploadPart},
|
|
2108
|
+
* {@link completeUpload}) to upload build artifacts.
|
|
2109
|
+
*
|
|
2110
|
+
* Requires the `network:deployments:trigger` scope.
|
|
2111
|
+
*
|
|
2112
|
+
* @param data - The application ID and optional git source.
|
|
2113
|
+
* @returns The newly created deployment.
|
|
2114
|
+
*
|
|
2115
|
+
* @example
|
|
2116
|
+
* ```ts
|
|
2117
|
+
* const deployment = await client.deployments.create({
|
|
2118
|
+
* applicationId: 'app-id',
|
|
2119
|
+
* });
|
|
2120
|
+
* console.log(`Created deployment ${deployment.id} (${deployment.status})`);
|
|
2121
|
+
* ```
|
|
2122
|
+
*/
|
|
2123
|
+
create(data: CreateDeploymentInput): Promise<Deployment>;
|
|
2124
|
+
/**
|
|
2125
|
+
* Start a multipart upload for deployment artifacts. This initiates a new
|
|
2126
|
+
* multipart upload and returns an upload ID for subsequent part uploads.
|
|
2127
|
+
*
|
|
2128
|
+
* The deployment must be in `"PENDING"` status.
|
|
2129
|
+
*
|
|
2130
|
+
* @param deploymentId - The deployment ID (UUID).
|
|
2131
|
+
* @returns An object containing the `uploadId` for subsequent calls.
|
|
2132
|
+
*
|
|
2133
|
+
* @example
|
|
2134
|
+
* ```ts
|
|
2135
|
+
* const { uploadId } = await client.deployments.startUpload('deployment-id');
|
|
2136
|
+
* ```
|
|
2137
|
+
*/
|
|
2138
|
+
startUpload(deploymentId: string): Promise<StartUploadResult>;
|
|
2139
|
+
/**
|
|
2140
|
+
* Get a presigned URL for uploading a single part of a multipart upload.
|
|
2141
|
+
* The URL is temporary and should be used immediately with {@link uploadPart}.
|
|
2142
|
+
*
|
|
2143
|
+
* @param deploymentId - The deployment ID (UUID).
|
|
2144
|
+
* @param uploadId - The multipart upload ID from {@link startUpload}.
|
|
2145
|
+
* @param partNumber - The 1-based part number.
|
|
2146
|
+
* @returns An object containing the presigned `url` to PUT the part data to.
|
|
2147
|
+
*
|
|
2148
|
+
* @example
|
|
2149
|
+
* ```ts
|
|
2150
|
+
* const { url } = await client.deployments.getPresignedUrl(
|
|
2151
|
+
* 'deployment-id', uploadId, 1,
|
|
2152
|
+
* );
|
|
2153
|
+
* ```
|
|
2154
|
+
*/
|
|
2155
|
+
getPresignedUrl(deploymentId: string, uploadId: string, partNumber: number): Promise<PresignedUrlResult>;
|
|
2156
|
+
/**
|
|
2157
|
+
* Upload a part to a presigned URL obtained from {@link getPresignedUrl}.
|
|
2158
|
+
* This sends the chunk data directly to the backend storage service, not
|
|
2159
|
+
* to the Gigadrive API. The returned `etag` is needed for
|
|
2160
|
+
* {@link completeUpload}.
|
|
2161
|
+
*
|
|
2162
|
+
* @param presignedUrl - The presigned URL from {@link getPresignedUrl}.
|
|
2163
|
+
* @param data - The chunk data to upload.
|
|
2164
|
+
* @param partNumber - The 1-based part number (used for error messages).
|
|
2165
|
+
* @returns The part number and ETag. Collect these for {@link completeUpload}.
|
|
2166
|
+
* @throws {@link ApiError} if the PUT request fails.
|
|
2167
|
+
* @throws Error if the storage provider does not return an ETag header.
|
|
2168
|
+
*
|
|
2169
|
+
* @example
|
|
2170
|
+
* ```ts
|
|
2171
|
+
* const chunk = fileBuffer.subarray(0, 10 * 1024 * 1024); // 10 MB
|
|
2172
|
+
* const part = await client.deployments.uploadPart(presignedUrl, chunk, 1);
|
|
2173
|
+
* // part = { partNumber: 1, etag: '"abc123..."' }
|
|
2174
|
+
* ```
|
|
2175
|
+
*/
|
|
2176
|
+
uploadPart(presignedUrl: string, data: ArrayBuffer | Uint8Array | Blob, partNumber: number): Promise<UploadPart>;
|
|
2177
|
+
/**
|
|
2178
|
+
* Complete a multipart upload after all parts have been uploaded via
|
|
2179
|
+
* {@link uploadPart}. This signals the storage provider to assemble the
|
|
2180
|
+
* parts into a single object and triggers the deployment build pipeline.
|
|
2181
|
+
*
|
|
2182
|
+
* @param deploymentId - The deployment ID (UUID).
|
|
2183
|
+
* @param uploadId - The multipart upload ID from {@link startUpload}.
|
|
2184
|
+
* @param parts - Array of `{ partNumber, etag }` from each {@link uploadPart} call.
|
|
2185
|
+
*
|
|
2186
|
+
* @example
|
|
2187
|
+
* ```ts
|
|
2188
|
+
* await client.deployments.completeUpload(deploymentId, uploadId, [
|
|
2189
|
+
* { partNumber: 1, etag: '"abc..."' },
|
|
2190
|
+
* { partNumber: 2, etag: '"def..."' },
|
|
2191
|
+
* ]);
|
|
2192
|
+
* ```
|
|
2193
|
+
*/
|
|
2194
|
+
completeUpload(deploymentId: string, uploadId: string, parts: UploadPart[]): Promise<void>;
|
|
2195
|
+
/**
|
|
2196
|
+
* Fetch deployment logs. Supports pagination and filtering by timestamp
|
|
2197
|
+
* for incremental log tailing.
|
|
2198
|
+
*
|
|
2199
|
+
* @param deploymentId - The deployment ID (UUID).
|
|
2200
|
+
* @param query - Optional pagination and filter parameters.
|
|
2201
|
+
* @returns A page of log entries with total count.
|
|
2202
|
+
*
|
|
2203
|
+
* @example
|
|
2204
|
+
* ```ts
|
|
2205
|
+
* // Get the first page of logs
|
|
2206
|
+
* const page = await client.deployments.getLogs('deployment-id', {
|
|
2207
|
+
* offset: 0,
|
|
2208
|
+
* limit: 100,
|
|
2209
|
+
* });
|
|
2210
|
+
*
|
|
2211
|
+
* for (const entry of page.items) {
|
|
2212
|
+
* const prefix = entry.type === 'ERROR' ? 'ERR' : entry.type === 'WARN' ? 'WRN' : 'INF';
|
|
2213
|
+
* console.log(`[${prefix}] ${entry.message}`);
|
|
2214
|
+
* }
|
|
2215
|
+
*
|
|
2216
|
+
* // Tail new logs since last fetch
|
|
2217
|
+
* const newLogs = await client.deployments.getLogs('deployment-id', {
|
|
2218
|
+
* 'createdAt[gt]': lastEntry.createdAt,
|
|
2219
|
+
* });
|
|
2220
|
+
* ```
|
|
2221
|
+
*/
|
|
2222
|
+
getLogs(deploymentId: string, query?: ListDeploymentLogsQuery): Promise<DeploymentLogPage>;
|
|
2223
|
+
/**
|
|
2224
|
+
* List the immutable `*.gigadrive.app` hostnames assigned to a deployment.
|
|
2225
|
+
*
|
|
2226
|
+
* @param deploymentId - The deployment ID (UUID).
|
|
2227
|
+
* @returns A paginated list of hostnames.
|
|
2228
|
+
*
|
|
2229
|
+
* @example
|
|
2230
|
+
* ```ts
|
|
2231
|
+
* const { items } = await client.deployments.getHostnames('deployment-id');
|
|
2232
|
+
* console.log(items.map((h) => h.hostname));
|
|
2233
|
+
* ```
|
|
2234
|
+
*/
|
|
2235
|
+
getHostnames(deploymentId: string): Promise<Paginated<Hostname>>;
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
/**
|
|
2239
|
+
* Configuration for the {@link GigadriveClient}.
|
|
2240
|
+
*
|
|
2241
|
+
* Credentials are resolved in priority order: explicit config fields first,
|
|
2242
|
+
* then environment variables. See {@link GigadriveClient} for the full
|
|
2243
|
+
* resolution chain.
|
|
2244
|
+
*/
|
|
2245
|
+
interface GigadriveClientConfig {
|
|
2246
|
+
/**
|
|
2247
|
+
* OAuth2 client ID (the API key ID from the Gigadrive dashboard).
|
|
2248
|
+
* Used for both client-credentials and refresh-token flows.
|
|
2249
|
+
* Falls back to the `GIGADRIVE_CLIENT_ID` environment variable.
|
|
2250
|
+
*/
|
|
2251
|
+
clientId?: string;
|
|
2252
|
+
/**
|
|
2253
|
+
* OAuth2 client secret (the API key secret from the Gigadrive dashboard).
|
|
2254
|
+
* Used together with {@link clientId} for the client-credentials grant.
|
|
2255
|
+
* Falls back to the `GIGADRIVE_CLIENT_SECRET` environment variable.
|
|
2256
|
+
*/
|
|
2257
|
+
clientSecret?: string;
|
|
2258
|
+
/**
|
|
2259
|
+
* A pre-obtained bearer token (either an IDP or Network token).
|
|
2260
|
+
* When set, the SDK sends this token directly without any OAuth exchange.
|
|
2261
|
+
* The token is never refreshed — if it expires, requests will fail.
|
|
2262
|
+
* Falls back to the `GIGADRIVE_BEARER_TOKEN` environment variable.
|
|
2263
|
+
*/
|
|
2264
|
+
bearerToken?: string;
|
|
2265
|
+
/**
|
|
2266
|
+
* An IDP refresh token for automatic access-token renewal. Used together
|
|
2267
|
+
* with {@link clientId}. The SDK will exchange this for short-lived access
|
|
2268
|
+
* tokens and handle refresh-token rotation automatically.
|
|
2269
|
+
* Falls back to the `GIGADRIVE_REFRESH_TOKEN` environment variable.
|
|
2270
|
+
*/
|
|
2271
|
+
refreshToken?: string;
|
|
2272
|
+
/**
|
|
2273
|
+
* The IDP issuer URL used for OIDC discovery (fetching the
|
|
2274
|
+
* `.well-known/openid-configuration`). Only needed for refresh-token and
|
|
2275
|
+
* authorization-code flows.
|
|
2276
|
+
* Falls back to `GIGADRIVE_IDP_ISSUER_URL`, default: `https://idp.gigadrive.de`.
|
|
2277
|
+
*/
|
|
2278
|
+
idpIssuerUrl?: string;
|
|
2279
|
+
/**
|
|
2280
|
+
* Callback for the OAuth2 authorization code flow with PKCE. The SDK
|
|
2281
|
+
* builds the authorization URL and passes it to this callback. Your code
|
|
2282
|
+
* must present the URL to the user (e.g. open a browser), then return
|
|
2283
|
+
* either the full redirect URL or just the authorization code.
|
|
2284
|
+
*
|
|
2285
|
+
* Requires {@link clientId} to be set.
|
|
2286
|
+
*
|
|
2287
|
+
* @param url - The authorization URL the user should visit.
|
|
2288
|
+
* @returns The full redirect URL (including `?code=...&state=...`) or the
|
|
2289
|
+
* bare authorization code.
|
|
2290
|
+
*
|
|
2291
|
+
* @example
|
|
2292
|
+
* ```ts
|
|
2293
|
+
* const client = new GigadriveClient({
|
|
2294
|
+
* clientId: 'my-app',
|
|
2295
|
+
* onAuthorizationUrl: async (url) => {
|
|
2296
|
+
* console.log('Visit:', url);
|
|
2297
|
+
* return await readline.question('Paste the redirect URL: ');
|
|
2298
|
+
* },
|
|
2299
|
+
* });
|
|
2300
|
+
* ```
|
|
2301
|
+
*/
|
|
2302
|
+
onAuthorizationUrl?: (url: string) => Promise<string>;
|
|
2303
|
+
/**
|
|
2304
|
+
* Redirect URI for the authorization code flow.
|
|
2305
|
+
* Default: `urn:ietf:wg:oauth:2.0:oob` (out-of-band / manual copy-paste).
|
|
2306
|
+
*/
|
|
2307
|
+
redirectUri?: string;
|
|
2308
|
+
/**
|
|
2309
|
+
* OAuth scopes to request during the authorization-code flow, in addition to
|
|
2310
|
+
* the default identity scopes (`openid profile email offline_access`). Use
|
|
2311
|
+
* this to request API capability scopes (e.g. `network:applications:read`) so
|
|
2312
|
+
* the resulting token can call the corresponding endpoints.
|
|
2313
|
+
*/
|
|
2314
|
+
scopes?: string[];
|
|
2315
|
+
/**
|
|
2316
|
+
* Base URL of the Gigadrive Network API.
|
|
2317
|
+
* Falls back to `GIGADRIVE_API_BASE_URL`, default: `https://api.gigadrive.network`.
|
|
2318
|
+
*/
|
|
2319
|
+
baseUrl?: string;
|
|
2320
|
+
/**
|
|
2321
|
+
* Custom `fetch` implementation. Useful for testing (injectable mock) or
|
|
2322
|
+
* non-standard runtimes like Cloudflare Workers that provide their own
|
|
2323
|
+
* `fetch`. Defaults to `globalThis.fetch`.
|
|
2324
|
+
*/
|
|
2325
|
+
fetch?: typeof globalThis.fetch;
|
|
2326
|
+
}
|
|
2327
|
+
/**
|
|
2328
|
+
* The main entry point for the Gigadrive Network SDK.
|
|
2329
|
+
*
|
|
2330
|
+
* Create an instance to interact with organizations, applications, deployments,
|
|
2331
|
+
* storage, and the AI gateway. Authentication is handled automatically —
|
|
2332
|
+
* tokens are obtained, cached, and refreshed behind the scenes.
|
|
2333
|
+
*
|
|
2334
|
+
* ## Credential resolution order
|
|
2335
|
+
*
|
|
2336
|
+
* The client resolves credentials in the following order, using the first
|
|
2337
|
+
* match it finds:
|
|
2338
|
+
*
|
|
2339
|
+
* 1. Explicit `bearerToken` in config
|
|
2340
|
+
* 2. Explicit `clientId` + `clientSecret` in config
|
|
2341
|
+
* 3. Explicit `clientId` + `refreshToken` in config
|
|
2342
|
+
* 4. Explicit `clientId` + `onAuthorizationUrl` callback in config
|
|
2343
|
+
* 5. `GIGADRIVE_BEARER_TOKEN` environment variable
|
|
2344
|
+
* 6. `GIGADRIVE_CLIENT_ID` + `GIGADRIVE_CLIENT_SECRET` environment variables
|
|
2345
|
+
* 7. `GIGADRIVE_CLIENT_ID` + `GIGADRIVE_REFRESH_TOKEN` environment variables
|
|
2346
|
+
*
|
|
2347
|
+
* If no credentials are found, the constructor throws an
|
|
2348
|
+
* {@link AuthenticationError}.
|
|
2349
|
+
*
|
|
2350
|
+
* @example
|
|
2351
|
+
* ```ts
|
|
2352
|
+
* // Credentials auto-detected from environment variables
|
|
2353
|
+
* const client = new GigadriveClient();
|
|
2354
|
+
*
|
|
2355
|
+
* // Explicit API key (client credentials)
|
|
2356
|
+
* const client = new GigadriveClient({
|
|
2357
|
+
* clientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
|
|
2358
|
+
* clientSecret: 'sk_live_...',
|
|
2359
|
+
* });
|
|
2360
|
+
*
|
|
2361
|
+
* // Pre-obtained bearer token
|
|
2362
|
+
* const client = new GigadriveClient({ bearerToken: 'eyJ...' });
|
|
2363
|
+
*
|
|
2364
|
+
* // IDP refresh token — access tokens are renewed automatically
|
|
2365
|
+
* const client = new GigadriveClient({
|
|
2366
|
+
* clientId: 'my-app',
|
|
2367
|
+
* refreshToken: 'rt_...',
|
|
2368
|
+
* });
|
|
2369
|
+
*
|
|
2370
|
+
* // Use the client
|
|
2371
|
+
* const orgs = await client.organizations.list();
|
|
2372
|
+
* const deployment = await client.deployments.create({ applicationId: 'app-1' });
|
|
2373
|
+
* ```
|
|
2374
|
+
*
|
|
2375
|
+
* @throws {@link AuthenticationError} if no valid credentials are found.
|
|
2376
|
+
*/
|
|
2377
|
+
declare class GigadriveClient {
|
|
2378
|
+
/** Organization management (list, environment variables). */
|
|
2379
|
+
readonly organizations: OrganizationsResource;
|
|
2380
|
+
/** Application management (list, environment variables, storage). */
|
|
2381
|
+
readonly applications: ApplicationsResource;
|
|
2382
|
+
/** Deployment lifecycle (create, upload, status, logs). */
|
|
2383
|
+
readonly deployments: DeploymentsResource;
|
|
2384
|
+
/** AI Gateway — OpenAI-compatible chat completions and model listing. */
|
|
2385
|
+
readonly aiGateway: AiGatewayResource;
|
|
2386
|
+
constructor(config?: GigadriveClientConfig);
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
/**
|
|
2390
|
+
* Base error class for all Gigadrive SDK errors. Every error thrown by the SDK
|
|
2391
|
+
* extends this class, so you can catch all SDK errors with a single check.
|
|
2392
|
+
*
|
|
2393
|
+
* @example
|
|
2394
|
+
* ```ts
|
|
2395
|
+
* try {
|
|
2396
|
+
* await client.organizations.list();
|
|
2397
|
+
* } catch (err) {
|
|
2398
|
+
* if (err instanceof GigadriveError) {
|
|
2399
|
+
* console.error('SDK error:', err.message);
|
|
2400
|
+
* }
|
|
2401
|
+
* }
|
|
2402
|
+
* ```
|
|
2403
|
+
*/
|
|
2404
|
+
declare class GigadriveError extends Error {
|
|
2405
|
+
constructor(message: string);
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Thrown when authentication fails. This includes missing or invalid credentials,
|
|
2409
|
+
* expired tokens, failed token refresh attempts, and failed token exchanges.
|
|
2410
|
+
*
|
|
2411
|
+
* Common causes:
|
|
2412
|
+
* - No credentials provided and no environment variables set
|
|
2413
|
+
* - Invalid `clientId`/`clientSecret` pair
|
|
2414
|
+
* - Expired or revoked refresh token
|
|
2415
|
+
* - API returned 401 even after an automatic token refresh retry
|
|
2416
|
+
*
|
|
2417
|
+
* @example
|
|
2418
|
+
* ```ts
|
|
2419
|
+
* try {
|
|
2420
|
+
* const client = new GigadriveClient(); // no credentials
|
|
2421
|
+
* } catch (err) {
|
|
2422
|
+
* if (err instanceof AuthenticationError) {
|
|
2423
|
+
* console.error('Auth failed:', err.message);
|
|
2424
|
+
* }
|
|
2425
|
+
* }
|
|
2426
|
+
* ```
|
|
2427
|
+
*/
|
|
2428
|
+
declare class AuthenticationError extends GigadriveError {
|
|
2429
|
+
constructor(message: string);
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* Thrown when the Gigadrive API returns a non-2xx HTTP response.
|
|
2433
|
+
*
|
|
2434
|
+
* Contains the HTTP {@link status} code and an optional machine-readable
|
|
2435
|
+
* {@link code} parsed from the response body.
|
|
2436
|
+
*
|
|
2437
|
+
* @example
|
|
2438
|
+
* ```ts
|
|
2439
|
+
* try {
|
|
2440
|
+
* await client.deployments.get('non-existent-id');
|
|
2441
|
+
* } catch (err) {
|
|
2442
|
+
* if (err instanceof ApiError) {
|
|
2443
|
+
* console.error(`API error ${err.status}: ${err.message}`);
|
|
2444
|
+
* // err.code may contain a machine-readable error code
|
|
2445
|
+
* }
|
|
2446
|
+
* }
|
|
2447
|
+
* ```
|
|
2448
|
+
*/
|
|
2449
|
+
declare class ApiError extends GigadriveError {
|
|
2450
|
+
/** The HTTP status code of the failed response (e.g. 404, 500). */
|
|
2451
|
+
readonly status: number;
|
|
2452
|
+
/** An optional machine-readable error code from the API response body. */
|
|
2453
|
+
readonly code: string | undefined;
|
|
2454
|
+
constructor(message: string, status: number, code?: string);
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Thrown when a file upload fails. The original cause (e.g. a network error or a
|
|
2458
|
+
* transport-level error from the resumable upload) is preserved on
|
|
2459
|
+
* {@link cause} for inspection.
|
|
2460
|
+
*
|
|
2461
|
+
* @example
|
|
2462
|
+
* ```ts
|
|
2463
|
+
* try {
|
|
2464
|
+
* await client.applications.storage.upload({ applicationId, bucketId, key, data });
|
|
2465
|
+
* } catch (err) {
|
|
2466
|
+
* if (err instanceof UploadError) {
|
|
2467
|
+
* console.error('Upload failed:', err.message, err.cause);
|
|
2468
|
+
* }
|
|
2469
|
+
* }
|
|
2470
|
+
* ```
|
|
2471
|
+
*/
|
|
2472
|
+
declare class UploadError extends GigadriveError {
|
|
2473
|
+
/** The underlying error that caused the upload to fail, if any. */
|
|
2474
|
+
readonly cause: unknown;
|
|
2475
|
+
constructor(message: string, cause?: unknown);
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Thrown when an upload cannot complete because its session (and the short-lived
|
|
2479
|
+
* upload URL it was issued with) expired. Create a new upload to retry.
|
|
2480
|
+
*
|
|
2481
|
+
* The upload URL is only valid until `session.expiresAt`; very large uploads on
|
|
2482
|
+
* slow connections can exceed that window.
|
|
2483
|
+
*/
|
|
2484
|
+
declare class UploadSessionExpiredError extends UploadError {
|
|
2485
|
+
constructor(message?: string, cause?: unknown);
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
/**
|
|
2489
|
+
* Lazily iterate every item across all pages of a cursor-paginated endpoint.
|
|
2490
|
+
* Pass a function that fetches one page for a given cursor; iteration stops when
|
|
2491
|
+
* the API stops returning a `nextCursor`.
|
|
2492
|
+
*
|
|
2493
|
+
* @typeParam T - The item type.
|
|
2494
|
+
* @param fetchPage - Fetches a single page for the given cursor (`undefined` for the first page).
|
|
2495
|
+
*
|
|
2496
|
+
* @example
|
|
2497
|
+
* ```ts
|
|
2498
|
+
* for await (const object of paginate((cursor) =>
|
|
2499
|
+
* client.applications.storage.objects.list('app-id', 'bucket-id', { cursor }),
|
|
2500
|
+
* )) {
|
|
2501
|
+
* console.log(object.key);
|
|
2502
|
+
* }
|
|
2503
|
+
* ```
|
|
2504
|
+
*/
|
|
2505
|
+
declare function paginate<T>(fetchPage: (cursor: string | undefined) => Promise<Paginated<T>>): AsyncGenerator<T>;
|
|
2506
|
+
|
|
2507
|
+
/**
|
|
2508
|
+
* Server-Sent Events (SSE) parsing for streamed API responses (e.g. streamed
|
|
2509
|
+
* chat completions). Works in browsers and Node.js 18+ where `Response.body` is
|
|
2510
|
+
* a web `ReadableStream`.
|
|
2511
|
+
*
|
|
2512
|
+
* @internal
|
|
2513
|
+
*/
|
|
2514
|
+
/**
|
|
2515
|
+
* Parse an SSE stream, yielding each event's `data` payload parsed as JSON.
|
|
2516
|
+
* The `[DONE]` sentinel and empty keep-alive events are skipped; iteration ends
|
|
2517
|
+
* when the underlying stream closes.
|
|
2518
|
+
*
|
|
2519
|
+
* @typeParam T - The shape of each streamed JSON chunk.
|
|
2520
|
+
* @param response - A streaming `fetch` response.
|
|
2521
|
+
*/
|
|
2522
|
+
declare function parseSSEStream<T = unknown>(response: Response): AsyncGenerator<T>;
|
|
2523
|
+
|
|
2524
|
+
export { AiGatewayAudioResource, type AiGatewayBudget, type AiGatewayBudgetInput, AiGatewayBudgetsResource, AiGatewayPoliciesResource, type AiGatewayPolicy, type AiGatewayPolicyInput, type AiGatewayProviderAttempt, type AiGatewayRequestEvent, type AiGatewayRequestsQuery, AiGatewayResource, type AiGatewayUsageBreakdown, type AiGatewayUsageQuery, AiGatewayUsageResource, type AiGatewayUsageSummary, AiGatewayVideosResource, type AiModel, type AiModelCapabilities, type AiModelRoutingProvider, ApiError, type Application, ApplicationEnvVarsResource, type ApplicationHostnameList, ApplicationRequestsResource, ApplicationStorageResource, ApplicationsResource, AuthenticationError, type ChatCompletionChoice, type ChatCompletionChunk, type ChatCompletionContentPart, type ChatCompletionMessage, type ChatCompletionRequest, type ChatCompletionResponse, type ChatCompletionUsage, type CreateDeploymentInput, type CreateEnvVarInput, type CreateStorageBucketInput, type CreateUploadSessionInput, type CreateUploadSessionResponse, type Deployment, type DeploymentLog, type DeploymentLogPage, type DeploymentLogType, type DeploymentStatus, DeploymentsResource, type EnvVar, type GatewayRequestOptions, type GatewayResult, GigadriveClient, type GigadriveClientConfig, GigadriveError, type Hostname, type HostnameAvailability, type ListApplicationsQuery, type ListDeploymentLogsQuery, type ListDeploymentsQuery, type ListQuery, type ListRequestsQuery, type ListStorageObjectsQuery, type NetworkRequest, type NetworkRequestApplicationRef, type NetworkRequestAssetRef, type NetworkRequestBucketRef, type NetworkRequestDeploymentRef, type NetworkRequestDetails, type NetworkRequestFunctionRef, type NetworkRequestMetrics, type NetworkRequestObjectRef, type NetworkRequestSummary, type NetworkResponseDetails, type NodeReadableLike, type Organization, OrganizationAiGatewayResource, OrganizationEnvVarsResource, OrganizationsResource, type Paginated, type PresignedUrlResult, type ProviderRouting, type QueryValue, type ResponsesRequest, type ResponsesResponse, type RunUploadOptions, type SetProductionHostnameResult, type SpeechRequest, type StartUploadResult, type StorageBucket, StorageBucketsResource, type StorageObject, type StorageObjectAccess, type StorageObjectList, StorageObjectsResource, type StorageUploadSession, StorageUploadSessionsResource, type TranscriptionRequest, type TranscriptionResponse, type UpdateEnvVarInput, type UploadBatchItemResult, type UploadBatchOptions, type UploadByteSource, type UploadData, UploadError, type UploadFileInput, type UploadFileResult, type UploadPart, UploadSessionExpiredError, type UploadUrlStorage, type VideoGenerationRequest, type VideoGenerationResponse, type VideoModelList, type WaitForCompletionOptions, paginate, parseSSEStream };
|