ExpoClient.d.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /// <reference types="node" />
  2. import { Agent } from 'http';
  3. export declare class Expo {
  4. static pushNotificationChunkSizeLimit: number;
  5. static pushNotificationReceiptChunkSizeLimit: number;
  6. private httpAgent;
  7. private limitConcurrentRequests;
  8. private accessToken;
  9. private useFcmV1;
  10. constructor(options?: ExpoClientOptions);
  11. /**
  12. * Returns `true` if the token is an Expo push token
  13. */
  14. static isExpoPushToken(token: unknown): token is ExpoPushToken;
  15. /**
  16. * Sends the given messages to their recipients via push notifications and returns an array of
  17. * push tickets. Each ticket corresponds to the message at its respective index (the nth receipt
  18. * is for the nth message) and contains a receipt ID. Later, after Expo attempts to deliver the
  19. * messages to the underlying push notification services, the receipts with those IDs will be
  20. * available for a period of time (approximately a day).
  21. *
  22. * There is a limit on the number of push notifications you can send at once. Use
  23. * `chunkPushNotifications` to divide an array of push notification messages into appropriately
  24. * sized chunks.
  25. */
  26. sendPushNotificationsAsync(messages: ExpoPushMessage[]): Promise<ExpoPushTicket[]>;
  27. getPushNotificationReceiptsAsync(receiptIds: ExpoPushReceiptId[]): Promise<{
  28. [id: string]: ExpoPushReceipt;
  29. }>;
  30. chunkPushNotifications(messages: ExpoPushMessage[]): ExpoPushMessage[][];
  31. chunkPushNotificationReceiptIds(receiptIds: ExpoPushReceiptId[]): ExpoPushReceiptId[][];
  32. private chunkItems;
  33. private requestAsync;
  34. private parseErrorResponseAsync;
  35. private getTextResponseErrorAsync;
  36. /**
  37. * Returns an error for the first API error in the result, with an optional `others` field that
  38. * contains any other errors.
  39. */
  40. private getErrorFromResult;
  41. /**
  42. * Returns an error for a single API error
  43. */
  44. private getErrorFromResultError;
  45. static _getActualMessageCount(messages: ExpoPushMessage[]): number;
  46. }
  47. export default Expo;
  48. export type ExpoClientOptions = {
  49. httpAgent?: Agent;
  50. maxConcurrentRequests?: number;
  51. accessToken?: string;
  52. useFcmV1?: boolean;
  53. };
  54. export type ExpoPushToken = string;
  55. export type ExpoPushMessage = {
  56. to: ExpoPushToken | ExpoPushToken[];
  57. data?: object;
  58. title?: string;
  59. subtitle?: string;
  60. body?: string;
  61. sound?: 'default' | null | {
  62. critical?: boolean;
  63. name?: 'default' | null;
  64. volume?: number;
  65. };
  66. ttl?: number;
  67. expiration?: number;
  68. priority?: 'default' | 'normal' | 'high';
  69. badge?: number;
  70. channelId?: string;
  71. categoryId?: string;
  72. mutableContent?: boolean;
  73. };
  74. export type ExpoPushReceiptId = string;
  75. export type ExpoPushSuccessTicket = {
  76. status: 'ok';
  77. id: ExpoPushReceiptId;
  78. };
  79. export type ExpoPushErrorTicket = ExpoPushErrorReceipt;
  80. export type ExpoPushTicket = ExpoPushSuccessTicket | ExpoPushErrorTicket;
  81. export type ExpoPushSuccessReceipt = {
  82. status: 'ok';
  83. details?: object;
  84. __debug?: any;
  85. };
  86. export type ExpoPushErrorReceipt = {
  87. status: 'error';
  88. message: string;
  89. details?: {
  90. error?: 'DeveloperError' | 'DeviceNotRegistered' | 'ExpoError' | 'InvalidCredentials' | 'MessageRateExceeded' | 'MessageTooBig' | 'ProviderError';
  91. };
  92. __debug?: any;
  93. };
  94. export type ExpoPushReceipt = ExpoPushSuccessReceipt | ExpoPushErrorReceipt;