or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api.mdcompiler.mdindex.mdruntime.md
tile.json

api.mddocs/

API Adaptation

Complete uni API implementation with Alipay-specific adaptations, protocol mappings, and compatibility shims for seamless cross-platform development. This module provides a unified API surface that works consistently across different mini program platforms.

Capabilities

Core API Initialization

The main API export provides a complete uni API instance configured for Alipay Mini Program.

/**
 * Complete uni API configured with Alipay-specific shims and protocols
 * Provides unified interface for mini program APIs across platforms
 */
declare const uni: UniAPI;

/**
 * Initializes uni API with platform-specific adaptations
 * @param shims - Platform-specific API implementations
 * @param protocols - API protocol adaptations and mappings
 * @returns Configured uni API instance
 */
declare function initUni(shims: any, protocols: any): UniAPI;

Storage APIs

Synchronous storage operations adapted for Alipay Mini Program format.

/**
 * Sets storage data synchronously using Alipay API
 * @param key - Storage key
 * @param data - Data to store (any serializable type)
 */
function setStorageSync(key: string, data: any): void;

/**
 * Gets storage data synchronously with Alipay-specific handling
 * Returns empty string when data is null (cross-platform consistency)
 * @param key - Storage key
 * @returns Stored data or empty string if not found
 */
function getStorageSync(key: string): any;

/**
 * Removes storage data synchronously
 * @param key - Storage key to remove
 */
function removeStorageSync(key: string): void;

Usage Example:

// Store user preferences
uni.setStorageSync('userPrefs', {
  theme: 'dark',
  language: 'zh-CN'
});

// Retrieve preferences
const prefs = uni.getStorageSync('userPrefs');
console.log(prefs.theme); // 'dark'

// Remove when no longer needed
uni.removeStorageSync('userPrefs');

Provider APIs

Query available service providers for different functionality areas.

/**
 * Gets available providers for specified service types
 * Configured for Alipay's supported services
 * @param service - Service type to query
 * @returns Provider information
 */
declare function getProvider(service: ProviderService): ProviderResult;

type ProviderService = 'oauth' | 'share' | 'payment' | 'push';

interface ProviderResult {
  service: ProviderService;
  provider: string[];
}

For Alipay Mini Program, all services return ['alipay'] as the provider.

Network APIs

HTTP request functionality with Alipay/DingTalk compatibility adaptations.

/**
 * Makes HTTP requests with platform-specific adaptations
 * Handles differences between Alipay and DingTalk environments
 */
interface RequestOptions {
  /** Request URL */
  url: string;
  /** HTTP method */
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
  /** Request data */
  data?: any;
  /** Request headers */
  header?: Record<string, string>;
  /** Success callback */
  success?: (result: RequestSuccessResult) => void;
  /** Failure callback */
  fail?: (error: any) => void;
  /** Completion callback */
  complete?: () => void;
}

interface RequestSuccessResult {
  /** Response data */
  data: any;
  /** HTTP status code */
  statusCode: number;
  /** Response headers */
  header: Record<string, string>;
}

Usage Example:

uni.request({
  url: 'https://api.example.com/users',
  method: 'POST',
  data: { name: 'Alice', email: 'alice@example.com' },
  header: {
    'Content-Type': 'application/json'
  },
  success: (res) => {
    console.log('User created:', res.data);
  },
  fail: (err) => {
    console.error('Request failed:', err);
  }
});

UI APIs

User interface components and interactions adapted for Alipay Mini Program.

/**
 * Shows modal dialog with Alipay/DingTalk compatibility
 * Falls back to confirm/alert for DingTalk environment
 */
interface ShowModalOptions {
  /** Modal title */
  title?: string;
  /** Modal content */
  content?: string;
  /** Show cancel button */
  showCancel?: boolean;
  /** Cancel button text */
  cancelText?: string;
  /** Confirm button text */
  confirmText?: string;
  /** Success callback */
  success?: (result: ShowModalResult) => void;
}

interface ShowModalResult {
  /** User confirmed */
  confirm: boolean;
  /** User cancelled */
  cancel: boolean;
}

/**
 * Shows toast message or loading indicator
 */
interface ShowToastOptions {
  /** Toast title/message */
  title: string;
  /** Toast icon type */
  icon?: 'success' | 'loading' | 'none';
  /** Duration in milliseconds */
  duration?: number;
}

