API Types
Request/response patterns, pagination, authentication tokens, and API errors.
TypeScript type definitions that power the entire Varity SDK ecosystem. These types provide auto-completion, compile-time validation, and clear documentation for all Varity APIs.
npm install @varity-labs/typespnpm add @varity-labs/typesyarn add @varity-labs/typesThis package provides TypeScript interfaces and types for:
API Types
Request/response patterns, pagination, authentication tokens, and API errors.
Storage Types
Multi-tier storage configuration, upload options, file metadata, and cost tracking.
Authentication Types
Access keys, permissions, sessions, and policy management.
Varity L3 Types
Chain configuration, wallet setup, contract interactions, and gas estimation.
Type-safe alternatives to any that improve code quality:
import type { JSONValue, // Any JSON-serializable value JSONObject, // Object with JSON values Metadata, // Key-value pairs for custom data Nullable, // T | null Optional, // T | undefined DeepPartial, // Make all nested properties optional} from '@varity-labs/types';Standard patterns for API communication:
import type { APIResponse, // Standard response wrapper APIError, // Error response format PaginatedResponse, // Paginated list results AuthToken, // JWT/session tokens UserProfile, // User account data} from '@varity-labs/types';Configure file uploads, downloads, and multi-tier storage:
import type { UploadOptions, // File upload configuration StorageResult, // Upload result with URL StorageItem, // File listing item StorageMetrics, // Usage statistics} from '@varity-labs/types';
import { StorageBackend, // filecoin-ipfs, s3-compatible, etc. StorageTier, // hot, warm, cold, glacier StorageLayer, // varity-internal, industry-rag, customer-data} from '@varity-labs/types';Manage access control and permissions:
import type { AccessKey, // API key credentials Permission, // Resource permissions Session, // User session data} from '@varity-labs/types';
import { AuthProvider, // aws-signature-v4, gcs-oauth2, browser-wallet PermissionEffect, // allow, deny Action, // storage:GetObject, admin:ViewMetrics, etc.} from '@varity-labs/types';Types for interacting with the Varity L3 network are currently available via the SDK subpath import rather than the types package:
// Chain types and USDC utilities are available from the SDK:import { varityL3Testnet, USDC_DECIMALS, formatUSDC, parseUSDC,} from '@varity-labs/sdk/chains';import { formatUSDC, parseUSDC, USDC_DECIMALS } from '@varity-labs/sdk/chains';
// Convert human-readable to raw (for transactions)const amount = parseUSDC("10.50");// Returns: 10500000n (bigint)
// Convert raw to human-readable (for display)const display = formatUSDC(10500000n);// Returns: "10.50" (string)
// Always use the constant for decimalsconst scale = 10 ** USDC_DECIMALS; // 1,000,000Type-safe error handling in catch blocks:
import { toError, getErrorMessage, isErrorWithMessage } from '@varity-labs/types';
try { await riskyOperation();} catch (error) { // Convert unknown error to Error instance const safeError = toError(error);
// Or just get the message const message = getErrorMessage(error);
// Type guard for error checking if (isErrorWithMessage(error)) { console.log(error.message); // TypeScript knows this is safe }}Runtime type validation with TypeScript inference:
import { isAWSSignatureV4Credentials, isGCSServiceAccount,} from '@varity-labs/types';
// Validate AWS credentials at runtimeif (isAWSSignatureV4Credentials(creds)) { // TypeScript knows creds has accessKeyId, secretAccessKey, region console.log(creds.accessKeyId);}
// Validate GCS service accountif (isGCSServiceAccount(account)) { // TypeScript knows account has project_id, client_email, etc. console.log(account.project_id);}import { VERSION, PACKAGE_NAME } from '@varity-labs/types';
console.log(VERSION); // "2.0.0-beta.2"console.log(PACKAGE_NAME); // "@varity-labs/types"