CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-dcloudio--uni-mp-toutiao

This package is the uni-app Toutiao (ByteDance) mini-program support module that enables developers to compile and deploy uni-app applications to the Toutiao mini-program platform.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

api-integration.mddocs/

API Integration

Seamless API integration that bridges uni-app's universal APIs with Toutiao's platform-specific implementations through protocols and shims, ensuring consistent behavior across platforms.

Capabilities

Runtime Initialization

The API module automatically initializes uni-app runtime with Toutiao-specific API adaptations and platform configurations. The module exports the result of initialization, not the function itself.

/**
 * Pre-initialized uni-app runtime with Toutiao-specific shims and protocols
 * This is the default export from the API module
 */
declare const initUni: any;

Usage Example:

import initUni from "@dcloudio/uni-mp-toutiao/api";

// No need to call initUni() - it's already initialized
// The import automatically sets up API mappings and platform-specific behavior

// uni-app APIs are now ready to work with Toutiao platform
uni.login({ success: console.log });

Navigation APIs

Platform-adapted navigation functions that handle Toutiao-specific routing and page management.

interface NavigationProtocols {
  /** Navigate to a new page */
  navigateTo: (options: NavigateToOptions) => void;
  /** Redirect to a page, closing current page */
  redirectTo: (options: RedirectToOptions) => void;
  /** Preview images with Toutiao-specific options */
  previewImage: (options: PreviewImageOptions) => void;
}

interface NavigateToOptions {
  url: string;
  success?: () => void;
  fail?: (error: any) => void;
}

interface RedirectToOptions {
  url: string;
  success?: () => void;
  fail?: (error: any) => void;
}

interface PreviewImageOptions {
  urls: string[];
  current?: string;
  success?: () => void;
  fail?: (error: any) => void;
}

System Information APIs

System and device information APIs adapted for Toutiao platform capabilities.

interface SystemProtocols {
  /** Get system information asynchronously */
  getSystemInfo: (options: SystemInfoOptions) => void;
  /** Get system information synchronously */
  getSystemInfoSync: () => SystemInfo;
  /** Get base system information via tt.getSystemInfoSync() */
  getBaseSystemInfo: () => BaseSystemInfo;
}

interface SystemInfoOptions {
  success?: (result: SystemInfo) => void;
  fail?: (error: any) => void;
}

interface SystemInfo {
  brand: string;
  model: string;
  pixelRatio: number;
  screenWidth: number;
  screenHeight: number;
  windowWidth: number;
  windowHeight: number;
  statusBarHeight: number;
  language: string;
  version: string;
  system: string;
  platform: string;
  SDKVersion: string;
}

interface BaseSystemInfo {
  platform: string;
  system: string;
  version: string;
}

Device APIs

Device-specific functionality with Toutiao platform adaptations and limitations.

interface DeviceProtocols {
  /** Start accelerometer with interval configuration */
  startAccelerometer: (options: AccelerometerOptions) => void;
  /** Scan QR/barcodes (excludes onlyFromCamera and scanType) */
  scanCode: (options: ScanCodeOptions) => void;
  /** Connect WebSocket (method parameter not supported) */
  connectSocket: (options: SocketOptions) => void;
}

interface AccelerometerOptions {
  interval?: 'game' | 'ui' | 'normal';
  success?: () => void;
  fail?: (error: any) => void;
}

interface ScanCodeOptions {
  success?: (result: ScanResult) => void;
  fail?: (error: any) => void;
  // Note: onlyFromCamera and scanType not supported on Toutiao
}

interface ScanResult {
  result: string;
  scanType: string;
  charSet: string;
  path: string;
}

interface SocketOptions {
  url: string;
  protocols?: string[];
  success?: () => void;
  fail?: (error: any) => void;
  // Note: method parameter not supported on Toutiao
}

User Authentication APIs

User authentication and information APIs with Toutiao-specific parameters and scopes.

interface UserProtocols {
  /** User login with scopes and timeout options */
  login: (options: LoginOptions) => void;
  /** Get user information with language and timeout options */
  getUserInfo: (options: UserInfoOptions) => void;
}

interface LoginOptions {
  scopes?: string[];
  timeout?: number;
  success?: (result: LoginResult) => void;
  fail?: (error: any) => void;
}

interface LoginResult {
  code: string;
  anonymousCode?: string;
}