/**
 * Shows action sheet with item selection
 */
interface ShowActionSheetOptions {
  /** List of action items */
  itemList: string[];
  /** Success callback */
  success?: (result: { tapIndex: number }) => void;
}

/**
 * Shows loading indicator with optional mask
 */
interface ShowLoadingOptions {
  /** Loading title */
  title: string;
  /** Show mask overlay */
  mask?: boolean;
}

Usage Examples:

// Show confirmation dialog
uni.showModal({
  title: 'Confirm Delete',
  content: 'Are you sure you want to delete this item?',
  success: (res) => {
    if (res.confirm) {
      // User confirmed
      deleteItem();
    }
  }
});

// Show success toast
uni.showToast({
  title: 'Saved successfully',
  icon: 'success',
  duration: 2000
});

// Show action sheet
uni.showActionSheet({
  itemList: ['Camera', 'Album', 'Cancel'],
  success: (res) => {
    if (res.tapIndex === 0) {
      // Camera selected
    } else if (res.tapIndex === 1) {
      // Album selected
    }
  }
});

File APIs

File operations with Alipay-specific path and parameter mappings.

/**
 * Uploads files with parameter mapping for Alipay
 */
interface UploadFileOptions {
  /** Upload URL */
  url: string;
  /** Local file path */
  filePath: string;
  /** File parameter name (mapped to 'fileName' for Alipay) */
  name: string;
  /** Additional form data */
  formData?: Record<string, any>;
  /** Success callback */
  success?: (result: UploadFileResult) => void;
}

/**
 * Downloads files with Alipay path mapping
 */
interface DownloadFileOptions {
  /** Download URL */
  url: string;
  /** Success callback */
  success?: (result: { tempFilePath: string }) => void;
}

/**
 * Compresses images with quality mapping for Alipay
 */
interface CompressImageOptions {
  /** Source image path */
  src: string;
  /** Compression quality (0-100, mapped to Alipay's levels) */
  quality?: number;
  /** Success callback */
  success?: (result: { tempFilePath: string }) => void;
}

/**
 * Chooses images from camera or album
 */
interface ChooseImageOptions {
  /** Maximum number of images */
  count?: number;
  /** Image size type */
  sizeType?: string[];
  /** Image source type */
  sourceType?: string[];
  /** Success callback */
  success?: (result: ChooseImageResult) => void;
}

interface ChooseImageResult {
  /** Temporary file paths */
  tempFilePaths: string[];
  /** File objects */
  tempFiles: Array<{ path: string }>;
}

Device APIs

Device information and control APIs with Alipay adaptations.

/**
 * Gets system information with Alipay-specific adaptations
 * Includes platform detection, safe area handling, and screen size corrections
 */
interface GetSystemInfoOptions {
  success?: (result: SystemInfo) => void;
  fail?: (error: any) => void;
}

interface SystemInfo {
  /** System name */
  system: string;
  /** Platform identifier */
  platform: string;
  /** Device model */
  model: string;
  /** Screen width */
  screenWidth: number;
  /** Screen height */
  screenHeight: number;
  /** Window width */
  windowWidth: number;
  /** Window height */
  windowHeight: number;
  /** Status bar height */
  statusBarHeight: number;
  /** Safe area information */
  safeArea: SafeArea;
  /** Device pixel ratio */
  pixelRatio: number;
}

interface SafeArea {
  left: number;
  right: number;
  top: number;
  bottom: number;
  width: number;
  height: number;
}

/**
 * Gets system information synchronously
 */
function getSystemInfoSync(): SystemInfo;

/**
 * Sets screen brightness (0-1)
 */
function setScreenBrightness(options: { value: number }): void;

/**
 * Gets current screen brightness
 */
function getScreenBrightness(options: {
  success?: (result: { value: number }) => void;
}): void;

Location APIs

Location services with Alipay-specific parameter handling.

/**
 * Gets current device location
 * Filters out unsupported parameters for Alipay
 */
interface GetLocationOptions {
  /** Coordinate system type (ignored for Alipay) */
  type?: string;
  /** Include altitude (ignored for Alipay) */
  altitude?: boolean;
  /** Success callback */
  success?: (result: LocationResult) => void;
}

