UNPKG

expo-server-sdk

Version:

Server-side library for working with Expo using Node.js

103 lines (102 loc) 3.7 kB
import { Agent } from 'node:http'; export declare class Expo { static pushNotificationChunkSizeLimit: number; static pushNotificationReceiptChunkSizeLimit: number; private httpAgent; private limitConcurrentRequests; private accessToken; private useFcmV1; private retryMinTimeout; constructor(options?: Partial<ExpoClientOptions>); /** * Returns `true` if the token is an Expo push token */ static isExpoPushToken(token: unknown): token is ExpoPushToken; /** * Sends the given messages to their recipients via push notifications and returns an array of * push tickets. Each ticket corresponds to the message at its respective index (the nth receipt * is for the nth message) and contains a receipt ID. Later, after Expo attempts to deliver the * messages to the underlying push notification services, the receipts with those IDs will be * available for a period of time (approximately a day). * * There is a limit on the number of push notifications you can send at once. Use * `chunkPushNotifications` to divide an array of push notification messages into appropriately * sized chunks. */ sendPushNotificationsAsync(messages: ExpoPushMessage[]): Promise<ExpoPushTicket[]>; getPushNotificationReceiptsAsync(receiptIds: ExpoPushReceiptId[]): Promise<{ [id: string]: ExpoPushReceipt; }>; chunkPushNotifications(messages: ExpoPushMessage[]): ExpoPushMessage[][]; chunkPushNotificationReceiptIds(receiptIds: ExpoPushReceiptId[]): ExpoPushReceiptId[][]; private chunkItems; private requestAsync; private parseErrorResponseAsync; private getTextResponseErrorAsync; /** * Returns an error for the first API error in the result, with an optional `others` field that * contains any other errors. */ private getErrorFromResult; /** * Returns an error for a single API error */ private getErrorFromResultError; static _getActualMessageCount(messages: ExpoPushMessage[]): number; } export default Expo; export type ExpoClientOptions = { httpAgent: Agent; maxConcurrentRequests: number; retryMinTimeout: number; accessToken: string; useFcmV1: boolean; }; export type ExpoPushToken = string; export type ExpoPushMessage = { to: ExpoPushToken | ExpoPushToken[]; data?: Record<string, unknown>; title?: string; subtitle?: string; body?: string; sound?: string | null | { critical?: boolean; name?: string | null; volume?: number; }; ttl?: number; expiration?: number; priority?: 'default' | 'normal' | 'high'; interruptionLevel?: 'active' | 'critical' | 'passive' | 'time-sensitive'; badge?: number; channelId?: string; icon?: string; richContent?: { image?: string; }; categoryId?: string; mutableContent?: boolean; _contentAvailable?: boolean; }; export type ExpoPushReceiptId = string; export type ExpoPushSuccessTicket = { status: 'ok'; id: ExpoPushReceiptId; }; export type ExpoPushErrorTicket = ExpoPushErrorReceipt; export type ExpoPushTicket = ExpoPushSuccessTicket | ExpoPushErrorTicket; export type ExpoPushSuccessReceipt = { status: 'ok'; details?: object; __debug?: any; }; export type ExpoPushErrorReceipt = { status: 'error'; message: string; details?: { error?: 'DeveloperError' | 'DeviceNotRegistered' | 'ExpoError' | 'InvalidCredentials' | 'MessageRateExceeded' | 'MessageTooBig' | 'ProviderError'; expoPushToken?: string; }; __debug?: any; }; export type ExpoPushReceipt = ExpoPushSuccessReceipt | ExpoPushErrorReceipt;