interface UserInfoOptions {
  withCredentials?: boolean;
  lang?: string;
  timeout?: number;
  success?: (result: UserInfo) => void;
  fail?: (error: any) => void;
}

interface UserInfo {
  userInfo: {
    nickName: string;
    avatarUrl: string;
    gender: number;
    city: string;
    province: string;
    country: string;
    language: string;
  };
  rawData: string;
  signature: string;
  encryptedData: string;
  iv: string;
}

Payment APIs

Payment processing with dynamic method mapping for Toutiao platform variations.

interface PaymentProtocols {
  /** Payment processing with dynamic method mapping */
  requestPayment: PaymentProtocol;
}

interface PaymentProtocol {
  /** Dynamic method name: 'pay' if tt.pay exists, otherwise 'requestPayment' */
  name: string;
  args: {
    /** Parameter mapping: 'orderInfo' if using tt.pay, 'data' if using fallback */
    orderInfo: string;
  };
}

interface PaymentOptions {
  /** Payment data (maps to 'data' when using fallback) */
  orderInfo?: string;
  /** Alternative payment data field */
  data?: string;
  success?: (result: PaymentResult) => void;
  fail?: (error: any) => void;
}

interface PaymentResult {
  [key: string]: any;
}

Protocol Implementation:

// Actual protocol configuration
const requestPayment = {
  name: tt.pay ? 'pay' : 'requestPayment',
  args: {
    orderInfo: tt.pay ? 'orderInfo' : 'data',
  },
};

Note: Uses tt.pay if available, otherwise falls back to requestPayment. When using fallback, orderInfo parameter is mapped to data.

Error Handling APIs

Global error event management for application-wide error handling.

interface ErrorProtocols {
  /** Add global error event listener */
  onError: (callback: (error: string) => void) => void;
  /** Remove global error listeners */
  offError: (callback?: (error: string) => void) => void;
}

Usage Example:

import initUni from "@dcloudio/uni-mp-toutiao/api";

// API runtime is already initialized on import

// Set up global error handling
uni.onError((error) => {
  console.error('Global error:', error);
  // Send error to logging service
});

// Handle specific errors
uni.offError(); // Remove all error listeners

Provider Services

Service provider detection for platform-specific functionality.

interface ProviderShims {
  /** Detect available service providers */
  getProvider: (options: ProviderOptions) => void;
}

interface ProviderOptions {
  service: 'oauth' | 'share' | 'payment' | 'push';
  success?: (result: ProviderResult) => void;
  fail?: (error: any) => void;
}

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

Supported Providers:

  • oauth: ['toutiao']
  • share: ['toutiao']
  • payment: ['toutiao']
  • push: ['toutiao']

Usage Example:

import initUni from "@dcloudio/uni-mp-toutiao/api";

// API runtime is already initialized on import

// Check available payment providers
uni.getProvider({
  service: 'payment',
  success(result) {
    console.log('Payment providers:', result.provider);
    // Result: ['toutiao']
  }
});

// Check OAuth providers
uni.getProvider({
  service: 'oauth',
  success(result) {
    console.log('OAuth providers:', result.provider);
    // Result: ['toutiao']
  }
});

Platform-Specific Adaptations

API Parameter Mapping

Some APIs have parameter differences that are automatically handled:

  • Payment API: orderInfodata mapping when using fallback method
  • Accelerometer: Interval configuration support
  • Scan Code: Excludes unsupported onlyFromCamera and scanType parameters
  • WebSocket: Excludes unsupported method parameter

Method Resolution

APIs that have multiple implementation methods on Toutiao:

// Payment API resolution
if (tt.pay) {
  // Use tt.pay method
  tt.pay(options);
} else {
  // Fall back to tt.requestPayment with parameter mapping
  tt.requestPayment({ data: options.orderInfo, ...otherOptions });
}

Global Integration

All APIs integrate with Toutiao's global tt object:

  • tt.createApp, tt.createPage, tt.createComponent
  • tt.EventChannel for event communication
  • Platform detection via __PLATFORM__ === 'mp-toutiao'
  • Global reference via __GLOBAL__ === 'tt'

Install with Tessl CLI

npx tessl i tessl/npm-dcloudio--uni-mp-toutiao

docs

api-integration.md

build-system.md

index.md

parsing-utilities.md

platform-services.md

runtime.md

tile.json