interface LocationResult {
  /** Latitude */
  latitude: number;
  /** Longitude */
  longitude: number;
  /** Location accuracy */
  accuracy: number;
}

/**
 * Opens location on map with default scale handling
 */
interface OpenLocationOptions {
  /** Latitude */
  latitude: number;
  /** Longitude */
  longitude: number;
  /** Map scale (defaults to 18 for Alipay) */
  scale?: number;
  /** Location name */
  name?: string;
  /** Address description */
  address?: string;
}

Sensor APIs

Device sensor access with callback-based event handling.

/**
 * Starts gyroscope monitoring
 * Provides success callbacks for Alipay compatibility
 */
interface StartGyroscopeOptions {
  /** Success callback */
  success?: (result: { errMsg: string }) => void;
  /** Completion callback */
  complete?: (result: { errMsg: string }) => void;
}

function startGyroscope(options: StartGyroscopeOptions): void;

/**
 * Stops gyroscope monitoring
 */
function stopGyroscope(): void;

/**
 * Stops accelerometer monitoring
 */
function stopAccelerometer(): void;

/**
 * Stops compass monitoring
 */
function stopCompass(): void;

Selector Query APIs

DOM query functionality with Alipay-specific enhancements.

/**
 * Creates enhanced selector query with Alipay adaptations
 * Adds missing methods and improves callback handling
 */
function createSelectorQuery(): SelectorQuery;

interface SelectorQuery {
  /** Execute query with enhanced callback support */
  exec(callback?: Function): any;
  /** Get scroll offset with callback support */
  scrollOffset(callback?: Function): SelectorQuery;
  /** Get bounding client rect with callback support */
  boundingClientRect(callback?: Function): SelectorQuery;
  /** Get node fields (added for compatibility) */
  fields(fields: NodeField, callback?: Function): SelectorQuery;
  /** Set query context (added for compatibility) */
  in(): SelectorQuery;
}

interface NodeField {
  /** Include rect information */
  rect?: boolean;
  /** Include size information */
  size?: boolean;
  /** Include scroll offset */
  scrollOffset?: boolean;
}

/**
 * Creates intersection observer with Alipay adaptations
 */
function createIntersectionObserver(
  component: any,
  options?: IntersectionObserverOptions
): IntersectionObserver;

interface IntersectionObserverOptions {
  /** Observe all matching elements (mapped to selectAll) */
  observeAll?: boolean;
}

Keyboard APIs

Keyboard height monitoring with unified event handling.

/**
 * Monitors keyboard height changes
 * Maintains single listener consistency across platforms
 */
function onKeyboardHeightChange(callback: (result: KeyboardHeightResult) => void): void;

/**
 * Removes keyboard height change listener
 */
function offKeyboardHeightChange(): void;

interface KeyboardHeightResult {
  /** Keyboard height in pixels */
  height: number;
}

User APIs

User authentication and information access.

/**
 * User login with auth code (Alipay-specific)
 */
interface LoginOptions {
  /** Success callback */
  success?: (result: { code: string }) => void;
  /** Failure callback */
  fail?: (error: any) => void;
}

/**
 * Gets user information with OpenUserInfo fallback
 */
interface GetUserInfoOptions {
  /** Success callback */
  success?: (result: UserInfoResult) => void;
  /** Failure callback */
  fail?: (error: any) => void;
}

interface UserInfoResult {
  userInfo: {
    /** User open ID */
    openId: string;
    /** User nickname */
    nickName: string;
    /** User avatar URL */
    avatarUrl: string;
  };
}

Payment APIs

Payment functionality using Alipay's trade system.

/**
 * Requests payment via Alipay trade system
 */
interface RequestPaymentOptions {
  /** Trade order info (mapped to tradeNO) */
  orderInfo: string;
  /** Success callback */
  success?: () => void;
  /** Failure callback */
  fail?: (error: any) => void;
}

Protocol Adaptation

The API system includes comprehensive protocol adaptation for cross-platform compatibility:

/**
 * Normalizes API response formats across platforms
 * @param methodName - API method name
 * @param res - Platform-specific response
 * @returns Normalized response
 */
function returnValue(methodName: string, res?: Record<string, any>): any;

This ensures consistent error messaging and response formats across different mini program platforms, with automatic errMsg generation and error field normalization.