@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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/test.ts","../src/index.ts"],"sourcesContent":["export const test = () => {\n console.log('asd');\n};\n","import { test } from './test';\n\ntest();\n"],"mappings":";AAAO,IAAM,OAAO,MAAM;AACxB,UAAQ,IAAI,KAAK;AACnB;;;ACAA,KAAK;","names":[]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/auth/credential-provider.ts","../src/auth/token-manager.ts","../src/http-client.ts","../src/streaming.ts","../src/resources/base-resource.ts","../src/resources/ai-gateway/index.ts","../src/resources/application-env-vars.ts","../src/resources/application-requests.ts","../src/upload/checksum.ts","../src/upload/content-type.ts","../src/upload/source.ts","../src/upload/transport.ts","../src/resources/storage-buckets.ts","../src/resources/storage-objects.ts","../src/resources/storage-upload-sessions.ts","../src/resources/application-storage.ts","../src/resources/applications.ts","../src/resources/deployments.ts","../src/resources/organization-ai-gateway.ts","../src/resources/organization-env-vars.ts","../src/resources/organizations.ts","../src/client.ts","../src/pagination.ts"],"sourcesContent":["/**\n * Base error class for all Gigadrive SDK errors. Every error thrown by the SDK\n * extends this class, so you can catch all SDK errors with a single check.\n *\n * @example\n * ```ts\n * try {\n * await client.organizations.list();\n * } catch (err) {\n * if (err instanceof GigadriveError) {\n * console.error('SDK error:', err.message);\n * }\n * }\n * ```\n */\nexport class GigadriveError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'GigadriveError';\n }\n}\n\n/**\n * Thrown when authentication fails. This includes missing or invalid credentials,\n * expired tokens, failed token refresh attempts, and failed token exchanges.\n *\n * Common causes:\n * - No credentials provided and no environment variables set\n * - Invalid `clientId`/`clientSecret` pair\n * - Expired or revoked refresh token\n * - API returned 401 even after an automatic token refresh retry\n *\n * @example\n * ```ts\n * try {\n * const client = new GigadriveClient(); // no credentials\n * } catch (err) {\n * if (err instanceof AuthenticationError) {\n * console.error('Auth failed:', err.message);\n * }\n * }\n * ```\n */\nexport class AuthenticationError extends GigadriveError {\n constructor(message: string) {\n super(message);\n this.name = 'AuthenticationError';\n }\n}\n\n/**\n * Thrown when the Gigadrive API returns a non-2xx HTTP response.\n *\n * Contains the HTTP {@link status} code and an optional machine-readable\n * {@link code} parsed from the response body.\n *\n * @example\n * ```ts\n * try {\n * await client.deployments.get('non-existent-id');\n * } catch (err) {\n * if (err instanceof ApiError) {\n * console.error(`API error ${err.status}: ${err.message}`);\n * // err.code may contain a machine-readable error code\n * }\n * }\n * ```\n */\nexport class ApiError extends GigadriveError {\n /** The HTTP status code of the failed response (e.g. 404, 500). */\n readonly status: number;\n /** An optional machine-readable error code from the API response body. */\n readonly code: string | undefined;\n\n constructor(message: string, status: number, code?: string) {\n super(message);\n this.name = 'ApiError';\n this.status = status;\n this.code = code;\n }\n}\n\n/**\n * Thrown when a file upload fails. The original cause (e.g. a network error or a\n * transport-level error from the resumable upload) is preserved on\n * {@link cause} for inspection.\n *\n * @example\n * ```ts\n * try {\n * await client.applications.storage.upload({ applicationId, bucketId, key, data });\n * } catch (err) {\n * if (err instanceof UploadError) {\n * console.error('Upload failed:', err.message, err.cause);\n * }\n * }\n * ```\n */\nexport class UploadError extends GigadriveError {\n /** The underlying error that caused the upload to fail, if any. */\n override readonly cause: unknown;\n\n constructor(message: string, cause?: unknown) {\n super(message);\n this.name = 'UploadError';\n this.cause = cause;\n }\n}\n\n/**\n * Thrown when an upload cannot complete because its session (and the short-lived\n * upload URL it was issued with) expired. Create a new upload to retry.\n *\n * The upload URL is only valid until `session.expiresAt`; very large uploads on\n * slow connections can exceed that window.\n */\nexport class UploadSessionExpiredError extends UploadError {\n constructor(\n message = 'The upload session expired before the upload completed. Start a new upload to retry.',\n cause?: unknown\n ) {\n super(message, cause);\n this.name = 'UploadSessionExpiredError';\n }\n}\n","import { AuthenticationError } from '../errors';\n\nconst DEFAULT_SCOPE = 'offline_access openid profile email';\nconst TOKEN_EXPIRY_MARGIN_SECONDS = 30;\n\n/**\n * Compute the absolute expiry (epoch ms) for a token, applying a safety margin\n * so the SDK refreshes proactively. The margin is clamped to never exceed half\n * the token lifetime, so very short-lived tokens are not treated as already\n * expired (which would refresh on every request).\n */\nconst computeExpiresAt = (expiresInSeconds: number | undefined): number => {\n const ttl = expiresInSeconds ?? 3600;\n const margin = Math.min(TOKEN_EXPIRY_MARGIN_SECONDS, ttl / 2);\n return Date.now() + (ttl - margin) * 1000;\n};\n\n/**\n * Read an environment variable safely. Returns `undefined` when `process` is\n * unavailable (e.g. browsers / some edge runtimes) instead of throwing.\n *\n * @internal\n */\nexport const readEnv = (name: string): string | undefined => {\n if (typeof process === 'undefined' || !process.env) return undefined;\n return process.env[name];\n};\n\ninterface RawTokenResponse {\n access_token: string;\n refresh_token?: string;\n expires_in?: number;\n}\n\n/**\n * Validate and normalize a token-endpoint JSON response, guarding against\n * malformed payloads that would otherwise yield `Authorization: Bearer undefined`.\n */\nconst parseTokenResponse = (payload: unknown): RawTokenResponse => {\n const data = payload as { access_token?: unknown; refresh_token?: unknown; expires_in?: unknown };\n if (typeof data.access_token !== 'string' || data.access_token.length === 0) {\n throw new AuthenticationError('Token endpoint returned no access_token');\n }\n return {\n access_token: data.access_token,\n refresh_token: typeof data.refresh_token === 'string' ? data.refresh_token : undefined,\n expires_in: typeof data.expires_in === 'number' ? data.expires_in : undefined,\n };\n};\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** The result of a credential provider's token fetch. */\nexport interface TokenResult {\n /** The access token to use in API requests. */\n accessToken: string;\n /** Epoch milliseconds when the token expires, or `null` for tokens that never expire (e.g. static bearer tokens). */\n expiresAt: number | null;\n /** A refresh token for obtaining new access tokens, if the provider supports token rotation. */\n refreshToken?: string;\n}\n\n/**\n * A strategy for obtaining access tokens. The SDK ships with four built-in\n * providers (see {@link resolveCredentialProvider} for automatic selection),\n * but you can implement this interface for custom auth flows.\n */\nexport interface CredentialProvider {\n /** A string identifying the provider type (e.g. `\"oauth2-client-credentials\"`, `\"bearer\"`). */\n readonly type: string;\n /** Fetch a new access token. May perform network requests (e.g. OAuth2 token exchange). */\n getToken(): Promise<TokenResult>;\n}\n\ninterface OidcDiscoveryDocument {\n token_endpoint?: string;\n authorization_endpoint?: string;\n userinfo_endpoint?: string;\n}\n\n// ---------------------------------------------------------------------------\n// OIDC Discovery\n// ---------------------------------------------------------------------------\n\nconst discoverOidc = async (issuerUrl: string, fetchFn: typeof globalThis.fetch): Promise<OidcDiscoveryDocument> => {\n const discoveryUrl = `${issuerUrl.replace(/\\/$/, '')}/.well-known/openid-configuration`;\n const response = await fetchFn(discoveryUrl);\n\n if (!response.ok) {\n throw new AuthenticationError(`OIDC discovery failed: ${response.status} ${response.statusText}`);\n }\n\n return (await response.json()) as OidcDiscoveryDocument;\n};\n\n// ---------------------------------------------------------------------------\n// PKCE helpers\n// ---------------------------------------------------------------------------\n\nconst base64UrlEncode = (buffer: Uint8Array): string => {\n let binary = '';\n for (let i = 0; i < buffer.byteLength; i++) {\n binary += String.fromCharCode(buffer[i]);\n }\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n};\n\nconst generatePkce = async (): Promise<{ codeVerifier: string; codeChallenge: string }> => {\n const randomBytes = new Uint8Array(64);\n crypto.getRandomValues(randomBytes);\n const codeVerifier = base64UrlEncode(randomBytes);\n\n const encoder = new TextEncoder();\n const data = encoder.encode(codeVerifier);\n const digest = await crypto.subtle.digest('SHA-256', data);\n const codeChallenge = base64UrlEncode(new Uint8Array(digest));\n\n return { codeVerifier, codeChallenge };\n};\n\nconst generateState = (): string => {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n};\n\n// ---------------------------------------------------------------------------\n// OAuth2 Client Credentials Provider (Network API keys)\n// ---------------------------------------------------------------------------\n\n/**\n * Authenticates using the OAuth2 client credentials grant. Exchanges an\n * API key (client ID + secret) for a short-lived access token via the\n * Gigadrive Network token endpoint.\n *\n * Tokens are valid for 5 minutes. A 30-second safety margin is applied so\n * the SDK refreshes proactively before the token actually expires.\n *\n * This is the most common provider for server-to-server (machine-to-machine)\n * use cases.\n */\nexport class OAuth2ClientCredentialProvider implements CredentialProvider {\n readonly type = 'oauth2-client-credentials';\n\n constructor(\n private readonly clientId: string,\n private readonly clientSecret: string,\n private readonly tokenUrl: string,\n private readonly fetchFn: typeof globalThis.fetch\n ) {}\n\n async getToken(): Promise<TokenResult> {\n const credentials = btoa(`${this.clientId}:${this.clientSecret}`);\n\n const response = await this.fetchFn(this.tokenUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Authorization: `Basic ${credentials}`,\n },\n body: new URLSearchParams({ grant_type: 'client_credentials' }).toString(),\n });\n\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n throw new AuthenticationError(`OAuth2 token request failed (${response.status}): ${body}`);\n }\n\n const data = parseTokenResponse(await response.json());\n\n return {\n accessToken: data.access_token,\n expiresAt: computeExpiresAt(data.expires_in),\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// OAuth2 Authorization Code Provider (IDP, PKCE, no local server)\n// ---------------------------------------------------------------------------\n\n/**\n * Authenticates using the OAuth2 authorization code grant with PKCE. This\n * provider is designed for interactive flows where a user authorizes the\n * application via a browser.\n *\n * The SDK generates the PKCE challenge, builds the authorization URL, and\n * passes it to your `onAuthorizationUrl` callback. Your callback is\n * responsible for presenting the URL to the user and returning the result\n * (either the full redirect URL or just the authorization code).\n *\n * The provider performs OIDC discovery to locate the authorization and token\n * endpoints automatically.\n */\nexport class OAuth2AuthorizationCodeProvider implements CredentialProvider {\n readonly type = 'oauth2-authorization-code';\n private currentRefreshToken: string | null = null;\n\n constructor(\n private readonly clientId: string,\n private readonly issuerUrl: string,\n private readonly redirectUri: string,\n private readonly onAuthorizationUrl: (url: string) => Promise<string>,\n private readonly fetchFn: typeof globalThis.fetch,\n private readonly scope: string = DEFAULT_SCOPE\n ) {}\n\n async getToken(): Promise<TokenResult> {\n const oidc = await discoverOidc(this.issuerUrl, this.fetchFn);\n\n if (!oidc.token_endpoint) {\n throw new AuthenticationError('OIDC discovery returned no token endpoint');\n }\n\n // After the first interactive exchange, refresh silently rather than\n // re-prompting the user. Only fall back to a fresh authorization when the\n // refresh token is actually rejected — transient errors are surfaced.\n if (this.currentRefreshToken) {\n const refreshed = await this.tryRefresh(oidc.token_endpoint, this.currentRefreshToken);\n if (refreshed) return refreshed;\n this.currentRefreshToken = null;\n }\n\n if (!oidc.authorization_endpoint) {\n throw new AuthenticationError('OIDC discovery returned incomplete endpoints');\n }\n\n const { codeVerifier, codeChallenge } = await generatePkce();\n const state = generateState();\n\n const authUrl = new URL(oidc.authorization_endpoint);\n authUrl.searchParams.set('client_id', this.clientId);\n authUrl.searchParams.set('redirect_uri', this.redirectUri);\n authUrl.searchParams.set('response_type', 'code');\n authUrl.searchParams.set('scope', this.scope);\n authUrl.searchParams.set('code_challenge', codeChallenge);\n authUrl.searchParams.set('code_challenge_method', 'S256');\n authUrl.searchParams.set('state', state);\n\n const result = await this.onAuthorizationUrl(authUrl.toString());\n\n // Extract the authorization code — accept either a full URL or just the code\n let code: string;\n let returnedState: string | null = null;\n\n try {\n const callbackUrl = new URL(result);\n code = callbackUrl.searchParams.get('code') ?? '';\n returnedState = callbackUrl.searchParams.get('state');\n\n const error = callbackUrl.searchParams.get('error');\n if (error) {\n const description = callbackUrl.searchParams.get('error_description') ?? error;\n throw new AuthenticationError(`Authorization failed: ${description}`);\n }\n } catch (e) {\n if (e instanceof AuthenticationError) throw e;\n // Not a valid URL — treat the entire result as the code\n code = result;\n }\n\n if (!code) {\n throw new AuthenticationError('No authorization code received');\n }\n\n if (returnedState !== null && returnedState !== state) {\n throw new AuthenticationError('State mismatch — possible CSRF attack');\n }\n\n // Exchange code for tokens\n const response = await this.fetchFn(oidc.token_endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n grant_type: 'authorization_code',\n client_id: this.clientId,\n code,\n redirect_uri: this.redirectUri,\n code_verifier: codeVerifier,\n }).toString(),\n });\n\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n throw new AuthenticationError(`Token exchange failed (${response.status}): ${body}`);\n }\n\n const data = parseTokenResponse(await response.json());\n\n this.currentRefreshToken = data.refresh_token ?? null;\n\n return {\n accessToken: data.access_token,\n expiresAt: computeExpiresAt(data.expires_in),\n refreshToken: data.refresh_token,\n };\n }\n\n /**\n * Try to exchange the stored refresh token for a new access token. Returns the\n * token on success, `null` when the refresh token is definitively rejected\n * (a 4xx — caller should re-authenticate), and throws on transient failures.\n */\n private async tryRefresh(tokenEndpoint: string, refreshToken: string): Promise<TokenResult | null> {\n const response = await this.fetchFn(tokenEndpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n grant_type: 'refresh_token',\n client_id: this.clientId,\n refresh_token: refreshToken,\n }).toString(),\n });\n\n if (!response.ok) {\n // A 4xx means the refresh token is invalid/expired — re-authenticate.\n if (response.status >= 400 && response.status < 500) return null;\n // Transient (network/5xx) failures surface instead of forcing a re-prompt.\n const body = await response.text().catch(() => '');\n throw new AuthenticationError(`Token refresh failed (${response.status}): ${body}`);\n }\n\n const data = parseTokenResponse(await response.json());\n\n if (data.refresh_token) {\n this.currentRefreshToken = data.refresh_token;\n }\n\n return {\n accessToken: data.access_token,\n expiresAt: computeExpiresAt(data.expires_in),\n refreshToken: data.refresh_token ?? this.currentRefreshToken ?? undefined,\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// OAuth2 Refresh Token Provider (IDP)\n// ---------------------------------------------------------------------------\n\n/**\n * Authenticates using an IDP refresh token. Exchanges the refresh token for\n * a short-lived access token via the IDP's token endpoint (discovered via\n * OIDC). Handles refresh-token rotation automatically — if the IDP issues\n * a new refresh token, it is stored internally for subsequent refreshes.\n *\n * This provider is typically used when a user has previously logged in\n * (e.g. via the CLI) and you have a stored refresh token.\n */\nexport class OAuth2RefreshTokenProvider implements CredentialProvider {\n readonly type = 'oauth2-refresh-token';\n private currentRefreshToken: string;\n\n constructor(\n private readonly clientId: string,\n refreshToken: string,\n private readonly issuerUrl: string,\n private readonly fetchFn: typeof globalThis.fetch\n ) {\n this.currentRefreshToken = refreshToken;\n }\n\n async getToken(): Promise<TokenResult> {\n const oidc = await discoverOidc(this.issuerUrl, this.fetchFn);\n\n if (!oidc.token_endpoint) {\n throw new AuthenticationError('OIDC discovery returned no token endpoint');\n }\n\n const response = await this.fetchFn(oidc.token_endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n grant_type: 'refresh_token',\n client_id: this.clientId,\n refresh_token: this.currentRefreshToken,\n }).toString(),\n });\n\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n if (response.status === 400) {\n throw new AuthenticationError('Refresh token is invalid or expired. Please re-authenticate.');\n }\n throw new AuthenticationError(`Token refresh failed (${response.status}): ${body}`);\n }\n\n const data = parseTokenResponse(await response.json());\n\n // Handle refresh token rotation\n if (data.refresh_token) {\n this.currentRefreshToken = data.refresh_token;\n }\n\n return {\n accessToken: data.access_token,\n expiresAt: computeExpiresAt(data.expires_in),\n refreshToken: data.refresh_token ?? this.currentRefreshToken,\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Bearer Token Provider (static)\n// ---------------------------------------------------------------------------\n\n/**\n * Uses a static, pre-obtained bearer token. The token is never refreshed —\n * if it expires, API requests will fail with an {@link AuthenticationError}.\n *\n * This is the simplest provider and is used when the caller already has a\n * valid access token (e.g. from an external auth flow or a long-lived token).\n */\nexport class BearerTokenProvider implements CredentialProvider {\n readonly type = 'bearer';\n\n constructor(private readonly token: string) {}\n\n getToken(): Promise<TokenResult> {\n return Promise.resolve({ accessToken: this.token, expiresAt: null });\n }\n}\n\n// ---------------------------------------------------------------------------\n// Credential resolution\n// ---------------------------------------------------------------------------\n\nexport interface CredentialResolverConfig {\n clientId?: string;\n clientSecret?: string;\n bearerToken?: string;\n refreshToken?: string;\n idpIssuerUrl?: string;\n onAuthorizationUrl?: (url: string) => Promise<string>;\n redirectUri?: string;\n baseUrl?: string;\n fetch?: typeof globalThis.fetch;\n /** OAuth scopes to request in the authorization-code flow (in addition to identity scopes). */\n scopes?: string[];\n}\n\nconst DEFAULT_IDP_ISSUER_URL = 'https://idp.gigadrive.de';\nconst DEFAULT_BASE_URL = 'https://api.gigadrive.network';\n\n/**\n * Resolves a `CredentialProvider` from explicit config or environment variables.\n *\n * Resolution order:\n * 1. Explicit `bearerToken` → BearerTokenProvider\n * 2. Explicit `clientId` + `clientSecret` → OAuth2ClientCredentialProvider\n * 3. Explicit `refreshToken` + `clientId` → OAuth2RefreshTokenProvider\n * 4. Explicit `onAuthorizationUrl` + `clientId` → OAuth2AuthorizationCodeProvider\n * 5. `GIGADRIVE_BEARER_TOKEN` env var → BearerTokenProvider\n * 6. `GIGADRIVE_CLIENT_ID` + `GIGADRIVE_CLIENT_SECRET` → OAuth2ClientCredentialProvider\n * 7. `GIGADRIVE_REFRESH_TOKEN` + `GIGADRIVE_CLIENT_ID` → OAuth2RefreshTokenProvider\n * 8. Throws AuthenticationError\n */\nexport const resolveCredentialProvider = (config: CredentialResolverConfig): CredentialProvider => {\n // Bind the default fetch to globalThis so calling it as `this.fetchFn(...)`\n // does not throw \"Illegal invocation\" in runtimes that require a bound receiver.\n const fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);\n const baseUrl = config.baseUrl ?? readEnv('GIGADRIVE_API_BASE_URL') ?? DEFAULT_BASE_URL;\n const idpIssuerUrl = config.idpIssuerUrl ?? readEnv('GIGADRIVE_IDP_ISSUER_URL') ?? DEFAULT_IDP_ISSUER_URL;\n const tokenUrl = `${baseUrl}/oauth2/token`;\n\n // 1. Explicit bearer token\n if (config.bearerToken) {\n return new BearerTokenProvider(config.bearerToken);\n }\n\n // 2. Explicit client credentials\n if (config.clientId && config.clientSecret) {\n return new OAuth2ClientCredentialProvider(config.clientId, config.clientSecret, tokenUrl, fetchFn);\n }\n\n // 3. Explicit refresh token\n if (config.refreshToken && config.clientId) {\n return new OAuth2RefreshTokenProvider(config.clientId, config.refreshToken, idpIssuerUrl, fetchFn);\n }\n\n // 4. Explicit authorization code callback\n if (config.onAuthorizationUrl && config.clientId) {\n const redirectUri = config.redirectUri ?? 'urn:ietf:wg:oauth:2.0:oob';\n const scope = config.scopes && config.scopes.length > 0 ? config.scopes.join(' ') : DEFAULT_SCOPE;\n return new OAuth2AuthorizationCodeProvider(\n config.clientId,\n idpIssuerUrl,\n redirectUri,\n config.onAuthorizationUrl,\n fetchFn,\n scope\n );\n }\n\n // 5. GIGADRIVE_BEARER_TOKEN env var\n const envBearerToken = readEnv('GIGADRIVE_BEARER_TOKEN');\n if (envBearerToken) {\n return new BearerTokenProvider(envBearerToken);\n }\n\n // 6. GIGADRIVE_CLIENT_ID + GIGADRIVE_CLIENT_SECRET env vars\n const envClientId = readEnv('GIGADRIVE_CLIENT_ID');\n const envClientSecret = readEnv('GIGADRIVE_CLIENT_SECRET');\n if (envClientId && envClientSecret) {\n return new OAuth2ClientCredentialProvider(envClientId, envClientSecret, tokenUrl, fetchFn);\n }\n\n // 7. GIGADRIVE_REFRESH_TOKEN + GIGADRIVE_CLIENT_ID env vars\n const envRefreshToken = readEnv('GIGADRIVE_REFRESH_TOKEN');\n if (envRefreshToken && envClientId) {\n return new OAuth2RefreshTokenProvider(envClientId, envRefreshToken, idpIssuerUrl, fetchFn);\n }\n\n // 8. No credentials found\n throw new AuthenticationError(\n 'No credentials provided. Set one of:\\n' +\n ' - GIGADRIVE_BEARER_TOKEN\\n' +\n ' - GIGADRIVE_CLIENT_ID + GIGADRIVE_CLIENT_SECRET\\n' +\n ' - GIGADRIVE_REFRESH_TOKEN + GIGADRIVE_CLIENT_ID\\n' +\n 'Or pass credentials directly to the GigadriveClient constructor.'\n );\n};\n","import type { CredentialProvider } from './credential-provider';\n\n/**\n * Manages the access-token lifecycle: caching, automatic expiry detection,\n * proactive refresh, and concurrent-call deduplication.\n *\n * When multiple API requests fire simultaneously with an expired token, only\n * a single refresh call is made — all concurrent callers await the same\n * pending Promise. This prevents a \"thundering herd\" of token requests.\n *\n * @internal Used internally by {@link HttpClient}. Not part of the public API.\n */\nexport class TokenManager {\n private cachedToken: string | null = null;\n private expiresAt: number | null = null;\n private pendingRefresh: Promise<string> | null = null;\n\n constructor(private readonly provider: CredentialProvider) {}\n\n /**\n * Returns a valid access token. Uses the cached token if still valid,\n * otherwise fetches a new one from the credential provider.\n *\n * Concurrent calls are deduplicated — only one refresh runs at a time.\n */\n async getToken(): Promise<string> {\n if (this.cachedToken && (this.expiresAt === null || Date.now() < this.expiresAt)) {\n return this.cachedToken;\n }\n\n // Deduplicate concurrent refresh calls\n if (this.pendingRefresh) {\n return this.pendingRefresh;\n }\n\n this.pendingRefresh = this.refresh();\n\n try {\n return await this.pendingRefresh;\n } finally {\n this.pendingRefresh = null;\n }\n }\n\n /**\n * Invalidates the cached token. The next `getToken()` call will trigger a refresh.\n */\n invalidate(): void {\n this.cachedToken = null;\n this.expiresAt = null;\n }\n\n private async refresh(): Promise<string> {\n const result = await this.provider.getToken();\n this.cachedToken = result.accessToken;\n this.expiresAt = result.expiresAt;\n return result.accessToken;\n }\n}\n","import type { TokenManager } from './auth/token-manager';\nimport { ApiError, AuthenticationError } from './errors';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * A paginated API response. List endpoints return this shape.\n *\n * @typeParam T - The type of each item in the list.\n */\nexport interface Paginated<T> {\n /** The items on the current page. */\n items: T[];\n /** The total number of items across all pages. */\n total: number;\n /** An opaque cursor for the next page, present on cursor-paginated endpoints when more items remain. */\n nextCursor?: string;\n}\n\n/** A value that can be serialized into a query-string parameter. `undefined` values are omitted. */\nexport type QueryValue = string | number | boolean | undefined;\n\n/** Common pagination query parameters accepted by list endpoints. */\nexport interface ListQuery {\n /** 1-indexed page number (for page/`perPage`-style pagination). */\n page?: number;\n /** Maximum number of items per page. */\n perPage?: number;\n /** Opaque cursor for cursor-based pagination (from a previous response's `nextCursor`). */\n cursor?: string;\n}\n\n/** @internal */\nexport interface RequestOptions {\n query?: Record<string, QueryValue>;\n body?: unknown;\n headers?: Record<string, string>;\n /** Abort signal to cancel the request (and any 401-refresh retry). */\n signal?: AbortSignal;\n}\n\nconst isRawBody = (body: unknown): boolean =>\n typeof body === 'string' ||\n body instanceof ArrayBuffer ||\n (typeof Uint8Array !== 'undefined' && body instanceof Uint8Array) ||\n (typeof Blob !== 'undefined' && body instanceof Blob) ||\n (typeof FormData !== 'undefined' && body instanceof FormData) ||\n (typeof ReadableStream !== 'undefined' && body instanceof ReadableStream);\n\nconst hasHeader = (headers: Record<string, string>, name: string): boolean =>\n Object.keys(headers).some((key) => key.toLowerCase() === name.toLowerCase());\n\n// ---------------------------------------------------------------------------\n// HTTP Client\n// ---------------------------------------------------------------------------\n\n/**\n * Low-level HTTP client used internally by all resource classes. Handles\n * authentication header injection, JSON serialization, error mapping, and\n * automatic retry on 401 responses.\n *\n * You do not need to use this class directly — interact with the API through\n * the resource properties on {@link GigadriveClient} instead.\n *\n * @internal\n */\nexport class HttpClient {\n constructor(\n private readonly baseUrl: string,\n private readonly tokenManager: TokenManager,\n private readonly fetchFn: typeof globalThis.fetch\n ) {}\n\n /** @internal */\n async get<T>(path: string, options?: Pick<RequestOptions, 'query' | 'signal'>): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n /** @internal */\n async post<T>(\n path: string,\n body?: unknown,\n options?: Pick<RequestOptions, 'headers' | 'query' | 'signal'>\n ): Promise<T> {\n return this.request<T>('POST', path, { body, ...options });\n }\n\n /** @internal */\n async put<T>(\n path: string,\n body?: unknown,\n options?: Pick<RequestOptions, 'headers' | 'query' | 'signal'>\n ): Promise<T> {\n return this.request<T>('PUT', path, { body, ...options });\n }\n\n /** @internal */\n async patch<T>(\n path: string,\n body?: unknown,\n options?: Pick<RequestOptions, 'headers' | 'query' | 'signal'>\n ): Promise<T> {\n return this.request<T>('PATCH', path, { body, ...options });\n }\n\n /** @internal */\n async delete<T>(path: string, options?: Pick<RequestOptions, 'query' | 'signal'>): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n /** @internal */\n async postRaw<T>(\n path: string,\n body: string | ArrayBuffer | Uint8Array | ReadableStream | Blob | FormData,\n headers?: Record<string, string>\n ): Promise<T> {\n return this.request<T>('POST', path, { body, headers });\n }\n\n /**\n * Make an authenticated request and return the raw `Response` without parsing\n * the body. Used for streamed (SSE) and binary responses.\n *\n * @throws {@link ApiError} if the response status is not OK.\n * @internal\n */\n async requestStream(method: string, path: string, options?: RequestOptions): Promise<Response> {\n const response = await this.fetchWithAuth(method, path, options);\n if (!response.ok) {\n throw await this.toApiError(response);\n }\n return response;\n }\n\n /**\n * Make a raw fetch request to an arbitrary URL (e.g. presigned upload URLs\n * or resumable upload endpoints). No auth header is injected and the base URL\n * is not prepended.\n *\n * @param url - The full URL to fetch.\n * @param init - Standard `RequestInit` options.\n * @returns The raw `Response` object.\n * @throws {@link ApiError} if the response status is not OK.\n *\n * @internal\n */\n async fetchRaw(url: string, init: RequestInit): Promise<Response> {\n const response = await this.fetchFn(url, init);\n if (!response.ok) {\n throw new ApiError(response.statusText, response.status);\n }\n return response;\n }\n\n private async request<T>(method: string, path: string, options?: RequestOptions): Promise<T> {\n const response = await this.fetchWithAuth(method, path, options);\n return this.handleResponse<T>(response);\n }\n\n /** Perform the request with auth injection and a single 401 refresh-retry. */\n private async fetchWithAuth(method: string, path: string, options?: RequestOptions): Promise<Response> {\n const url = this.buildUrl(path, options?.query);\n const token = await this.tokenManager.getToken();\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${token}`,\n ...options?.headers,\n };\n\n let requestBody: RequestInit['body'] = null;\n if (options?.body !== undefined) {\n if (isRawBody(options.body)) {\n // Raw bodies (FormData/Blob/bytes/streams) set their own Content-Type.\n requestBody = options.body as RequestInit['body'];\n } else {\n requestBody = JSON.stringify(options.body);\n if (!hasHeader(headers, 'Content-Type')) {\n headers['Content-Type'] = 'application/json';\n }\n }\n }\n\n const signal = options?.signal;\n const response = await this.fetchFn(url, { method, headers, body: requestBody, signal });\n\n // A streamed body is consumed by the first fetch and cannot be replayed, so\n // we cannot transparently retry it after a token refresh.\n const bodyIsOneShot = typeof ReadableStream !== 'undefined' && requestBody instanceof ReadableStream;\n\n // Retry once on 401 after refreshing the token.\n if (response.status === 401 && !bodyIsOneShot) {\n this.tokenManager.invalidate();\n const retryToken = await this.tokenManager.getToken();\n headers.Authorization = `Bearer ${retryToken}`;\n\n const retryResponse = await this.fetchFn(url, { method, headers, body: requestBody, signal });\n if (retryResponse.status === 401) {\n throw new AuthenticationError('Authentication failed after token refresh');\n }\n return retryResponse;\n }\n\n return response;\n }\n\n private async handleResponse<T>(response: Response): Promise<T> {\n if (response.ok) {\n // Handle empty responses (204 No Content, or responses with no body)\n if (response.status === 204) {\n return undefined as T;\n }\n\n const text = await response.text();\n if (!text) {\n return undefined as T;\n }\n\n return JSON.parse(text) as T;\n }\n\n throw await this.toApiError(response);\n }\n\n private async toApiError(response: Response): Promise<ApiError> {\n let message: string;\n let code: string | undefined;\n\n try {\n const body = (await response.json()) as { error?: string | { message?: string; code?: string } };\n if (typeof body.error === 'string') {\n message = body.error;\n } else if (body.error && typeof body.error === 'object') {\n message = body.error.message ?? response.statusText;\n code = body.error.code;\n } else {\n message = response.statusText;\n }\n } catch {\n message = response.statusText;\n }\n\n return new ApiError(message, response.status, code);\n }\n\n private buildUrl(path: string, query?: Record<string, QueryValue>): string {\n const url = `${this.baseUrl}${path}`;\n\n if (!query) return url;\n\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) {\n params.set(key, String(value));\n }\n }\n\n const qs = params.toString();\n return qs ? `${url}?${qs}` : url;\n }\n}\n","/**\n * Server-Sent Events (SSE) parsing for streamed API responses (e.g. streamed\n * chat completions). Works in browsers and Node.js 18+ where `Response.body` is\n * a web `ReadableStream`.\n *\n * @internal\n */\n\n/** Extract and concatenate the `data:` payload(s) from a single SSE event block. */\nconst extractData = (rawEvent: string): string | null => {\n const dataLines = rawEvent\n .split('\\n')\n .filter((line) => line.startsWith('data:'))\n .map((line) => line.slice('data:'.length).replace(/^ /, ''));\n if (dataLines.length === 0) return null;\n const joined = dataLines.join('\\n');\n // Treat whitespace-only events (e.g. keep-alive comments or a truncated final\n // \"data:\" line) as \"no data\" so we never call JSON.parse on an empty string.\n return joined.trim().length === 0 ? null : joined;\n};\n\nconst parseEvent = <T>(data: string): T => {\n try {\n return JSON.parse(data) as T;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to parse streamed SSE data as JSON: ${message}`);\n }\n};\n\n/**\n * Parse an SSE stream, yielding each event's `data` payload parsed as JSON.\n * The `[DONE]` sentinel and empty keep-alive events are skipped; iteration ends\n * when the underlying stream closes.\n *\n * @typeParam T - The shape of each streamed JSON chunk.\n * @param response - A streaming `fetch` response.\n */\nexport async function* parseSSEStream<T = unknown>(response: Response): AsyncGenerator<T> {\n const body = response.body as ReadableStream<Uint8Array> | null;\n if (!body) {\n throw new Error('The response has no readable body to stream.');\n }\n\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n\n const drain = function* (flush: boolean): Generator<T> {\n // SSE events are separated by a blank line; CRLF is normalised on read.\n let separator = buffer.indexOf('\\n\\n');\n while (separator !== -1) {\n const rawEvent = buffer.slice(0, separator);\n buffer = buffer.slice(separator + 2);\n const data = extractData(rawEvent);\n if (data !== null && data !== '[DONE]') {\n yield parseEvent<T>(data);\n }\n separator = buffer.indexOf('\\n\\n');\n }\n if (flush) {\n const data = extractData(buffer);\n buffer = '';\n if (data !== null && data !== '[DONE]') {\n yield parseEvent<T>(data);\n }\n }\n };\n\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n // Normalise CRLF on the whole buffer so a separator split across two reads\n // (a trailing \"\\r\" then a leading \"\\n\") is still collapsed correctly.\n buffer = (buffer + decoder.decode(value, { stream: true })).replace(/\\r\\n/g, '\\n');\n yield* drain(false);\n }\n yield* drain(true);\n } finally {\n // Cancel (not just release the lock) so breaking out of the consumer's\n // `for await` early stops the underlying HTTP body instead of leaking it.\n await reader.cancel().catch(() => undefined);\n }\n}\n","import type { HttpClient } from '../http-client';\n\n/**\n * Base class for all API resource classes. Provides access to the shared\n * HTTP client for making authenticated API requests.\n *\n * @internal\n */\nexport class BaseResource {\n constructor(protected readonly httpClient: HttpClient) {}\n}\n","import type { HttpClient, Paginated } from '../../http-client';\nimport { parseSSEStream } from '../../streaming';\nimport { BaseResource } from '../base-resource';\nimport type {\n AiModel,\n ChatCompletionChunk,\n ChatCompletionRequest,\n ChatCompletionResponse,\n GatewayRequestOptions,\n GatewayResult,\n ResponsesRequest,\n ResponsesResponse,\n SpeechRequest,\n TranscriptionRequest,\n TranscriptionResponse,\n VideoGenerationRequest,\n VideoGenerationResponse,\n VideoModelList,\n} from './types';\n\nexport type * from './types';\n\nconst BASE = '/ai/v1';\n\nconst toBlob = (file: Blob | Uint8Array | ArrayBuffer): Blob => {\n if (file instanceof Uint8Array) return new Blob([file]);\n if (typeof Blob !== 'undefined' && file instanceof Blob) return file;\n return new Blob([new Uint8Array(file as ArrayBuffer)]);\n};\n\n/** Text-to-speech and speech-to-text endpoints. */\nexport class AiGatewayAudioResource extends BaseResource {\n /**\n * Synthesize speech from text. Returns the raw audio bytes.\n *\n * @returns The audio content as an `ArrayBuffer` (format per `response_format`).\n */\n async speech(data: SpeechRequest, options?: GatewayRequestOptions): Promise<ArrayBuffer> {\n const response = await this.httpClient.requestStream('POST', `${BASE}/audio/speech`, {\n body: data,\n headers: options?.headers,\n });\n return response.arrayBuffer();\n }\n\n /**\n * Transcribe an audio file to text. The file is sent as multipart form data.\n */\n async transcriptions(data: TranscriptionRequest, options?: GatewayRequestOptions): Promise<TranscriptionResponse> {\n const form = new FormData();\n const { file, filename, ...rest } = data;\n form.set('file', toBlob(file), filename ?? 'audio');\n for (const [key, value] of Object.entries(rest)) {\n if (value === undefined || value === null) continue;\n form.set(key, typeof value === 'object' ? JSON.stringify(value) : String(value as string | number | boolean));\n }\n return this.httpClient.postRaw(`${BASE}/audio/transcriptions`, form, options?.headers);\n }\n}\n\n/** Video generation endpoints. */\nexport class AiGatewayVideosResource extends BaseResource {\n /** Generate a video from a prompt. */\n async generations(data: VideoGenerationRequest, options?: GatewayRequestOptions): Promise<VideoGenerationResponse> {\n return this.httpClient.post(`${BASE}/videos`, data, { headers: options?.headers });\n }\n\n /** List the video models available through the gateway. */\n async listModels(): Promise<VideoModelList> {\n return this.httpClient.get(`${BASE}/videos/models`);\n }\n}\n\n/**\n * Interact with the Gigadrive AI Gateway — an OpenAI-compatible API that routes\n * requests to multiple AI providers. Accessed via {@link GigadriveClient.aiGateway}.\n *\n * @example\n * ```ts\n * // Chat completion\n * const res = await client.aiGateway.chatCompletions({\n * model: 'openai/gpt-4o',\n * messages: [{ role: 'user', content: 'Hello!' }],\n * });\n * console.log(res.choices[0].message.content);\n *\n * // Streamed chat completion\n * for await (const chunk of client.aiGateway.chatCompletionsStream({\n * model: 'openai/gpt-4o',\n * messages: [{ role: 'user', content: 'Write a haiku.' }],\n * })) {\n * process.stdout.write(chunk.choices[0]?.delta.content ?? '');\n * }\n * ```\n */\nexport class AiGatewayResource extends BaseResource {\n /** Text-to-speech and speech-to-text. */\n readonly audio: AiGatewayAudioResource;\n /** Video generation. */\n readonly videos: AiGatewayVideosResource;\n\n constructor(httpClient: HttpClient) {\n super(httpClient);\n this.audio = new AiGatewayAudioResource(httpClient);\n this.videos = new AiGatewayVideosResource(httpClient);\n }\n\n /**\n * Create a chat completion using the OpenAI-compatible endpoint.\n *\n * @param data - The chat completion request (model, messages, options, provider routing).\n * @param options - Custom headers (e.g. `X-Gigadrive-Application-Id`).\n */\n async chatCompletions(data: ChatCompletionRequest, options?: GatewayRequestOptions): Promise<ChatCompletionResponse> {\n return this.httpClient.post(`${BASE}/chat/completions`, { ...data, stream: false }, { headers: options?.headers });\n }\n\n /**\n * Like {@link chatCompletions}, but also returns the raw response and the\n * gateway request-id / cost headers.\n */\n async chatCompletionsWithResponse(\n data: ChatCompletionRequest,\n options?: GatewayRequestOptions\n ): Promise<GatewayResult<ChatCompletionResponse>> {\n const response = await this.httpClient.requestStream('POST', `${BASE}/chat/completions`, {\n body: { ...data, stream: false },\n headers: options?.headers,\n });\n const body = (await response.json()) as ChatCompletionResponse;\n const cost = response.headers.get('X-Gigadrive-Cost-Micros');\n const costMicros = cost !== null ? Number(cost) : NaN;\n return {\n data: body,\n response,\n requestId: response.headers.get('X-Gigadrive-Request-Id') ?? undefined,\n costMicros: Number.isFinite(costMicros) ? costMicros : undefined,\n };\n }\n\n /**\n * Stream a chat completion as Server-Sent Events. Yields each chunk as it\n * arrives and ends when the gateway closes the stream.\n */\n async *chatCompletionsStream(\n data: ChatCompletionRequest,\n options?: GatewayRequestOptions\n ): AsyncGenerator<ChatCompletionChunk> {\n const response = await this.httpClient.requestStream('POST', `${BASE}/chat/completions`, {\n body: { ...data, stream: true },\n headers: options?.headers,\n });\n yield* parseSSEStream<ChatCompletionChunk>(response);\n }\n\n /**\n * Create a response using the Open Responses-compatible endpoint.\n */\n async responses(data: ResponsesRequest, options?: GatewayRequestOptions): Promise<ResponsesResponse> {\n return this.httpClient.post(`${BASE}/responses`, { ...data, stream: false }, { headers: options?.headers });\n }\n\n /**\n * Stream a response using the Open Responses-compatible endpoint.\n */\n async *responsesStream(data: ResponsesRequest, options?: GatewayRequestOptions): AsyncGenerator<unknown> {\n const response = await this.httpClient.requestStream('POST', `${BASE}/responses`, {\n body: { ...data, stream: true },\n headers: options?.headers,\n });\n yield* parseSSEStream(response);\n }\n\n /**\n * List all AI models available through the gateway.\n */\n async listModels(): Promise<Paginated<AiModel>> {\n return this.httpClient.get(`${BASE}/models`);\n }\n\n /**\n * Get details for a specific AI model by its ID.\n *\n * @param modelId - The model identifier (e.g. `\"openai/gpt-4o\"`).\n */\n async getModel(modelId: string): Promise<AiModel> {\n return this.httpClient.get(`${BASE}/models/${encodeURIComponent(modelId)}`);\n }\n}\n","import type { ListQuery, Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\nimport type { CreateEnvVarInput, EnvVar, UpdateEnvVarInput } from './env-vars';\n\n/**\n * Manage environment variables scoped to an application.\n * Accessed via `client.applications.envVars`.\n */\nexport class ApplicationEnvVarsResource extends BaseResource {\n /**\n * List all environment variables for an application.\n *\n * @param applicationId - The application ID (UUID).\n * @returns A paginated list of environment variables.\n *\n * @example\n * ```ts\n * const { items } = await client.applications.envVars.list('app-id');\n * for (const v of items) {\n * console.log(`${v.key}=${v.sensitive ? '***' : v.value}`);\n * }\n * ```\n */\n async list(applicationId: string, query?: ListQuery): Promise<Paginated<EnvVar>> {\n return this.httpClient.get(`/applications/${applicationId}/env-vars`, {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /**\n * Create a new environment variable for an application.\n *\n * @param applicationId - The application ID (UUID).\n * @param data - The variable key, value, and optional settings.\n * @returns The newly created environment variable.\n *\n * @example\n * ```ts\n * const envVar = await client.applications.envVars.create('app-id', {\n * key: 'DATABASE_URL',\n * value: 'postgres://...',\n * sensitive: true,\n * });\n * ```\n */\n async create(applicationId: string, data: CreateEnvVarInput): Promise<EnvVar> {\n return this.httpClient.post(`/applications/${applicationId}/env-vars`, data);\n }\n\n /**\n * Update an existing environment variable. Only the fields you provide\n * will be changed; omitted fields are left unchanged.\n *\n * @param applicationId - The application ID (UUID).\n * @param envVarId - The environment variable ID (UUID).\n * @param data - The fields to update.\n * @returns The updated environment variable.\n *\n * @example\n * ```ts\n * await client.applications.envVars.update('app-id', 'var-id', {\n * value: 'postgres://new-host/db',\n * });\n * ```\n */\n async update(applicationId: string, envVarId: string, data: UpdateEnvVarInput): Promise<EnvVar> {\n return this.httpClient.patch(`/applications/${applicationId}/env-vars/${envVarId}`, data);\n }\n\n /**\n * Permanently delete an environment variable.\n *\n * @param applicationId - The application ID (UUID).\n * @param envVarId - The environment variable ID (UUID).\n *\n * @example\n * ```ts\n * await client.applications.envVars.delete('app-id', 'var-id');\n * ```\n */\n async delete(applicationId: string, envVarId: string): Promise<void> {\n return this.httpClient.delete(`/applications/${applicationId}/env-vars/${envVarId}`);\n }\n}\n","import type { Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\n\n/** A nested reference to the application that served a request. */\nexport interface NetworkRequestApplicationRef {\n id: string;\n name: string;\n}\n\n/** A nested reference to the deployment that served a request. */\nexport interface NetworkRequestDeploymentRef {\n id: string;\n status: string;\n}\n\n/** A nested reference to the function route that handled a request. */\nexport interface NetworkRequestFunctionRef {\n id: string;\n name: string | null;\n path: string;\n region: string | null;\n}\n\n/** A nested reference to the static asset that served a request. */\nexport interface NetworkRequestAssetRef {\n id: string;\n path: string;\n objectKey: string;\n}\n\n/** A nested reference to the storage bucket involved in a request. */\nexport interface NetworkRequestBucketRef {\n id: string;\n name: string;\n slug: string;\n}\n\n/** A nested reference to the storage object involved in a request. */\nexport interface NetworkRequestObjectRef {\n id: string;\n key: string;\n contentType: string | null;\n}\n\n/** The HTTP request details captured for a network request. */\nexport interface NetworkRequestDetails {\n method: string;\n hostname: string;\n path: string;\n query: string | null;\n protocol: string | null;\n country: string | null;\n userAgent: string | null;\n referer: string | null;\n}\n\n/** The HTTP response details captured for a network request. */\nexport interface NetworkResponseDetails {\n status: number | null;\n cacheStatus: 'hit' | 'miss' | 'bypass' | 'revalidated' | 'stale' | 'updating' | null;\n cacheHit: boolean | null;\n region: string | null;\n edgeLocation: string | null;\n}\n\n/** Byte and timing metrics for a network request. */\nexport interface NetworkRequestMetrics {\n requestBodyBytes: number | null;\n responseBodyBytes: number | null;\n bytesSent: number | null;\n durationMs: number | null;\n}\n\n/** A single observed request served through the Gigadrive Network edge (summary form). */\nexport interface NetworkRequestSummary {\n id: string;\n application: NetworkRequestApplicationRef;\n deployment: NetworkRequestDeploymentRef | null;\n deploymentFunction: NetworkRequestFunctionRef | null;\n deploymentAsset: NetworkRequestAssetRef | null;\n storageBucket: NetworkRequestBucketRef | null;\n storageObject: NetworkRequestObjectRef | null;\n request: NetworkRequestDetails;\n response: NetworkResponseDetails;\n metrics: NetworkRequestMetrics;\n startedAt: string;\n completedAt: string | null;\n}\n\n/** A full network request record, including sanitized request/response headers. */\nexport interface NetworkRequest extends NetworkRequestSummary {\n /** Sanitized request headers captured for debugging. */\n requestHeaders: Record<string, string>;\n /** Sanitized response headers captured for debugging. */\n responseHeaders: Record<string, string>;\n}\n\n/** Query filters for listing application requests. All fields are optional. */\nexport interface ListRequestsQuery {\n /** Filter to requests served by one deployment. */\n deploymentId?: string;\n /** Filter to requests served by one function route. */\n deploymentFunctionId?: string;\n /** Filter to requests served by one static asset route. */\n deploymentAssetId?: string;\n /** Filter to storage delivery requests for one bucket. */\n storageBucketId?: string;\n /** Filter to storage delivery requests for one object. */\n storageObjectId?: string;\n /** Only include requests that started at or after this ISO 8601 timestamp. */\n from?: string;\n /** Only include requests that started before or at this ISO 8601 timestamp. */\n to?: string;\n /** Maximum number of records to return. */\n limit?: number;\n /** Opaque cursor from a previous response's `nextCursor`. */\n cursor?: string;\n /** Filter by HTTP method (e.g. `\"GET\"`). */\n method?: string;\n /** Filter by exact HTTP status code. */\n status?: number;\n /** Filter by status family (`2`, `3`, `4`, or `5`). */\n statusFamily?: number;\n /** Filter by request hostname. */\n hostname?: string;\n /** Filter to requests whose path starts with this prefix. */\n pathPrefix?: string;\n /** Filter by ISO 3166-1 alpha-2 country code. */\n country?: string;\n /** Filter by origin region. */\n region?: string;\n /** Filter by edge location. */\n edgeLocation?: string;\n /** Filter by CDN cache state. */\n cacheStatus?: string;\n /** Filter by whether the response was served from cache. */\n cacheHit?: boolean;\n}\n\n/**\n * Read observed traffic (request logs) for an application. Accessed via\n * `client.applications.requests`.\n *\n * @example\n * ```ts\n * // Recent 5xx responses for a deployment\n * const { items } = await client.applications.requests.list('app-id', {\n * deploymentId: 'dep-id',\n * statusFamily: 5,\n * limit: 100,\n * });\n * ```\n */\nexport class ApplicationRequestsResource extends BaseResource {\n /**\n * List requests for an application, with rich filtering and cursor pagination.\n *\n * @param applicationId - The application ID (UUID).\n * @param query - Optional filters and pagination.\n * @returns A page of request summaries.\n */\n async list(applicationId: string, query?: ListRequestsQuery): Promise<Paginated<NetworkRequestSummary>> {\n return this.httpClient.get(`/applications/${applicationId}/requests`, {\n query: query as Record<string, string | number | boolean | undefined> | undefined,\n });\n }\n\n /**\n * Get a single request by ID, including sanitized request/response headers.\n *\n * @param applicationId - The application ID (UUID).\n * @param requestId - The request record ID (UUID).\n * @returns The full request record.\n */\n async get(applicationId: string, requestId: string): Promise<NetworkRequest> {\n return this.httpClient.get(`/applications/${applicationId}/requests/${requestId}`);\n }\n}\n","/**\n * Checksum helpers used to satisfy the storage upload contract, which requires\n * a SHA-256 of the object content (SHA-1 and MD5 are optional integrity hints).\n *\n * SHA-256 and SHA-1 are computed with the Web Crypto API (`crypto.subtle`),\n * which is available in modern browsers and Node.js 18+. MD5 is not provided by\n * Web Crypto, so it is computed with Node's `crypto` module and is therefore\n * Node-only — pass `checksumMd5` explicitly if you need it in the browser.\n *\n * @internal\n */\n\n/** A set of computed content checksums (lowercase hex). */\nexport interface Checksums {\n /** SHA-256 checksum. Always computed. */\n sha256: string;\n /** SHA-1 checksum, when requested. */\n sha1?: string;\n /** MD5 checksum, when requested (Node.js only). */\n md5?: string;\n}\n\n/** Which optional checksums to compute alongside the always-required SHA-256. */\nexport interface ChecksumRequest {\n /** Also compute a SHA-1 checksum. */\n sha1?: boolean;\n /** Also compute an MD5 checksum (Node.js only). */\n md5?: boolean;\n}\n\nconst toHex = (buffer: ArrayBuffer): string => {\n const bytes = new Uint8Array(buffer);\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += bytes[i].toString(16).padStart(2, '0');\n }\n return hex;\n};\n\nconst subtleDigest = async (algorithm: 'SHA-256' | 'SHA-1', bytes: Uint8Array): Promise<string> =>\n toHex(await crypto.subtle.digest(algorithm, bytes));\n\nconst importNodeCrypto = async (): Promise<typeof import('node:crypto') | null> => {\n if (typeof process === 'undefined' || !process.versions?.node) return null;\n try {\n return await import('node:crypto');\n } catch {\n return null;\n }\n};\n\nconst md5Hex = async (bytes: Uint8Array): Promise<string> => {\n const nodeCrypto = await importNodeCrypto();\n if (!nodeCrypto) {\n throw new Error('MD5 checksums are only supported in Node.js. Provide checksumMd5 explicitly in the browser.');\n }\n return nodeCrypto.createHash('md5').update(bytes).digest('hex');\n};\n\n/**\n * Compute checksums for an in-memory byte buffer.\n *\n * @param bytes - The content bytes.\n * @param request - Which optional checksums to compute (SHA-256 is always computed).\n */\nexport const computeChecksums = async (bytes: Uint8Array, request: ChecksumRequest = {}): Promise<Checksums> => {\n const checksums: Checksums = { sha256: await subtleDigest('SHA-256', bytes) };\n if (request.sha1) checksums.sha1 = await subtleDigest('SHA-1', bytes);\n if (request.md5) checksums.md5 = await md5Hex(bytes);\n return checksums;\n};\n\n/**\n * Compute checksums for a file on disk by streaming it through Node's hashing\n * primitives — avoids loading the whole file into memory. Node.js only.\n *\n * @param path - Filesystem path to hash.\n * @param request - Which optional checksums to compute (SHA-256 is always computed).\n */\nexport const hashNodeFile = async (path: string, request: ChecksumRequest = {}): Promise<Checksums> => {\n const [fs, nodeCrypto] = await Promise.all([import('node:fs'), import('node:crypto')]);\n const sha256 = nodeCrypto.createHash('sha256');\n const sha1 = request.sha1 ? nodeCrypto.createHash('sha1') : null;\n const md5 = request.md5 ? nodeCrypto.createHash('md5') : null;\n\n await new Promise<void>((resolve, reject) => {\n const stream = fs.createReadStream(path);\n stream.on('data', (chunk) => {\n sha256.update(chunk);\n sha1?.update(chunk);\n md5?.update(chunk);\n });\n stream.on('end', () => resolve());\n stream.on('error', reject);\n });\n\n const checksums: Checksums = { sha256: sha256.digest('hex') };\n if (sha1) checksums.sha1 = sha1.digest('hex');\n if (md5) checksums.md5 = md5.digest('hex');\n return checksums;\n};\n","/**\n * Minimal filename → MIME type inference used to populate an upload's content\n * type when the caller does not provide one. Intentionally dependency-free and\n * covers the most common web/asset types; callers can always pass an explicit\n * `contentType` to override.\n *\n * @internal\n */\n\nconst MIME_TYPES: Record<string, string> = {\n // Text & code\n txt: 'text/plain',\n csv: 'text/csv',\n html: 'text/html',\n htm: 'text/html',\n css: 'text/css',\n js: 'text/javascript',\n mjs: 'text/javascript',\n json: 'application/json',\n xml: 'application/xml',\n md: 'text/markdown',\n // Images\n png: 'image/png',\n jpg: 'image/jpeg',\n jpeg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp',\n svg: 'image/svg+xml',\n avif: 'image/avif',\n ico: 'image/x-icon',\n bmp: 'image/bmp',\n tiff: 'image/tiff',\n heic: 'image/heic',\n // Audio\n mp3: 'audio/mpeg',\n wav: 'audio/wav',\n ogg: 'audio/ogg',\n oga: 'audio/ogg',\n flac: 'audio/flac',\n aac: 'audio/aac',\n m4a: 'audio/mp4',\n // Video\n mp4: 'video/mp4',\n webm: 'video/webm',\n mov: 'video/quicktime',\n avi: 'video/x-msvideo',\n mkv: 'video/x-matroska',\n // Documents\n pdf: 'application/pdf',\n doc: 'application/msword',\n docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n xls: 'application/vnd.ms-excel',\n xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n ppt: 'application/vnd.ms-powerpoint',\n pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n // Archives & binaries\n zip: 'application/zip',\n gz: 'application/gzip',\n tar: 'application/x-tar',\n br: 'application/x-brotli',\n wasm: 'application/wasm',\n // Fonts\n woff: 'font/woff',\n woff2: 'font/woff2',\n ttf: 'font/ttf',\n otf: 'font/otf',\n};\n\n/**\n * Infer a MIME type from a filename or object key by its extension.\n *\n * @param nameOrKey - A filename or object key (e.g. `\"images/photo.jpg\"`).\n * @returns The inferred MIME type, or `undefined` if the extension is unknown.\n */\nexport const inferContentType = (nameOrKey: string): string | undefined => {\n const lastDot = nameOrKey.lastIndexOf('.');\n if (lastDot === -1 || lastDot === nameOrKey.length - 1) return undefined;\n const ext = nameOrKey.slice(lastDot + 1).toLowerCase();\n return MIME_TYPES[ext];\n};\n","/**\n * Resolves the various accepted upload inputs (in-memory bytes, a Node.js file\n * path, or a Node.js readable stream) into the concrete values the upload flow\n * needs: the object tus-js-client consumes, the byte size, an inferred content\n * type, and the required checksums.\n *\n * @internal\n */\n\nimport { computeChecksums, hashNodeFile, type Checksums } from './checksum';\nimport { inferContentType } from './content-type';\n\n/** A minimal Node.js `Readable`-like shape (avoids depending on `node:stream` types). */\nexport interface NodeReadableLike {\n on(event: string, listener: (...args: unknown[]) => void): unknown;\n pipe?: unknown;\n read?: unknown;\n}\n\n/** In-memory data accepted by the upload helpers. `Buffer` is a `Uint8Array`. */\nexport type UploadData = Blob | ArrayBuffer | Uint8Array;\n\n/** The tus-js-client file input union. */\nexport type TusFile = File | Blob | Uint8Array | NodeReadableLike;\n\n/** Input describing what to upload and any pre-supplied metadata. */\nexport interface UploadSourceInput {\n /** The object key/path the upload targets — used to infer content type. */\n key: string;\n /** In-memory data (browser `File`/`Blob`, Node `Buffer`, `Uint8Array`, `ArrayBuffer`). */\n data?: UploadData;\n /** A filesystem path to stream from (Node.js only). */\n path?: string;\n /** A readable stream (Node.js only). Requires `contentLength` and `checksumSha256`. */\n stream?: NodeReadableLike;\n /** Explicit content type. Inferred from `key` when omitted. */\n contentType?: string;\n /** Explicit byte size. Required for `stream`; computed otherwise. */\n contentLength?: number;\n /** Pre-computed SHA-256 (skips hashing). Required for `stream`. */\n checksumSha256?: string;\n /** Pre-computed SHA-1. */\n checksumSha1?: string;\n /** Pre-computed MD5. */\n checksumMd5?: string;\n}\n\n/** The fully resolved upload source. */\nexport interface ResolvedUploadSource {\n /** The value handed to tus-js-client. */\n tusFile: TusFile;\n /** Total upload size in bytes. */\n size: number;\n /** Resolved content type, if known. */\n contentType?: string;\n /** Checksums (always includes SHA-256). */\n checksums: Checksums;\n /** Whether a finite chunk size is required (true for streamed/file-path inputs). */\n requiresFiniteChunkSize: boolean;\n}\n\nconst isNode = (): boolean => typeof process !== 'undefined' && !!process.versions?.node;\n\nconst toBytes = async (data: UploadData): Promise<Uint8Array> => {\n if (typeof Blob !== 'undefined' && data instanceof Blob) return new Uint8Array(await data.arrayBuffer());\n if (data instanceof Uint8Array) return data;\n if (data instanceof ArrayBuffer) return new Uint8Array(data);\n throw new Error('Unsupported upload data type. Pass a File, Blob, Buffer, Uint8Array, or ArrayBuffer.');\n};\n\nconst sizeOf = (data: UploadData): number => {\n if (typeof Blob !== 'undefined' && data instanceof Blob) return data.size;\n if (data instanceof Uint8Array) return data.byteLength;\n if (data instanceof ArrayBuffer) return data.byteLength;\n throw new Error('Cannot determine upload size. Pass a File, Blob, Buffer, Uint8Array, or ArrayBuffer.');\n};\n\n/** Convert in-memory data into a value tus-js-client accepts in the current runtime. */\nconst toTusFile = (data: UploadData): TusFile => {\n // Node accepts Buffer/Uint8Array directly; browsers are happiest with a Blob.\n if (data instanceof Uint8Array) return isNode() ? data : new Blob([data]);\n if (typeof Blob !== 'undefined' && data instanceof Blob) return data;\n const bytes = new Uint8Array(data as ArrayBuffer);\n return isNode() ? bytes : new Blob([bytes]);\n};\n\n/**\n * Build the checksum set, always honoring caller-supplied SHA-1/MD5 (they are\n * passed through, never recomputed). Only SHA-256 is ever computed by the SDK.\n */\nconst buildChecksums = (input: UploadSourceInput, sha256: string): Checksums => {\n const checksums: Checksums = { sha256 };\n if (input.checksumSha1) checksums.sha1 = input.checksumSha1;\n if (input.checksumMd5) checksums.md5 = input.checksumMd5;\n return checksums;\n};\n\n/**\n * Resolve an {@link UploadSourceInput} into a {@link ResolvedUploadSource},\n * computing size, content type, and the SHA-256 as needed.\n *\n * @param input - The upload source description. Exactly one of `data`, `path`,\n * or `stream` must be provided.\n * @param options - Set `hash: false` to skip SHA-256 computation (e.g. when\n * uploading to an already-authorized URL, where checksums are not needed).\n */\nexport const resolveUploadSource = async (\n input: UploadSourceInput,\n options: { hash?: boolean } = {}\n): Promise<ResolvedUploadSource> => {\n const sourceCount = [input.data !== undefined, input.path !== undefined, input.stream !== undefined].filter(\n Boolean\n ).length;\n if (sourceCount > 1) {\n throw new Error('Provide only one upload source: data, path, or stream.');\n }\n\n const hash = options.hash !== false;\n const contentType = input.contentType ?? inferContentType(input.key);\n\n if (input.data !== undefined) {\n const size = input.contentLength ?? sizeOf(input.data);\n const sha256 = input.checksumSha256 ?? (hash ? (await computeChecksums(await toBytes(input.data))).sha256 : '');\n return {\n tusFile: toTusFile(input.data),\n size,\n contentType,\n checksums: buildChecksums(input, sha256),\n requiresFiniteChunkSize: false,\n };\n }\n\n if (input.path !== undefined) {\n if (!isNode()) throw new Error('Uploading from a file path is only supported in Node.js.');\n const fs = await import('node:fs');\n const size = input.contentLength ?? fs.statSync(input.path).size;\n const sha256 = input.checksumSha256 ?? (hash ? (await hashNodeFile(input.path)).sha256 : '');\n // A fresh read stream is handed to tus for the byte upload.\n const tusFile = fs.createReadStream(input.path) as unknown as NodeReadableLike;\n return { tusFile, size, contentType, checksums: buildChecksums(input, sha256), requiresFiniteChunkSize: true };\n }\n\n if (input.stream !== undefined) {\n if (input.contentLength === undefined) {\n throw new Error('Uploading from a stream requires contentLength to be provided.');\n }\n if (hash && !input.checksumSha256) {\n throw new Error('Uploading from a stream requires checksumSha256 to be provided.');\n }\n return {\n tusFile: input.stream,\n size: input.contentLength,\n contentType,\n checksums: buildChecksums(input, input.checksumSha256 ?? ''),\n requiresFiniteChunkSize: true,\n };\n }\n\n throw new Error('No upload source provided. Pass one of: data, path, or stream.');\n};\n","/**\n * Thin, injectable wrapper around `tus-js-client` that performs the resumable\n * byte upload. Isolated here so the upload flow can be unit-tested with a fake\n * transport (no real network I/O) and so abort/resume behaviour lives in one\n * place.\n *\n * @internal\n */\n\nimport * as tus from 'tus-js-client';\nimport { UploadError, UploadSessionExpiredError } from '../errors';\nimport type { ResolvedUploadSource, TusFile } from './source';\n\n/** Default chunk size for streamed/file-path uploads, which require a finite chunk size. */\nexport const DEFAULT_STREAM_CHUNK_SIZE = 50 * 1024 * 1024;\n\n/** A persistence backend for resumable upload fingerprints (matches tus-js-client's `UrlStorage`). */\nexport interface UploadUrlStorage {\n findAllUploads(): Promise<unknown[]>;\n findUploadsByFingerprint(fingerprint: string): Promise<unknown[]>;\n removeUpload(urlStorageKey: string): Promise<void>;\n addUpload(fingerprint: string, upload: unknown): Promise<string>;\n}\n\n/** Parameters for a single byte upload. */\nexport interface TusUploadParams {\n /** The file/data passed to tus-js-client. */\n data: TusFile;\n /** Signed upload URL (already includes the short-lived upload token). */\n uploadUrl: string;\n /** Total upload size in bytes. */\n uploadSize: number;\n /** Headers to send with each request (must include `Tus-Resumable`). */\n headers: Record<string, string>;\n /** Maximum chunk size in bytes. Required for streamed inputs. */\n chunkSize?: number;\n /** Retry backoff in milliseconds. `null`/`[]` disables retries. */\n retryDelays?: number[] | null;\n /** Progress callback. */\n onProgress?: (bytesSent: number, bytesTotal: number) => void;\n /** Abort signal to cancel the upload. */\n signal?: AbortSignal;\n /** Persist a resumable fingerprint so the upload can resume later. */\n resume?: boolean;\n /** Custom storage for resumable fingerprints (defaults to the tus-js-client default for the runtime). */\n urlStorage?: UploadUrlStorage;\n}\n\n/** Performs a single resumable byte upload. Resolves on success, rejects on error/abort. */\nexport type UploadTransport = (params: TusUploadParams) => Promise<void>;\n\nconst DEFAULT_RETRY_DELAYS = [0, 1000, 3000, 5000];\n\n/** An `AbortError`-named error, consistent with the Fetch/DOM cancellation convention. */\nexport const createAbortError = (): Error => {\n const error = new Error('The upload was aborted.');\n error.name = 'AbortError';\n return error;\n};\n\n/** The default upload transport, backed by `tus-js-client`. */\nexport const tusUploadTransport: UploadTransport = (params) =>\n new Promise<void>((resolve, reject) => {\n if (params.signal?.aborted) {\n reject(createAbortError());\n return;\n }\n\n let settled = false;\n const cleanup = () => {\n if (params.signal) params.signal.removeEventListener('abort', onAbort);\n };\n const finish = (fn: () => void) => {\n if (settled) return;\n settled = true;\n cleanup();\n fn();\n };\n\n const upload = new tus.Upload(params.data as tus.Upload['file'], {\n uploadUrl: params.uploadUrl,\n uploadSize: params.uploadSize,\n headers: params.headers,\n chunkSize: params.chunkSize ?? Infinity,\n retryDelays: params.retryDelays === undefined ? DEFAULT_RETRY_DELAYS : params.retryDelays,\n storeFingerprintForResuming: params.resume ?? false,\n removeFingerprintOnSuccess: true,\n ...(params.urlStorage ? { urlStorage: params.urlStorage as never } : {}),\n onProgress: params.onProgress ?? null,\n onError: (error) => finish(() => reject(error)),\n onSuccess: () => finish(() => resolve()),\n });\n\n const onAbort = () => {\n void upload.abort();\n finish(() => reject(createAbortError()));\n };\n // `once` ensures the listener detaches after firing, even if `finish` (and\n // thus `cleanup`) never runs because the upload hangs without settling.\n if (params.signal) params.signal.addEventListener('abort', onAbort, { once: true });\n\n upload.start();\n });\n\n/** Options shared by the high-level upload entry points. */\nexport interface RunUploadOptions {\n /** Maximum chunk size in bytes. */\n chunkSize?: number;\n /** Retry backoff in milliseconds. `null`/`[]` disables retries. */\n retryDelays?: number[] | null;\n /** Progress callback. */\n onProgress?: (bytesSent: number, bytesTotal: number) => void;\n /** Abort signal to cancel the upload. */\n signal?: AbortSignal;\n /** Persist a resumable fingerprint so the upload can resume later. */\n resume?: boolean;\n /** Custom storage for resumable fingerprints. */\n urlStorage?: UploadUrlStorage;\n}\n\n/** Run a resolved upload through the given transport, applying sensible chunk-size defaults. */\nexport const runResolvedUpload = (\n transport: UploadTransport,\n uploadUrl: string,\n resolved: ResolvedUploadSource,\n options: RunUploadOptions = {},\n headers: Record<string, string> = { 'Tus-Resumable': '1.0.0' }\n): Promise<void> =>\n transport({\n data: resolved.tusFile,\n uploadUrl,\n uploadSize: resolved.size,\n headers,\n chunkSize: options.chunkSize ?? (resolved.requiresFiniteChunkSize ? DEFAULT_STREAM_CHUNK_SIZE : undefined),\n retryDelays: options.retryDelays,\n onProgress: options.onProgress,\n signal: options.signal,\n resume: options.resume,\n urlStorage: options.urlStorage,\n });\n\nconst tusStatus = (error: unknown): number | undefined => {\n const response = (error as tus.DetailedError | undefined)?.originalResponse;\n return response ? response.getStatus() : undefined;\n};\n\n/**\n * Normalise a transport-layer error into an SDK error. Aborts are re-thrown\n * as-is; auth/expiry statuses become {@link UploadSessionExpiredError}; anything\n * else becomes a generic {@link UploadError}.\n */\nexport const toUploadError = (error: unknown): never => {\n if (error instanceof Error && error.name === 'AbortError') throw error;\n const status = tusStatus(error);\n if (status === 401 || status === 403 || status === 410) {\n throw new UploadSessionExpiredError(undefined, error);\n }\n throw new UploadError(error instanceof Error ? error.message : 'The upload failed.', error);\n};\n","import type { ListQuery, Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\n\n/** A storage bucket belonging to an application. Buckets hold objects (files). */\nexport interface StorageBucket {\n /** Unique identifier (UUID). */\n id: string;\n /** The application this bucket belongs to. */\n applicationId: string;\n /** Human-readable bucket name. */\n name: string;\n /** Globally unique, hostname-safe label used to build the bucket's serving hostname. */\n slug: string;\n /** `\"public\"` buckets serve objects through the CDN hostname; `\"private\"` buckets require signed access URLs. */\n visibility: 'public' | 'private';\n /** The hostname clients use to read public objects or signed private-object URLs. */\n cdnHostname: string;\n /** The application environment this bucket is scoped to. */\n environmentId: string;\n /** ISO 8601 creation timestamp. */\n createdAt: string;\n /** ISO 8601 last-updated timestamp. */\n updatedAt: string;\n}\n\n/** Input for creating a new storage bucket. */\nexport interface CreateStorageBucketInput {\n /** Human-readable name for the bucket. */\n name: string;\n /** The application environment to scope this bucket to. */\n environmentId: string;\n /** Optional hostname-safe slug used in the generated serving hostname. Auto-generated when omitted. */\n slug?: string;\n /** Bucket visibility. Defaults to `\"private\"`. */\n visibility?: 'public' | 'private';\n}\n\n/**\n * Manage storage buckets for an application.\n * Accessed via `client.applications.storage.buckets`.\n *\n * @example\n * ```ts\n * // Create a public bucket\n * const bucket = await client.applications.storage.buckets.create('app-id', {\n * name: 'User Uploads',\n * environmentId: 'env-id',\n * visibility: 'public',\n * });\n *\n * // List all buckets\n * const { items } = await client.applications.storage.buckets.list('app-id');\n * ```\n */\nexport class StorageBucketsResource extends BaseResource {\n /**\n * List all storage buckets for an application.\n *\n * @param applicationId - The application ID (UUID).\n * @param query - Optional pagination parameters.\n * @returns A paginated list of storage buckets.\n *\n * @example\n * ```ts\n * const { items, total } = await client.applications.storage.buckets.list('app-id');\n * console.log(`${total} buckets found`);\n * ```\n */\n async list(applicationId: string, query?: ListQuery): Promise<Paginated<StorageBucket>> {\n return this.httpClient.get(`/applications/${applicationId}/storage/buckets`, {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /**\n * Create a new storage bucket.\n *\n * @param applicationId - The application ID (UUID).\n * @param data - Bucket name, environment, and optional slug/visibility.\n * @returns The newly created bucket.\n *\n * @example\n * ```ts\n * const bucket = await client.applications.storage.buckets.create('app-id', {\n * name: 'Assets',\n * environmentId: 'env-id',\n * visibility: 'public',\n * });\n * console.log(`Bucket CDN: https://${bucket.cdnHostname}`);\n * ```\n */\n async create(applicationId: string, data: CreateStorageBucketInput): Promise<StorageBucket> {\n return this.httpClient.post(`/applications/${applicationId}/storage/buckets`, data);\n }\n\n /**\n * Get a storage bucket by ID.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @returns The bucket details.\n *\n * @example\n * ```ts\n * const bucket = await client.applications.storage.buckets.get('app-id', 'bucket-id');\n * console.log(`${bucket.name} (${bucket.visibility})`);\n * ```\n */\n async get(applicationId: string, bucketId: string): Promise<StorageBucket> {\n return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}`);\n }\n\n /**\n * Permanently delete a storage bucket and all its objects.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n *\n * @example\n * ```ts\n * await client.applications.storage.buckets.delete('app-id', 'bucket-id');\n * ```\n */\n async delete(applicationId: string, bucketId: string): Promise<void> {\n return this.httpClient.delete(`/applications/${applicationId}/storage/buckets/${bucketId}`);\n }\n}\n","import type { Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\n\n/** A file (object) stored in a storage bucket. */\nexport interface StorageObject {\n /** Unique identifier (UUID). */\n id: string;\n /** The bucket this object belongs to. */\n bucketId: string;\n /** The application this object belongs to. */\n applicationId: string;\n /** The upload session that created this object, or `null` for imported objects. */\n uploadSessionId: string | null;\n /** The object key (path) within the bucket (e.g. `\"images/photo.jpg\"`). */\n key: string;\n /** MIME content type (e.g. `\"image/jpeg\"`), or `null` if not set. */\n contentType: string | null;\n /** File size in bytes. */\n contentLength: number;\n /** SHA-1 checksum of the file contents, if available. */\n checksumSha1: string | null;\n /** SHA-256 checksum of the file contents, if available. */\n checksumSha256: string | null;\n /** MD5 checksum of the file contents, if available. */\n checksumMd5: string | null;\n /** ISO 8601 timestamp of when the upload was finalized. */\n uploadedAt: string;\n /** ISO 8601 creation timestamp. */\n createdAt: string;\n /** ISO 8601 last-updated timestamp. */\n updatedAt: string;\n}\n\n/**\n * Access URL details for a storage object. For public buckets, the URL is a\n * stable CDN URL. For private buckets, the URL is time-limited and signed.\n */\nexport interface StorageObjectAccess {\n /** `\"public\"` for stable CDN URLs, `\"signed\"` for time-limited signed URLs. */\n accessType: 'public' | 'signed';\n /** The URL to access the object. */\n url: string;\n /** ISO 8601 expiry timestamp for signed URLs. `null` for public URLs. */\n expiresAt: string | null;\n}\n\n/** Query parameters for listing objects in a bucket. */\nexport interface ListStorageObjectsQuery {\n /** Only return objects whose key starts with this prefix. */\n prefix?: string;\n /** Group keys by this delimiter into `commonPrefixes` (virtual folders). Defaults to `\"/\"`. */\n delimiter?: string;\n /** Opaque cursor from a previous response's `nextCursor`. */\n cursor?: string;\n /** Maximum number of objects to return (1–1000, default 200). */\n limit?: number;\n}\n\n/** A page of storage objects, including any common (folder) prefixes. */\nexport interface StorageObjectList extends Paginated<StorageObject> {\n /** Virtual \"folder\" prefixes at the current level when a delimiter is used. */\n commonPrefixes: string[];\n}\n\n/**\n * Read and delete objects in storage buckets, and generate access URLs.\n * Accessed via `client.applications.storage.objects`.\n *\n * Objects are addressed by their object ID (UUID). If you only have the object\n * key, use {@link getByKey} to resolve it, or read the `id` from a listing.\n *\n * To upload objects, use `client.applications.storage.upload()`.\n *\n * @example\n * ```ts\n * // List all objects in a bucket\n * const { items } = await client.applications.storage.objects.list('app-id', 'bucket-id');\n * for (const obj of items) {\n * console.log(`${obj.key} (${obj.contentLength} bytes)`);\n * }\n *\n * // Get a signed download URL for a private object\n * const { url } = await client.applications.storage.objects.getAccessUrl('app-id', 'bucket-id', 'object-id');\n * ```\n */\nexport class StorageObjectsResource extends BaseResource {\n /**\n * List objects in a storage bucket, optionally filtered by key prefix and\n * grouped into virtual folders by a delimiter.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param query - Optional prefix/delimiter/cursor/limit parameters.\n * @returns A page of objects plus any common (folder) prefixes and a `nextCursor`.\n *\n * @example\n * ```ts\n * // List the \"images/\" folder, one level deep\n * const { items, commonPrefixes, nextCursor } = await client.applications.storage.objects.list(\n * 'app-id', 'bucket-id', { prefix: 'images/', limit: 100 },\n * );\n * ```\n */\n async list(applicationId: string, bucketId: string, query?: ListStorageObjectsQuery): Promise<StorageObjectList> {\n return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/objects`, {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /**\n * Get metadata for a specific object by its object ID.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param objectId - The object ID (UUID) — not the object key. Use {@link getByKey} to resolve a key.\n * @returns The object metadata.\n *\n * @example\n * ```ts\n * const obj = await client.applications.storage.objects.get('app-id', 'bucket-id', 'object-id');\n * console.log(`${obj.key}: ${obj.contentLength} bytes, type: ${obj.contentType}`);\n * ```\n */\n async get(applicationId: string, bucketId: string, objectId: string): Promise<StorageObject> {\n return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}`);\n }\n\n /**\n * Resolve an object by its key (path) instead of its ID. Convenience over\n * {@link list} — lists with the key as the prefix and returns the exact match,\n * paging through results until found, or `null` if no object with that key\n * exists. (The API has no get-by-key endpoint.)\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param key - The object key/path (e.g. `\"images/photo.jpg\"`).\n * @returns The matching object, or `null` if not found.\n */\n async getByKey(applicationId: string, bucketId: string, key: string): Promise<StorageObject | null> {\n let cursor: string | undefined;\n do {\n const page = await this.list(applicationId, bucketId, { prefix: key, delimiter: '', cursor });\n const match = page.items.find((object) => object.key === key);\n if (match) return match;\n cursor = page.nextCursor;\n } while (cursor);\n return null;\n }\n\n /**\n * Permanently delete an object from a storage bucket.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param objectId - The object ID (UUID) — not the object key.\n *\n * @example\n * ```ts\n * await client.applications.storage.objects.delete('app-id', 'bucket-id', 'object-id');\n * ```\n */\n async delete(applicationId: string, bucketId: string, objectId: string): Promise<void> {\n return this.httpClient.delete(`/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}`);\n }\n\n /**\n * Get an access URL for a storage object. For objects in public buckets,\n * returns a stable CDN URL. For private buckets, returns a time-limited\n * signed URL.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param objectId - The object ID (UUID) — not the object key.\n * @param options - Optional `expiresInSeconds` for signed URLs (60–86400).\n * @returns The access URL and its type/expiry.\n *\n * @example\n * ```ts\n * const access = await client.applications.storage.objects.getAccessUrl('app-id', 'bucket-id', 'object-id', {\n * expiresInSeconds: 3600,\n * });\n * if (access.accessType === 'signed') {\n * console.log(`Signed URL expires at ${access.expiresAt}`);\n * }\n * console.log(`Download: ${access.url}`);\n * ```\n */\n async getAccessUrl(\n applicationId: string,\n bucketId: string,\n objectId: string,\n options?: { expiresInSeconds?: number }\n ): Promise<StorageObjectAccess> {\n return this.httpClient.get(\n `/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}/access-url`,\n { query: { expiresInSeconds: options?.expiresInSeconds } }\n );\n }\n}\n","import type { ListQuery, Paginated } from '../http-client';\nimport { resolveUploadSource, type NodeReadableLike, type UploadData } from '../upload/source';\nimport {\n runResolvedUpload,\n toUploadError,\n tusUploadTransport,\n type RunUploadOptions,\n type UploadTransport,\n} from '../upload/transport';\nimport { BaseResource } from './base-resource';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * Represents an upload session for a storage object. Upload sessions track the\n * lifecycle of a file upload from creation through completion.\n */\nexport interface StorageUploadSession {\n /** Unique identifier (UUID). */\n id: string;\n /** The bucket this upload targets. */\n bucketId: string;\n /** The application this upload belongs to. */\n applicationId: string;\n /** The object key/path the file will be stored at (e.g. `\"images/photo.jpg\"`). */\n key: string;\n /** MIME content type declared at creation, or `null` if not specified. */\n contentType: string | null;\n /** Expected file size in bytes declared at creation, or `null`. */\n contentLength: number | null;\n /** SHA-1 checksum for server-side verification, if provided. */\n checksumSha1: string | null;\n /** SHA-256 checksum for server-side verification, if provided. */\n checksumSha256: string | null;\n /** MD5 checksum for server-side verification, if provided. */\n checksumMd5: string | null;\n /**\n * Current session state:\n * - `\"pending\"` — Session created, awaiting the first bytes.\n * - `\"ready\"` — Receiving file data.\n * - `\"completed\"` — Upload verified and storage object created.\n * - `\"failed\"` — Upload failed or was rejected.\n * - `\"expired\"` — Session exceeded its expiration time.\n */\n state: 'pending' | 'ready' | 'completed' | 'failed' | 'expired';\n /** ISO 8601 timestamp when this session (and its upload URL) expires. */\n expiresAt: string;\n /** ISO 8601 timestamp when the upload was finalized, or `null`. */\n uploadedAt: string | null;\n /** ISO 8601 creation timestamp. */\n createdAt: string;\n /** ISO 8601 last-updated timestamp. */\n updatedAt: string;\n}\n\n/** Input for creating a new upload session. */\nexport interface CreateUploadSessionInput {\n /** The object key/path the file will be stored at (e.g. `\"images/photo.jpg\"`). 1–1024 characters. */\n key: string;\n /** File size in bytes. Required. */\n contentLength: number;\n /** Lowercase hex SHA-256 checksum (64 chars) of the content. Required for server-side verification. */\n checksumSha256: string;\n /** MIME content type of the file (e.g. `\"image/jpeg\"`). */\n contentType?: string;\n /** Optional lowercase hex SHA-1 checksum (40 chars). */\n checksumSha1?: string;\n /** Optional lowercase hex MD5 checksum (32 chars). */\n checksumMd5?: string;\n}\n\n/**\n * Response from creating an upload session. Contains both the session metadata\n * and the resumable upload instructions (signed URL + headers).\n */\nexport interface CreateUploadSessionResponse {\n /** The created upload session. */\n session: StorageUploadSession;\n /** Resumable upload instructions — use these to send the file data. */\n upload: {\n /** The HTTP method for the byte upload (resumable upload protocol). */\n method: 'PATCH';\n /** Signed upload URL. Send your file data here. */\n url: string;\n /** Required headers to include with the upload request. */\n headers: Record<string, string>;\n /** The URL where the object will be accessible after upload (CDN URL for public buckets). */\n publicObjectUrl: string;\n };\n}\n\n/** A byte source for uploading directly to a known signed URL. */\nexport interface UploadByteSource {\n /** In-memory data (`File`/`Blob`/`Buffer`/`Uint8Array`/`ArrayBuffer`). */\n data?: UploadData;\n /** A filesystem path to stream from (Node.js only). */\n path?: string;\n /** A readable stream (Node.js only). Requires `contentLength`. */\n stream?: NodeReadableLike;\n /** Byte size — required for `stream` inputs, computed otherwise. */\n contentLength?: number;\n}\n\n// ---------------------------------------------------------------------------\n// Resource\n// ---------------------------------------------------------------------------\n\n/**\n * Manage upload sessions and upload bytes to a signed upload URL using the\n * resumable upload protocol. Accessed via\n * `client.applications.storage.uploadSessions`.\n *\n * For most use cases, prefer the high-level `client.applications.storage.upload()`\n * which creates the session, computes the required checksum, uploads the bytes,\n * and returns the public URL.\n */\nexport class StorageUploadSessionsResource extends BaseResource {\n constructor(\n httpClient: ConstructorParameters<typeof BaseResource>[0],\n private readonly transport: UploadTransport = tusUploadTransport\n ) {\n super(httpClient);\n }\n\n /**\n * List upload sessions for a bucket.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param query - Optional pagination parameters.\n * @returns A paginated list of upload sessions.\n */\n async list(applicationId: string, bucketId: string, query?: ListQuery): Promise<Paginated<StorageUploadSession>> {\n return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/uploads`, {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /**\n * Create an upload session. Returns the session metadata and a signed upload\n * URL for sending file data. This is the low-level method — for most use\n * cases prefer `client.applications.storage.upload()` which also computes the\n * required SHA-256 checksum for you.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param data - Object key, content length, SHA-256 checksum, and optional content type / extra checksums.\n * @returns The session and resumable upload instructions (URL, method, headers).\n */\n async create(\n applicationId: string,\n bucketId: string,\n data: CreateUploadSessionInput\n ): Promise<CreateUploadSessionResponse> {\n return this.httpClient.post(`/applications/${applicationId}/storage/buckets/${bucketId}/uploads`, data);\n }\n\n /**\n * Get an upload session by ID. Use this to track server-side processing after\n * an upload (poll until `state === 'completed'`).\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param sessionId - The upload session ID (UUID).\n * @returns The current session state.\n */\n async get(applicationId: string, bucketId: string, sessionId: string): Promise<StorageUploadSession> {\n return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/uploads/${sessionId}`);\n }\n\n /**\n * Upload bytes directly to a pre-existing signed upload URL — for example, a\n * URL returned by {@link create} or handed to your client by a backend. Skips\n * session creation and checksum computation.\n *\n * @param url - A signed upload URL.\n * @param source - The bytes to upload.\n * @param options - Chunk size, retry config, progress, abort signal, resume,\n * and any required `headers` returned with the upload session.\n * @throws {@link UploadError} if the upload fails after all retries.\n */\n async uploadToUrl(\n url: string,\n source: UploadByteSource,\n options?: RunUploadOptions & { headers?: Record<string, string> }\n ): Promise<void> {\n const resolved = await resolveUploadSource({ key: '', ...source }, { hash: false });\n const headers = { 'Tus-Resumable': '1.0.0', ...options?.headers };\n await runResolvedUpload(this.transport, url, resolved, options, headers).catch(toUploadError);\n }\n\n /**\n * Resume an interrupted upload to a previously issued signed upload URL. The\n * resumable protocol negotiates the current offset and continues from there.\n *\n * @param url - The signed upload URL from the original {@link create} call.\n * @param source - The full bytes to upload (the same content as the original).\n * @param options - Chunk size, retry config, progress, abort signal.\n */\n async resumeFromUrl(\n url: string,\n source: UploadByteSource,\n options?: RunUploadOptions & { headers?: Record<string, string> }\n ): Promise<void> {\n return this.uploadToUrl(url, source, { ...options, resume: true });\n }\n}\n","import { UploadError } from '../errors';\nimport type { HttpClient } from '../http-client';\nimport { resolveUploadSource, type NodeReadableLike, type UploadData } from '../upload/source';\nimport {\n runResolvedUpload,\n toUploadError,\n tusUploadTransport,\n type UploadTransport,\n type UploadUrlStorage,\n} from '../upload/transport';\nimport { StorageBucketsResource } from './storage-buckets';\nimport { StorageObjectsResource, type StorageObject } from './storage-objects';\nimport { StorageUploadSessionsResource, type StorageUploadSession } from './storage-upload-sessions';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** Options controlling whether and how to wait for an upload to finalize server-side. */\nexport interface WaitForCompletionOptions {\n /** Maximum time to wait in milliseconds. Default: 60000. */\n timeoutMs?: number;\n /** How often to poll the session state, in milliseconds. Default: 1000. */\n pollIntervalMs?: number;\n}\n\n/** Input for the high-level {@link ApplicationStorageResource.upload | upload()} method. */\nexport interface UploadFileInput {\n /** The application ID (UUID). */\n applicationId: string;\n /** The target bucket ID (UUID). */\n bucketId: string;\n /** The object key/path in the bucket (e.g. `\"images/logo.png\"`). */\n key: string;\n /** In-memory data (browser `File`/`Blob`, Node `Buffer`, `Uint8Array`, `ArrayBuffer`). */\n data?: UploadData;\n /** A filesystem path to upload from (Node.js only). Size, checksum, and content type are derived automatically. */\n path?: string;\n /** A readable stream to upload from (Node.js only). Requires `contentLength` and `checksumSha256`. */\n stream?: NodeReadableLike;\n /** MIME content type. Inferred from `key` when omitted. */\n contentType?: string;\n /** Byte size. Required for `stream`; computed otherwise. */\n contentLength?: number;\n /** Pre-computed SHA-256 (skips hashing). Required for `stream`. */\n checksumSha256?: string;\n /** Also send a SHA-1 checksum. */\n checksumSha1?: string;\n /** Also send an MD5 checksum (Node.js only unless provided). */\n checksumMd5?: string;\n /** Maximum chunk size in bytes (for very large files / streams). */\n chunkSize?: number;\n /** Retry backoff in milliseconds; `null`/`[]` disables retries. */\n retryDelays?: number[] | null;\n /** Progress callback invoked during the byte upload. */\n onProgress?: (bytesSent: number, bytesTotal: number) => void;\n /** Abort signal to cancel the upload. */\n signal?: AbortSignal;\n /** Persist a resumable fingerprint so the upload can be resumed later. */\n resume?: boolean;\n /** Custom storage backend for resumable fingerprints. */\n urlStorage?: UploadUrlStorage;\n /** Wait until the object is finalized server-side before resolving. Pass options to tune polling. */\n waitForCompletion?: boolean | WaitForCompletionOptions;\n}\n\n/** Result of a successful upload. */\nexport interface UploadFileResult {\n /** The upload session. When `waitForCompletion` was set, `state` is `\"completed\"`. */\n session: StorageUploadSession;\n /** The public/CDN URL of the uploaded object. */\n url: string;\n /** The finalized storage object — present only when `waitForCompletion` was set. */\n object?: StorageObject;\n}\n\n/** Options for {@link ApplicationStorageResource.uploadBatch | uploadBatch()}. */\nexport interface UploadBatchOptions {\n /** Maximum number of concurrent uploads. Default: 4. */\n concurrency?: number;\n /** Called after each file settles, with the number completed and the total. */\n onProgress?: (completed: number, total: number) => void;\n}\n\n/** The outcome of one file within a batch upload. Errors are isolated per file. */\nexport interface UploadBatchItemResult {\n /** The input that produced this result. */\n input: UploadFileInput;\n /** The successful result, if the upload succeeded. */\n result?: UploadFileResult;\n /** The error, if this upload failed. */\n error?: unknown;\n}\n\n// ---------------------------------------------------------------------------\n// Resource\n// ---------------------------------------------------------------------------\n\nconst delay = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * Namespace for all storage operations on an application: bucket management,\n * object listing/access, low-level upload sessions, and the high-level\n * {@link upload} / {@link uploadBatch} helpers.\n *\n * Accessed via `client.applications.storage`.\n *\n * @example\n * ```ts\n * // High-level upload (Node.js, from a path — checksum/size/content-type inferred)\n * const { url } = await client.applications.storage.upload({\n * applicationId: 'app-id',\n * bucketId: 'bucket-id',\n * key: 'photos/cat.jpg',\n * path: './cat.jpg',\n * });\n *\n * // Browser upload from a file input, with progress and abort\n * const controller = new AbortController();\n * const { url } = await client.applications.storage.upload({\n * applicationId: 'app-id',\n * bucketId: 'bucket-id',\n * key: `uploads/${file.name}`,\n * data: file,\n * onProgress: (sent, total) => console.log(`${Math.round((sent / total) * 100)}%`),\n * signal: controller.signal,\n * });\n * ```\n */\nexport class ApplicationStorageResource {\n /** Create, list, get, and delete storage buckets. */\n readonly buckets: StorageBucketsResource;\n /** List, get, delete objects, and generate access URLs. */\n readonly objects: StorageObjectsResource;\n /** Low-level upload sessions and direct-to-URL byte uploads. */\n readonly uploadSessions: StorageUploadSessionsResource;\n\n private readonly transport: UploadTransport;\n\n constructor(httpClient: HttpClient, transport: UploadTransport = tusUploadTransport) {\n this.transport = transport;\n this.buckets = new StorageBucketsResource(httpClient);\n this.objects = new StorageObjectsResource(httpClient);\n this.uploadSessions = new StorageUploadSessionsResource(httpClient, transport);\n }\n\n /**\n * Upload a file to a storage bucket. Handles the full flow: computes the\n * required SHA-256 checksum, creates an upload session, uploads the bytes with\n * automatic retries (and optional progress/abort/resume), and returns the\n * public URL.\n *\n * Accepts browser `File`/`Blob`, Node `Buffer`/`Uint8Array`/`ArrayBuffer`, a\n * Node filesystem `path`, or a Node readable `stream` (with `contentLength`\n * and `checksumSha256`). The content type is inferred from `key` when omitted.\n *\n * @param input - What and where to upload, plus optional transfer options.\n * @returns The upload session and public object URL (and the finalized object when `waitForCompletion` is set).\n * @throws {@link UploadError} if the byte upload fails.\n * @throws {@link UploadSessionExpiredError} if the session expires mid-upload.\n *\n * @example\n * ```ts\n * const { session, url, object } = await client.applications.storage.upload({\n * applicationId, bucketId, key: 'reports/q1.pdf', path: './q1.pdf',\n * waitForCompletion: true,\n * });\n * console.log(object?.contentLength, 'bytes available at', url);\n * ```\n */\n async upload(input: UploadFileInput): Promise<UploadFileResult> {\n const resolved = await resolveUploadSource({\n key: input.key,\n data: input.data,\n path: input.path,\n stream: input.stream,\n contentType: input.contentType,\n contentLength: input.contentLength,\n checksumSha256: input.checksumSha256,\n checksumSha1: input.checksumSha1,\n checksumMd5: input.checksumMd5,\n });\n\n const { session, upload } = await this.uploadSessions.create(input.applicationId, input.bucketId, {\n key: input.key,\n contentLength: resolved.size,\n checksumSha256: resolved.checksums.sha256,\n contentType: resolved.contentType,\n checksumSha1: resolved.checksums.sha1,\n checksumMd5: resolved.checksums.md5,\n });\n\n await runResolvedUpload(\n this.transport,\n upload.url,\n resolved,\n {\n chunkSize: input.chunkSize,\n retryDelays: input.retryDelays,\n onProgress: input.onProgress,\n signal: input.signal,\n resume: input.resume,\n urlStorage: input.urlStorage,\n },\n // Forward any required headers the API issued with the session.\n { 'Tus-Resumable': '1.0.0', ...upload.headers }\n ).catch(toUploadError);\n\n if (input.waitForCompletion) {\n const options = typeof input.waitForCompletion === 'object' ? input.waitForCompletion : undefined;\n const completed = await this.waitForCompletion(input.applicationId, input.bucketId, session.id, options);\n const object = (await this.objects.getByKey(input.applicationId, input.bucketId, input.key)) ?? undefined;\n return { session: completed, url: upload.publicObjectUrl, object };\n }\n\n return { session, url: upload.publicObjectUrl };\n }\n\n /**\n * Upload many files concurrently. Each file is uploaded independently; a\n * failure for one file does not abort the others — inspect each item's\n * `error`/`result`.\n *\n * @param inputs - The files to upload.\n * @param options - Concurrency limit and an aggregated progress callback.\n * @returns One result per input, in the same order.\n *\n * @example\n * ```ts\n * const results = await client.applications.storage.uploadBatch(\n * files.map((f) => ({ applicationId, bucketId, key: `uploads/${f.name}`, data: f })),\n * { concurrency: 6, onProgress: (done, total) => console.log(`${done}/${total}`) },\n * );\n * const failed = results.filter((r) => r.error);\n * ```\n */\n async uploadBatch(inputs: UploadFileInput[], options?: UploadBatchOptions): Promise<UploadBatchItemResult[]> {\n const concurrency = Math.max(1, options?.concurrency ?? 4);\n const results: UploadBatchItemResult[] = new Array(inputs.length);\n let completed = 0;\n let next = 0;\n\n const worker = async (): Promise<void> => {\n for (;;) {\n const index = next++;\n if (index >= inputs.length) return;\n try {\n results[index] = { input: inputs[index], result: await this.upload(inputs[index]) };\n } catch (error) {\n results[index] = { input: inputs[index], error };\n }\n completed++;\n options?.onProgress?.(completed, inputs.length);\n }\n };\n\n await Promise.all(Array.from({ length: Math.min(concurrency, inputs.length) }, () => worker()));\n return results;\n }\n\n /**\n * Poll an upload session until the object is finalized server-side.\n *\n * @param applicationId - The application ID (UUID).\n * @param bucketId - The bucket ID (UUID).\n * @param sessionId - The upload session ID (UUID).\n * @param options - Timeout and polling interval.\n * @returns The completed session.\n * @throws {@link UploadError} if the session fails, expires, or the timeout elapses.\n */\n async waitForCompletion(\n applicationId: string,\n bucketId: string,\n sessionId: string,\n options?: WaitForCompletionOptions\n ): Promise<StorageUploadSession> {\n const timeoutMs = options?.timeoutMs ?? 60_000;\n const pollIntervalMs = options?.pollIntervalMs ?? 1000;\n const deadline = Date.now() + timeoutMs;\n\n for (;;) {\n const session = await this.uploadSessions.get(applicationId, bucketId, sessionId);\n if (session.state === 'completed') return session;\n if (session.state === 'failed' || session.state === 'expired') {\n throw new UploadError(`Upload session ${session.state}.`);\n }\n if (Date.now() >= deadline) {\n throw new UploadError('Timed out waiting for the upload to complete.');\n }\n await delay(pollIntervalMs);\n }\n }\n}\n","import type { ListQuery, Paginated } from '../http-client';\nimport { ApplicationEnvVarsResource } from './application-env-vars';\nimport { ApplicationRequestsResource } from './application-requests';\nimport { ApplicationStorageResource } from './application-storage';\nimport { BaseResource } from './base-resource';\nimport type { ApplicationHostnameList, HostnameAvailability, SetProductionHostnameResult } from './hostnames';\nimport type { Organization } from './organizations';\n\n/** A Gigadrive Network application, belonging to an {@link Organization}. */\nexport interface Application {\n /** Unique identifier (UUID). */\n id: string;\n /** The organization this application belongs to. */\n organization: Organization;\n /** Display name of the application. */\n name: string;\n /** Avatar / logo URL. */\n imageUrl: string;\n /** ISO 8601 creation timestamp. */\n createdAt: string;\n /** ISO 8601 last-updated timestamp. */\n updatedAt: string;\n}\n\n/** Query filters for listing applications. */\nexport interface ListApplicationsQuery extends ListQuery {\n /** Only return applications belonging to this organization. */\n organizationId?: string;\n}\n\n/**\n * Manage applications. Accessed via {@link GigadriveClient.applications}.\n *\n * @example\n * ```ts\n * const { items: apps } = await client.applications.list();\n * console.log(apps.map((a) => `${a.name} (${a.organization.name})`));\n * ```\n */\nexport class ApplicationsResource extends BaseResource {\n /**\n * Manage environment variables scoped to an application.\n *\n * @example\n * ```ts\n * await client.applications.envVars.create('app-id', {\n * key: 'DATABASE_URL',\n * value: 'postgres://...',\n * sensitive: true,\n * });\n * ```\n */\n readonly envVars: ApplicationEnvVarsResource;\n\n /**\n * Manage storage buckets, objects, and file uploads for an application.\n *\n * @example\n * ```ts\n * // Upload a file\n * const { url } = await client.applications.storage.upload({\n * applicationId: 'app-id',\n * bucketId: 'bucket-id',\n * key: 'images/logo.png',\n * data: fileData,\n * });\n *\n * // List objects in a bucket\n * const { items } = await client.applications.storage.objects.list('app-id', 'bucket-id');\n * ```\n */\n readonly storage: ApplicationStorageResource;\n\n /**\n * Read observed traffic (request logs) for an application.\n *\n * @example\n * ```ts\n * const { items } = await client.applications.requests.list('app-id', { statusFamily: 5 });\n * ```\n */\n readonly requests: ApplicationRequestsResource;\n\n constructor(...args: ConstructorParameters<typeof BaseResource>) {\n super(...args);\n this.envVars = new ApplicationEnvVarsResource(this.httpClient);\n this.storage = new ApplicationStorageResource(this.httpClient);\n this.requests = new ApplicationRequestsResource(this.httpClient);\n }\n\n /**\n * List applications the authenticated actor has access to.\n *\n * Requires the `network:applications:read` scope.\n *\n * @param query - Optional organization filter and pagination.\n * @returns A paginated list of applications.\n *\n * @example\n * ```ts\n * const { items, total } = await client.applications.list({ organizationId: 'org-id' });\n * console.log(`Found ${total} applications`);\n * ```\n */\n async list(query?: ListApplicationsQuery): Promise<Paginated<Application>> {\n return this.httpClient.get('/applications', {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /**\n * List the `*.gigadrive.app` hostnames for an application (production alias\n * and per-branch aliases).\n *\n * @param applicationId - The application ID (UUID).\n * @returns The hostnames plus the production hostname `label`.\n *\n * @example\n * ```ts\n * const { items, label } = await client.applications.hostnames('app-id');\n * console.log(`Production: ${label}.gigadrive.app`);\n * ```\n */\n async hostnames(applicationId: string): Promise<ApplicationHostnameList> {\n return this.httpClient.get(`/applications/${applicationId}/hostnames`);\n }\n\n /**\n * Check whether a candidate production hostname label is allowed and globally\n * available before setting it with {@link setProductionHostname}.\n *\n * Requires the `network:applications:read` scope.\n *\n * @param applicationId - The application ID (UUID).\n * @param label - The candidate production hostname label (e.g. `\"my-app\"`).\n * @returns Whether the label is available, plus a `reason` when it is not.\n *\n * @example\n * ```ts\n * const { available, reason } = await client.applications.checkHostnameAvailability('app-id', 'my-app');\n * if (!available) console.log(`Unavailable: ${reason}`);\n * ```\n */\n async checkHostnameAvailability(applicationId: string, label: string): Promise<HostnameAvailability> {\n return this.httpClient.get(`/applications/${applicationId}/hostname/availability`, {\n query: { label },\n });\n }\n\n /**\n * Set the application's production hostname. The production alias\n * `{label}.gigadrive.app` is re-pointed to the latest production deployment.\n *\n * Requires the `network:applications:write` scope. Deployment- and\n * function-scoped tokens cannot change the production hostname.\n *\n * @param applicationId - The application ID (UUID).\n * @param label - The production hostname label (e.g. `\"my-app\"`). It is\n * normalized (slugified) server-side.\n * @returns The saved label, the resulting hostname, and whether it is live yet.\n *\n * @example\n * ```ts\n * const { hostname, live } = await client.applications.setProductionHostname('app-id', 'my-app');\n * console.log(live ? `Live at ${hostname}` : `Reserved ${hostname} (deploy to go live)`);\n * ```\n */\n async setProductionHostname(applicationId: string, label: string): Promise<SetProductionHostnameResult> {\n return this.httpClient.put(`/applications/${applicationId}/hostname`, { label });\n }\n}\n","import type { Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\nimport type { Hostname } from './hostnames';\n\n/**\n * The lifecycle status of a deployment.\n * - `\"PENDING\"` — Created, waiting for artifact upload.\n * - `\"QUEUED\"` — Queued for processing.\n * - `\"STARTING\"` — Processing is starting.\n * - `\"BUILDING\"` — Build pipeline is running.\n * - `\"PROVISIONING\"` — Infrastructure is being provisioned.\n * - `\"ACTIVE\"` — Successfully deployed and serving traffic.\n * - `\"FAILED\"` — Build or provisioning failed.\n */\nexport type DeploymentStatus = 'PENDING' | 'QUEUED' | 'STARTING' | 'BUILDING' | 'PROVISIONING' | 'ACTIVE' | 'FAILED';\n\n/** The severity level of a deployment log entry. */\nexport type DeploymentLogType = 'INFO' | 'ERROR' | 'WARN';\n\n/** A deployment of an application to the Gigadrive Network. */\nexport interface Deployment {\n /** Unique identifier (UUID). */\n id: string;\n /** The application this deployment belongs to. */\n applicationId: string;\n /** Current lifecycle status. */\n status: DeploymentStatus;\n /** ISO 8601 creation timestamp. */\n createdAt: string;\n /** ISO 8601 last-updated timestamp. */\n updatedAt: string;\n}\n\n/** A single log entry from a deployment's build or provisioning pipeline. */\nexport interface DeploymentLog {\n /** Unique identifier. */\n id: string;\n /** The log message text. */\n message: string;\n /** Severity level: `\"INFO\"`, `\"ERROR\"`, or `\"WARN\"`. */\n type: DeploymentLogType;\n /** ISO 8601 timestamp of when this log entry was created. */\n createdAt: string;\n}\n\n/** A paginated page of deployment log entries. */\nexport interface DeploymentLogPage {\n /** Total number of log entries for this deployment. */\n totalItems: number;\n /** Maximum number of entries per page. */\n limit: number;\n /** Number of entries skipped (for pagination). */\n offset: number;\n /** The log entries on this page. */\n items: DeploymentLog[];\n}\n\n/** Input for creating a new deployment. */\nexport interface CreateDeploymentInput {\n /** The application to deploy. */\n applicationId: string;\n /** Optional git source for the deployment. When omitted, the deployment expects an artifact upload. */\n gitSource?: {\n /** The git ref to deploy (e.g. `\"main\"`, `\"v1.0.0\"`). */\n ref: string;\n /** A specific commit SHA to deploy. If omitted, the HEAD of the ref is used. */\n sha?: string;\n };\n}\n\n/** Query filters for listing deployments. All fields are optional. */\nexport interface ListDeploymentsQuery {\n /** Filter by organization ID. */\n organizationId?: string;\n /** Filter by application ID. */\n applicationId?: string;\n /** Filter by deployment status. */\n status?: DeploymentStatus;\n}\n\n/** Query parameters for fetching deployment logs. */\nexport interface ListDeploymentLogsQuery {\n /** Number of log entries to skip (for pagination). */\n offset?: number;\n /** Maximum number of log entries to return per page. */\n limit?: number;\n /** Only return log entries created after this ISO 8601 timestamp. Useful for tailing logs. */\n 'createdAt[gt]'?: string;\n}\n\n/** Result from starting a multipart deployment upload. */\nexport interface StartUploadResult {\n /** The multipart upload ID. Pass this to subsequent `getPresignedUrl` and `completeUpload` calls. */\n uploadId: string;\n}\n\n/** A presigned URL for uploading a single part of a multipart deployment upload. */\nexport interface PresignedUrlResult {\n /** The presigned URL to PUT the part data to. */\n url: string;\n}\n\n/** A successfully uploaded part, used to complete the multipart upload. */\nexport interface UploadPart {\n /** The 1-based part number. */\n partNumber: number;\n /** The ETag returned by the storage provider after uploading this part. */\n etag: string;\n}\n\n/**\n * Manage deployments — create, monitor, upload artifacts, and read logs.\n * Accessed via {@link GigadriveClient.deployments}.\n *\n * ## Deployment lifecycle\n *\n * 1. **Create** a deployment with {@link create}.\n * 2. **Upload** build artifacts using the multipart upload flow\n * ({@link startUpload} → {@link getPresignedUrl} → {@link uploadPart} → {@link completeUpload}).\n * 3. **Monitor** the build with {@link get} and {@link getLogs}.\n *\n * @example\n * ```ts\n * // Create a deployment\n * const deployment = await client.deployments.create({ applicationId: 'app-id' });\n *\n * // Check status\n * const updated = await client.deployments.get(deployment.id);\n * console.log(`Status: ${updated.status}`);\n *\n * // Read build logs\n * const logs = await client.deployments.getLogs(deployment.id, { limit: 50 });\n * for (const entry of logs.items) {\n * console.log(`[${entry.type}] ${entry.message}`);\n * }\n * ```\n */\nexport class DeploymentsResource extends BaseResource {\n /**\n * List deployments, optionally filtered by organization, application, or status.\n *\n * Requires the `network:deployments:read` scope.\n *\n * @param query - Optional filters.\n * @returns A paginated list of deployments.\n *\n * @example\n * ```ts\n * // All deployments for an application\n * const { items } = await client.deployments.list({ applicationId: 'app-id' });\n *\n * // Only active deployments\n * const { items } = await client.deployments.list({ status: 'ACTIVE' });\n * ```\n */\n async list(query?: ListDeploymentsQuery): Promise<Paginated<Deployment>> {\n return this.httpClient.get('/deployments', {\n query: query as Record<string, string | undefined> | undefined,\n });\n }\n\n /**\n * Get a deployment by ID, including its current status.\n *\n * @param deploymentId - The deployment ID (UUID).\n * @returns The deployment with its current status.\n *\n * @example\n * ```ts\n * const deployment = await client.deployments.get('deployment-id');\n * if (deployment.status === 'ACTIVE') {\n * console.log('Deployment is live!');\n * }\n * ```\n */\n async get(deploymentId: string): Promise<Deployment> {\n return this.httpClient.get(`/deployments/${deploymentId}`);\n }\n\n /**\n * Create a new deployment. The deployment starts in `\"PENDING\"` status,\n * waiting for artifact upload. Use the multipart upload methods\n * ({@link startUpload}, {@link getPresignedUrl}, {@link uploadPart},\n * {@link completeUpload}) to upload build artifacts.\n *\n * Requires the `network:deployments:trigger` scope.\n *\n * @param data - The application ID and optional git source.\n * @returns The newly created deployment.\n *\n * @example\n * ```ts\n * const deployment = await client.deployments.create({\n * applicationId: 'app-id',\n * });\n * console.log(`Created deployment ${deployment.id} (${deployment.status})`);\n * ```\n */\n async create(data: CreateDeploymentInput): Promise<Deployment> {\n return this.httpClient.post('/deployments', data);\n }\n\n /**\n * Start a multipart upload for deployment artifacts. This initiates a new\n * multipart upload and returns an upload ID for subsequent part uploads.\n *\n * The deployment must be in `\"PENDING\"` status.\n *\n * @param deploymentId - The deployment ID (UUID).\n * @returns An object containing the `uploadId` for subsequent calls.\n *\n * @example\n * ```ts\n * const { uploadId } = await client.deployments.startUpload('deployment-id');\n * ```\n */\n async startUpload(deploymentId: string): Promise<StartUploadResult> {\n return this.httpClient.post(`/deployments/${deploymentId}/upload/start`);\n }\n\n /**\n * Get a presigned URL for uploading a single part of a multipart upload.\n * The URL is temporary and should be used immediately with {@link uploadPart}.\n *\n * @param deploymentId - The deployment ID (UUID).\n * @param uploadId - The multipart upload ID from {@link startUpload}.\n * @param partNumber - The 1-based part number.\n * @returns An object containing the presigned `url` to PUT the part data to.\n *\n * @example\n * ```ts\n * const { url } = await client.deployments.getPresignedUrl(\n * 'deployment-id', uploadId, 1,\n * );\n * ```\n */\n async getPresignedUrl(deploymentId: string, uploadId: string, partNumber: number): Promise<PresignedUrlResult> {\n if (!Number.isInteger(partNumber) || partNumber < 1) {\n throw new Error(`partNumber must be a positive integer, received ${partNumber}`);\n }\n return this.httpClient.post(`/deployments/${deploymentId}/upload/part`, { uploadId, partNumber });\n }\n\n /**\n * Upload a part to a presigned URL obtained from {@link getPresignedUrl}.\n * This sends the chunk data directly to the backend storage service, not\n * to the Gigadrive API. The returned `etag` is needed for\n * {@link completeUpload}.\n *\n * @param presignedUrl - The presigned URL from {@link getPresignedUrl}.\n * @param data - The chunk data to upload.\n * @param partNumber - The 1-based part number (used for error messages).\n * @returns The part number and ETag. Collect these for {@link completeUpload}.\n * @throws {@link ApiError} if the PUT request fails.\n * @throws Error if the storage provider does not return an ETag header.\n *\n * @example\n * ```ts\n * const chunk = fileBuffer.subarray(0, 10 * 1024 * 1024); // 10 MB\n * const part = await client.deployments.uploadPart(presignedUrl, chunk, 1);\n * // part = { partNumber: 1, etag: '\"abc123...\"' }\n * ```\n */\n async uploadPart(\n presignedUrl: string,\n data: ArrayBuffer | Uint8Array | Blob,\n partNumber: number\n ): Promise<UploadPart> {\n if (!Number.isInteger(partNumber) || partNumber < 1) {\n throw new Error(`partNumber must be a positive integer, received ${partNumber}`);\n }\n const response = await this.httpClient.fetchRaw(presignedUrl, {\n method: 'PUT',\n headers: {\n // Deployment artifacts are always ZIP archives.\n 'Content-Type': 'application/zip',\n 'Content-Length': String(data instanceof Blob ? data.size : data.byteLength),\n },\n body: data,\n });\n\n const etag = response.headers.get('ETag');\n if (!etag) {\n throw new Error(`No ETag received for part ${partNumber}`);\n }\n\n return { partNumber, etag };\n }\n\n /**\n * Complete a multipart upload after all parts have been uploaded via\n * {@link uploadPart}. This signals the storage provider to assemble the\n * parts into a single object and triggers the deployment build pipeline.\n *\n * @param deploymentId - The deployment ID (UUID).\n * @param uploadId - The multipart upload ID from {@link startUpload}.\n * @param parts - Array of `{ partNumber, etag }` from each {@link uploadPart} call.\n *\n * @example\n * ```ts\n * await client.deployments.completeUpload(deploymentId, uploadId, [\n * { partNumber: 1, etag: '\"abc...\"' },\n * { partNumber: 2, etag: '\"def...\"' },\n * ]);\n * ```\n */\n async completeUpload(deploymentId: string, uploadId: string, parts: UploadPart[]): Promise<void> {\n return this.httpClient.post(`/deployments/${deploymentId}/upload/complete`, { uploadId, parts });\n }\n\n /**\n * Fetch deployment logs. Supports pagination and filtering by timestamp\n * for incremental log tailing.\n *\n * @param deploymentId - The deployment ID (UUID).\n * @param query - Optional pagination and filter parameters.\n * @returns A page of log entries with total count.\n *\n * @example\n * ```ts\n * // Get the first page of logs\n * const page = await client.deployments.getLogs('deployment-id', {\n * offset: 0,\n * limit: 100,\n * });\n *\n * for (const entry of page.items) {\n * const prefix = entry.type === 'ERROR' ? 'ERR' : entry.type === 'WARN' ? 'WRN' : 'INF';\n * console.log(`[${prefix}] ${entry.message}`);\n * }\n *\n * // Tail new logs since last fetch\n * const newLogs = await client.deployments.getLogs('deployment-id', {\n * 'createdAt[gt]': lastEntry.createdAt,\n * });\n * ```\n */\n async getLogs(deploymentId: string, query?: ListDeploymentLogsQuery): Promise<DeploymentLogPage> {\n return this.httpClient.get(`/deployments/${deploymentId}/logs`, {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /**\n * List the immutable `*.gigadrive.app` hostnames assigned to a deployment.\n *\n * @param deploymentId - The deployment ID (UUID).\n * @returns A paginated list of hostnames.\n *\n * @example\n * ```ts\n * const { items } = await client.deployments.getHostnames('deployment-id');\n * console.log(items.map((h) => h.hostname));\n * ```\n */\n async getHostnames(deploymentId: string): Promise<Paginated<Hostname>> {\n return this.httpClient.get(`/deployments/${deploymentId}/hostnames`);\n }\n}\n","import type { HttpClient, Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** One bucket of an AI Gateway usage breakdown (by model, provider, or user). */\nexport interface AiGatewayUsageBreakdown {\n /** Bucket label (a model, provider, or user identifier). */\n label: string;\n /** Number of requests in this bucket. */\n requests: number;\n /** Total tokens in this bucket. */\n tokens: number;\n /** Input tokens in this bucket. */\n inputTokens: number;\n /** Output tokens in this bucket. */\n outputTokens: number;\n /** Billable cost in micros of USD for this bucket. */\n costMicros: number;\n}\n\n/** Aggregated AI Gateway usage over a time range, with breakdowns. */\nexport interface AiGatewayUsageSummary {\n summary: {\n requestCount: number;\n successCount: number;\n errorCount: number;\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n billableCostMicros: number;\n avgLatencyMs: number;\n };\n byModel: AiGatewayUsageBreakdown[];\n byProvider: AiGatewayUsageBreakdown[];\n byUser: AiGatewayUsageBreakdown[];\n}\n\n/** One provider attempt recorded while routing an AI Gateway request. */\nexport interface AiGatewayProviderAttempt {\n provider: string;\n error?: string;\n statusCode?: number;\n tag?: string;\n}\n\n/** A single AI Gateway request event with full telemetry. */\nexport interface AiGatewayRequestEvent {\n id: string;\n requestId: string;\n traceId: string | null;\n billingSubjectType: 'organization' | 'application';\n organizationId: string;\n applicationId: string | null;\n actorId: string | null;\n actorType: string;\n apiKeyId: string | null;\n authenticatedUserId: string | null;\n callerEndUserId: string | null;\n modelRequested: string;\n modelServed: string | null;\n provider: string | null;\n providerAttempts: AiGatewayProviderAttempt[] | null;\n status: 'pending' | 'success' | 'error' | 'cancelled';\n errorCode: string | null;\n errorType: string | null;\n inputTokens: number;\n outputTokens: number;\n cachedInputTokens: number;\n totalTokens: number;\n usageSource: 'provider' | 'estimated' | 'none';\n providerCostMicros: number;\n billableCostMicros: number;\n streaming: boolean;\n latencyMs: number | null;\n metadata: Record<string, string> | null;\n startedAt: string;\n completedAt: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/** An AI Gateway spend/usage budget. */\nexport interface AiGatewayBudget {\n id: string;\n organizationId: string;\n /** Application-specific target, or `null` for organization-wide. */\n applicationId: string | null;\n /** User-specific target, or `null` for all users. */\n userId: string | null;\n period: 'day' | 'month';\n maxCostMicros: number | null;\n maxRequests: number | null;\n maxTokens: number | null;\n maxRequestCostMicros: number | null;\n enabled: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n/** Input for one budget when replacing the budget set. */\nexport interface AiGatewayBudgetInput {\n applicationId?: string;\n userId?: string;\n period?: 'day' | 'month';\n maxCostMicros?: number | null;\n maxRequests?: number | null;\n maxTokens?: number | null;\n maxRequestCostMicros?: number | null;\n enabled?: boolean;\n}\n\n/** An AI Gateway governance policy. */\nexport interface AiGatewayPolicy {\n id: string;\n organizationId: string;\n /** Application-specific target, or `null` for organization-wide. */\n applicationId: string | null;\n /** Allowed model IDs, or `null` to allow all. */\n allowedModels: string[] | null;\n /** Allowed provider IDs, or `null` to allow all. */\n allowedProviders: string[] | null;\n requireZdr: boolean;\n allowFallbacks: boolean;\n maxOutputTokens: number | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/** Input for creating or updating an AI Gateway policy. */\nexport interface AiGatewayPolicyInput {\n applicationId?: string;\n allowedModels?: string[] | null;\n allowedProviders?: string[] | null;\n requireZdr?: boolean;\n allowFallbacks?: boolean;\n maxOutputTokens?: number | null;\n}\n\n/** Query for usage summary. */\nexport interface AiGatewayUsageQuery {\n /** Only include usage at or after this ISO 8601 timestamp. */\n from?: string;\n /** Only include usage before or at this ISO 8601 timestamp. */\n to?: string;\n /** Restrict to one application. */\n applicationId?: string;\n}\n\n/** Query for the request-event log and CSV export. */\nexport interface AiGatewayRequestsQuery extends AiGatewayUsageQuery {\n model?: string;\n provider?: string;\n status?: 'pending' | 'success' | 'error' | 'cancelled';\n requestId?: string;\n authenticatedUserId?: string;\n callerEndUserId?: string;\n limit?: number;\n cursor?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Sub-resources\n// ---------------------------------------------------------------------------\n\n/** AI Gateway usage analytics for an organization. */\nexport class AiGatewayUsageResource extends BaseResource {\n /** Get an aggregated usage summary with breakdowns by model, provider, and user. */\n async summary(organizationId: string, query?: AiGatewayUsageQuery): Promise<AiGatewayUsageSummary> {\n return this.httpClient.get(`/organizations/${organizationId}/ai-gateway/usage/summary`, {\n query: query as Record<string, string | undefined> | undefined,\n });\n }\n\n /** List request-level usage events. */\n async requests(organizationId: string, query?: AiGatewayRequestsQuery): Promise<Paginated<AiGatewayRequestEvent>> {\n return this.httpClient.get(`/organizations/${organizationId}/ai-gateway/usage/requests`, {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /** Export request-level usage events as CSV text. */\n async export(organizationId: string, query?: AiGatewayRequestsQuery): Promise<string> {\n const response = await this.httpClient.requestStream(\n 'GET',\n `/organizations/${organizationId}/ai-gateway/usage/export`,\n { query: query as Record<string, string | number | undefined> | undefined }\n );\n return response.text();\n }\n}\n\n/** AI Gateway budgets for an organization. */\nexport class AiGatewayBudgetsResource extends BaseResource {\n /** List all budgets for an organization. */\n async list(organizationId: string): Promise<{ items: AiGatewayBudget[] }> {\n return this.httpClient.get(`/organizations/${organizationId}/ai-gateway/budgets`);\n }\n\n /**\n * Replace the organization's entire budget set. Pass an empty array to clear\n * all budgets.\n */\n async replace(organizationId: string, budgets: AiGatewayBudgetInput[]): Promise<{ items: AiGatewayBudget[] }> {\n return this.httpClient.put(`/organizations/${organizationId}/ai-gateway/budgets`, { budgets });\n }\n}\n\n/** AI Gateway governance policies for an organization. */\nexport class AiGatewayPoliciesResource extends BaseResource {\n /**\n * Get the governance policy for an organization, or for a specific\n * application when `applicationId` is provided. Returns `null` if no policy is set.\n */\n async get(organizationId: string, options?: { applicationId?: string }): Promise<AiGatewayPolicy | null> {\n const { policy } = await this.httpClient.get<{ policy: AiGatewayPolicy | null }>(\n `/organizations/${organizationId}/ai-gateway/policies`,\n { query: { applicationId: options?.applicationId } }\n );\n return policy;\n }\n\n /** Create or update an AI Gateway policy. */\n async put(organizationId: string, data: AiGatewayPolicyInput): Promise<AiGatewayPolicy> {\n const { policy } = await this.httpClient.put<{ policy: AiGatewayPolicy }>(\n `/organizations/${organizationId}/ai-gateway/policies`,\n data\n );\n return policy;\n }\n}\n\n/**\n * Organization-scoped AI Gateway governance: usage analytics, budgets, and\n * model/provider policies. Accessed via `client.organizations.aiGateway`.\n */\nexport class OrganizationAiGatewayResource {\n /** Usage analytics (summary, request log, CSV export). */\n readonly usage: AiGatewayUsageResource;\n /** Spend/usage budgets. */\n readonly budgets: AiGatewayBudgetsResource;\n /** Model/provider governance policies. */\n readonly policies: AiGatewayPoliciesResource;\n\n constructor(httpClient: HttpClient) {\n this.usage = new AiGatewayUsageResource(httpClient);\n this.budgets = new AiGatewayBudgetsResource(httpClient);\n this.policies = new AiGatewayPoliciesResource(httpClient);\n }\n}\n","import type { ListQuery, Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\nimport type { CreateEnvVarInput, EnvVar, UpdateEnvVarInput } from './env-vars';\n\n/**\n * Manage environment variables scoped to an organization.\n * Accessed via `client.organizations.envVars`.\n */\nexport class OrganizationEnvVarsResource extends BaseResource {\n /**\n * List all environment variables for an organization.\n *\n * @param organizationId - The organization ID (UUID).\n * @returns A paginated list of environment variables.\n *\n * @example\n * ```ts\n * const { items } = await client.organizations.envVars.list('org-id');\n * for (const v of items) {\n * console.log(`${v.key}=${v.sensitive ? '***' : v.value}`);\n * }\n * ```\n */\n async list(organizationId: string, query?: ListQuery): Promise<Paginated<EnvVar>> {\n return this.httpClient.get(`/organizations/${organizationId}/env-vars`, {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n\n /**\n * Create a new environment variable for an organization.\n *\n * @param organizationId - The organization ID (UUID).\n * @param data - The variable key, value, and optional settings.\n * @returns The newly created environment variable.\n *\n * @example\n * ```ts\n * const envVar = await client.organizations.envVars.create('org-id', {\n * key: 'STRIPE_SECRET',\n * value: 'sk_live_...',\n * sensitive: true,\n * });\n * ```\n */\n async create(organizationId: string, data: CreateEnvVarInput): Promise<EnvVar> {\n return this.httpClient.post(`/organizations/${organizationId}/env-vars`, data);\n }\n\n /**\n * Update an existing environment variable. Only the fields you provide\n * will be changed; omitted fields are left unchanged.\n *\n * @param organizationId - The organization ID (UUID).\n * @param envVarId - The environment variable ID (UUID).\n * @param data - The fields to update.\n * @returns The updated environment variable.\n *\n * @example\n * ```ts\n * await client.organizations.envVars.update('org-id', 'var-id', {\n * value: 'new-value',\n * });\n * ```\n */\n async update(organizationId: string, envVarId: string, data: UpdateEnvVarInput): Promise<EnvVar> {\n return this.httpClient.patch(`/organizations/${organizationId}/env-vars/${envVarId}`, data);\n }\n\n /**\n * Permanently delete an environment variable.\n *\n * @param organizationId - The organization ID (UUID).\n * @param envVarId - The environment variable ID (UUID).\n *\n * @example\n * ```ts\n * await client.organizations.envVars.delete('org-id', 'var-id');\n * ```\n */\n async delete(organizationId: string, envVarId: string): Promise<void> {\n return this.httpClient.delete(`/organizations/${organizationId}/env-vars/${envVarId}`);\n }\n}\n","import type { ListQuery, Paginated } from '../http-client';\nimport { BaseResource } from './base-resource';\nimport { OrganizationAiGatewayResource } from './organization-ai-gateway';\nimport { OrganizationEnvVarsResource } from './organization-env-vars';\n\n/** A Gigadrive Network organization. */\nexport interface Organization {\n /** Unique identifier (UUID). */\n id: string;\n /** Display name of the organization. */\n name: string;\n /** URL-safe slug (e.g. `gigadrive`). */\n slug: string;\n /** Avatar / logo URL. */\n imageUrl: string;\n /** ISO 8601 creation timestamp. */\n createdAt: string;\n /** ISO 8601 last-updated timestamp. */\n updatedAt: string;\n}\n\n/**\n * Manage organizations. Accessed via {@link GigadriveClient.organizations}.\n *\n * @example\n * ```ts\n * const { items: orgs } = await client.organizations.list();\n * console.log(orgs.map((o) => o.name));\n * ```\n */\nexport class OrganizationsResource extends BaseResource {\n /**\n * Manage environment variables scoped to an organization.\n *\n * @example\n * ```ts\n * // List all env vars for an organization\n * const { items } = await client.organizations.envVars.list('org-id');\n *\n * // Create a new env var\n * await client.organizations.envVars.create('org-id', {\n * key: 'ANALYTICS_KEY',\n * value: 'ak_live_...',\n * sensitive: true,\n * });\n * ```\n */\n readonly envVars: OrganizationEnvVarsResource;\n\n /**\n * AI Gateway governance for an organization: usage analytics, budgets, and\n * model/provider policies.\n *\n * @example\n * ```ts\n * const usage = await client.organizations.aiGateway.usage.summary('org-id', { from: '2026-06-01' });\n * console.log(usage.summary.totalTokens);\n * ```\n */\n readonly aiGateway: OrganizationAiGatewayResource;\n\n constructor(...args: ConstructorParameters<typeof BaseResource>) {\n super(...args);\n this.envVars = new OrganizationEnvVarsResource(this.httpClient);\n this.aiGateway = new OrganizationAiGatewayResource(this.httpClient);\n }\n\n /**\n * List organizations the authenticated actor has access to.\n *\n * @param query - Optional pagination.\n * @returns A paginated list of organizations.\n *\n * @example\n * ```ts\n * const { items, total } = await client.organizations.list();\n * console.log(`Found ${total} organizations`);\n * ```\n */\n async list(query?: ListQuery): Promise<Paginated<Organization>> {\n return this.httpClient.get('/organizations', {\n query: query as Record<string, string | number | undefined> | undefined,\n });\n }\n}\n","import { readEnv, resolveCredentialProvider } from './auth/credential-provider';\nimport { TokenManager } from './auth/token-manager';\nimport { HttpClient } from './http-client';\nimport { AiGatewayResource } from './resources/ai-gateway';\nimport { ApplicationsResource } from './resources/applications';\nimport { DeploymentsResource } from './resources/deployments';\nimport { OrganizationsResource } from './resources/organizations';\n\nconst DEFAULT_BASE_URL = 'https://api.gigadrive.network';\n\n/**\n * Configuration for the {@link GigadriveClient}.\n *\n * Credentials are resolved in priority order: explicit config fields first,\n * then environment variables. See {@link GigadriveClient} for the full\n * resolution chain.\n */\nexport interface GigadriveClientConfig {\n /**\n * OAuth2 client ID (the API key ID from the Gigadrive dashboard).\n * Used for both client-credentials and refresh-token flows.\n * Falls back to the `GIGADRIVE_CLIENT_ID` environment variable.\n */\n clientId?: string;\n\n /**\n * OAuth2 client secret (the API key secret from the Gigadrive dashboard).\n * Used together with {@link clientId} for the client-credentials grant.\n * Falls back to the `GIGADRIVE_CLIENT_SECRET` environment variable.\n */\n clientSecret?: string;\n\n /**\n * A pre-obtained bearer token (either an IDP or Network token).\n * When set, the SDK sends this token directly without any OAuth exchange.\n * The token is never refreshed — if it expires, requests will fail.\n * Falls back to the `GIGADRIVE_BEARER_TOKEN` environment variable.\n */\n bearerToken?: string;\n\n /**\n * An IDP refresh token for automatic access-token renewal. Used together\n * with {@link clientId}. The SDK will exchange this for short-lived access\n * tokens and handle refresh-token rotation automatically.\n * Falls back to the `GIGADRIVE_REFRESH_TOKEN` environment variable.\n */\n refreshToken?: string;\n\n /**\n * The IDP issuer URL used for OIDC discovery (fetching the\n * `.well-known/openid-configuration`). Only needed for refresh-token and\n * authorization-code flows.\n * Falls back to `GIGADRIVE_IDP_ISSUER_URL`, default: `https://idp.gigadrive.de`.\n */\n idpIssuerUrl?: string;\n\n /**\n * Callback for the OAuth2 authorization code flow with PKCE. The SDK\n * builds the authorization URL and passes it to this callback. Your code\n * must present the URL to the user (e.g. open a browser), then return\n * either the full redirect URL or just the authorization code.\n *\n * Requires {@link clientId} to be set.\n *\n * @param url - The authorization URL the user should visit.\n * @returns The full redirect URL (including `?code=...&state=...`) or the\n * bare authorization code.\n *\n * @example\n * ```ts\n * const client = new GigadriveClient({\n * clientId: 'my-app',\n * onAuthorizationUrl: async (url) => {\n * console.log('Visit:', url);\n * return await readline.question('Paste the redirect URL: ');\n * },\n * });\n * ```\n */\n onAuthorizationUrl?: (url: string) => Promise<string>;\n\n /**\n * Redirect URI for the authorization code flow.\n * Default: `urn:ietf:wg:oauth:2.0:oob` (out-of-band / manual copy-paste).\n */\n redirectUri?: string;\n\n /**\n * OAuth scopes to request during the authorization-code flow, in addition to\n * the default identity scopes (`openid profile email offline_access`). Use\n * this to request API capability scopes (e.g. `network:applications:read`) so\n * the resulting token can call the corresponding endpoints.\n */\n scopes?: string[];\n\n /**\n * Base URL of the Gigadrive Network API.\n * Falls back to `GIGADRIVE_API_BASE_URL`, default: `https://api.gigadrive.network`.\n */\n baseUrl?: string;\n\n /**\n * Custom `fetch` implementation. Useful for testing (injectable mock) or\n * non-standard runtimes like Cloudflare Workers that provide their own\n * `fetch`. Defaults to `globalThis.fetch`.\n */\n fetch?: typeof globalThis.fetch;\n}\n\n/**\n * The main entry point for the Gigadrive Network SDK.\n *\n * Create an instance to interact with organizations, applications, deployments,\n * storage, and the AI gateway. Authentication is handled automatically —\n * tokens are obtained, cached, and refreshed behind the scenes.\n *\n * ## Credential resolution order\n *\n * The client resolves credentials in the following order, using the first\n * match it finds:\n *\n * 1. Explicit `bearerToken` in config\n * 2. Explicit `clientId` + `clientSecret` in config\n * 3. Explicit `clientId` + `refreshToken` in config\n * 4. Explicit `clientId` + `onAuthorizationUrl` callback in config\n * 5. `GIGADRIVE_BEARER_TOKEN` environment variable\n * 6. `GIGADRIVE_CLIENT_ID` + `GIGADRIVE_CLIENT_SECRET` environment variables\n * 7. `GIGADRIVE_CLIENT_ID` + `GIGADRIVE_REFRESH_TOKEN` environment variables\n *\n * If no credentials are found, the constructor throws an\n * {@link AuthenticationError}.\n *\n * @example\n * ```ts\n * // Credentials auto-detected from environment variables\n * const client = new GigadriveClient();\n *\n * // Explicit API key (client credentials)\n * const client = new GigadriveClient({\n * clientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',\n * clientSecret: 'sk_live_...',\n * });\n *\n * // Pre-obtained bearer token\n * const client = new GigadriveClient({ bearerToken: 'eyJ...' });\n *\n * // IDP refresh token — access tokens are renewed automatically\n * const client = new GigadriveClient({\n * clientId: 'my-app',\n * refreshToken: 'rt_...',\n * });\n *\n * // Use the client\n * const orgs = await client.organizations.list();\n * const deployment = await client.deployments.create({ applicationId: 'app-1' });\n * ```\n *\n * @throws {@link AuthenticationError} if no valid credentials are found.\n */\nexport class GigadriveClient {\n /** Organization management (list, environment variables). */\n readonly organizations: OrganizationsResource;\n /** Application management (list, environment variables, storage). */\n readonly applications: ApplicationsResource;\n /** Deployment lifecycle (create, upload, status, logs). */\n readonly deployments: DeploymentsResource;\n /** AI Gateway — OpenAI-compatible chat completions and model listing. */\n readonly aiGateway: AiGatewayResource;\n\n constructor(config: GigadriveClientConfig = {}) {\n const baseUrl = config.baseUrl ?? readEnv('GIGADRIVE_API_BASE_URL') ?? DEFAULT_BASE_URL;\n // Bind the default fetch to globalThis so it can be invoked as a method on\n // the HTTP client without throwing \"Illegal invocation\" in some runtimes.\n const fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);\n\n const credentialProvider = resolveCredentialProvider({ ...config, baseUrl, fetch: fetchFn });\n const tokenManager = new TokenManager(credentialProvider);\n const httpClient = new HttpClient(baseUrl, tokenManager, fetchFn);\n\n this.organizations = new OrganizationsResource(httpClient);\n this.applications = new ApplicationsResource(httpClient);\n this.deployments = new DeploymentsResource(httpClient);\n this.aiGateway = new AiGatewayResource(httpClient);\n }\n}\n","import type { Paginated } from './http-client';\n\n/**\n * Lazily iterate every item across all pages of a cursor-paginated endpoint.\n * Pass a function that fetches one page for a given cursor; iteration stops when\n * the API stops returning a `nextCursor`.\n *\n * @typeParam T - The item type.\n * @param fetchPage - Fetches a single page for the given cursor (`undefined` for the first page).\n *\n * @example\n * ```ts\n * for await (const object of paginate((cursor) =>\n * client.applications.storage.objects.list('app-id', 'bucket-id', { cursor }),\n * )) {\n * console.log(object.key);\n * }\n * ```\n */\nexport async function* paginate<T>(\n fetchPage: (cursor: string | undefined) => Promise<Paginated<T>>\n): AsyncGenerator<T> {\n let cursor: string | undefined;\n do {\n const page = await fetchPage(cursor);\n for (const item of page.items) {\n yield item;\n }\n cursor = page.nextCursor;\n } while (cursor);\n}\n"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AAK,UAAU;AAEhE,UAAM,qBAAqB,0BAA0B,EAAE,GAAG,QAAQ,SAAS,OAAO,QAAQ,CAAC;AAC3F,UAAM,eAAe,IAAI,aAAa,kBAAkB;AACxD,UAAM,aAAa,IAAI,WAAW,SAAS,cAAc,OAAO;AAEhE,SAAK,gBAAgB,IAAI,sBAAsB,UAAU;AACzD,SAAK,eAAe,IAAI,qBAAqB,UAAU;AACvD,SAAK,cAAc,IAAI,oBAAoB,UAAU;AACrD,SAAK,YAAY,IAAI,kBAAkB,UAAU;AAAA,EACnD;AACF;;;ACrKA,gBAAuB,SACrB,WACmB;AACnB,MAAI;AACJ,KAAG;AACD,UAAM,OAAO,MAAM,UAAU,MAAM;AACnC,eAAW,QAAQ,KAAK,OAAO;AAC7B,YAAM;AAAA,IACR;AACA,aAAS,KAAK;AAAA,EAChB,SAAS;AACX;","names":["DEFAULT_BASE_URL"]}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@gigadrive/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
- "url": "https://github.com/Gigadrive/sdk.git"
6
+ "url": "https://github.com/Gigadrive/sdk.git",
7
+ "directory": "packages/sdk"
7
8
  },
8
9
  "license": "Apache-2.0",
9
10
  "author": "Gigadrive <business@gigadrivegroup.com> (https://gigadrive.de)",
@@ -20,8 +21,11 @@
20
21
  "files": [
21
22
  "dist"
22
23
  ],
24
+ "dependencies": {
25
+ "tus-js-client": "^4.3.1"
26
+ },
23
27
  "devDependencies": {
24
- "esbuild": "^0.25.0"
28
+ "esbuild": "^0.28.0"
25
29
  },
26
30
  "engines": {
27
31
  "node": ">=18.0.0"
@@ -31,6 +35,7 @@
31
35
  },
32
36
  "scripts": {
33
37
  "build": "tsup",
34
- "clean": "rm -rf dist"
38
+ "clean": "rm -rf dist",
39
+ "typecheck": "tsc --noEmit"
35
40
  }
36
41
  }