DefinitelyTyped/types/node-pushnotifications/index.d.ts

200 lines
7.0 KiB
TypeScript
Raw Permalink Normal View History

2018-03-20 12:32:07 +00:00
// Type definitions for node-pushnotifications 1.0
// Project: https://github.com/appfeel/node-pushnotifications
// Definitions by: Menushka Weeratunga <https://github.com/menushka>
// Julian Hundeloh <https://github.com/jaulz>
2018-03-20 12:32:07 +00:00
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
2018-03-20 12:32:07 +00:00
2018-03-20 19:38:15 +00:00
/// <reference types="node" />
import * as webPush from 'web-push';
2018-03-20 19:38:15 +00:00
export = PushNotifications;
2018-03-20 12:32:07 +00:00
declare class PushNotifications {
2018-03-20 19:38:15 +00:00
constructor(settings: PushNotifications.Settings);
2018-03-20 12:32:07 +00:00
2018-03-20 19:38:15 +00:00
setOptions(opts: PushNotifications.Settings): void;
sendWith(method: PushNotifications.PushMethod, regIds: string[], data: PushNotifications.Data, cb: PushNotifications.Callback): void;
send(registrationIds: PushNotifications.RegistrationId|PushNotifications.RegistrationId[], data: PushNotifications.Data, cb: PushNotifications.Callback): void;
send(registrationIds: PushNotifications.RegistrationId|PushNotifications.RegistrationId[], data: PushNotifications.Data): Promise<PushNotifications.Result[]>;
2018-03-20 12:32:07 +00:00
}
2018-03-20 19:38:15 +00:00
declare namespace PushNotifications {
interface Settings {
2018-03-20 12:32:07 +00:00
/** Google Cloud Messaging */
gcm?: {
/** GCM or FCM token */
2018-03-20 19:38:15 +00:00
id?: string;
};
2018-03-20 12:32:07 +00:00
/** Apple Push Notifications */
apn?: {
/** APN Token */
token?: {
2018-03-20 19:38:15 +00:00
/**
* The filename of the provider token key (as supplied by Apple) to load from disk, or a
* Buffer/String containing the key data.
*/
key?: Buffer | string;
2018-03-20 12:32:07 +00:00
/** The ID of the key issued by Apple */
2018-03-20 19:38:15 +00:00
keyId?: string;
2018-03-20 12:32:07 +00:00
/** ID of the team associated with the provider token key */
2018-03-20 19:38:15 +00:00
teamId?: string;
};
/**
* The filename of the connection certificate to load from disk, or a Buffer/String containing the
* certificate data.
*/
cert?: string;
/** The filename of the connection key to load from disk, or a Buffer or String containing the key data. */
key?: string;
/**
* An array of trusted certificates. Each element should contain either a filename to load, or a
* Buffer/String (in PEM format) to be used directly. If this is omitted several well known "root" CAs
* will be used. - You may need to use this as some environments don't include the CA used by
* Apple (entrust_2048).
*/
ca?: Array<Buffer | string>;
/**
* File path for private key, certificate and CA certs in PFX or PKCS12 format, or a Buffer containing
* the PFX data. If supplied will always be used instead of certificate and key above.
*/
pfx?: Buffer | string;
2018-03-20 12:32:07 +00:00
/** The passphrase for the connection key, if required */
2018-03-20 19:38:15 +00:00
passphrase?: string;
2018-03-21 13:22:49 +00:00
production?: boolean;
2018-03-20 19:38:15 +00:00
voip?: boolean;
address?: string;
port?: number;
rejectUnauthorized?: boolean;
connectionRetryLimit?: number;
cacheLength?: number;
connectionTimeout?: number;
autoAdjustCache?: boolean;
maxConnections?: number;
minConnections?: number;
connectTimeout?: number;
buffersNotifications?: boolean;
fastMode?: boolean;
disableNagle?: boolean;
disableEPIPEFix?: boolean;
};
2018-03-20 12:32:07 +00:00
/** Amazon Device Messaging */
adm?: {
2018-03-20 19:38:15 +00:00
client_id?: string;
client_secret?: string;
};
2018-03-20 12:32:07 +00:00
/** Windows Push Notifications */
wns?: {
2018-03-20 19:38:15 +00:00
client_id?: string;
client_secret?: string;
accessToken?: string;
headers?: string;
notificationMethod?: string;
};
2018-03-20 12:32:07 +00:00
/** Microsoft Push Notification Service */
mpns?: {
options?: {
2018-03-20 19:38:15 +00:00
client_id?: string;
client_secret?: string;
};
};
/** Web */
web?: webPush.RequestOptions;
/** Always use FCM? */
isAlwaysUseFCM?: boolean;
2018-03-20 12:32:07 +00:00
}
2018-03-20 19:38:15 +00:00
interface Data {
2018-03-20 12:32:07 +00:00
/** REQUIRED */
2018-03-20 19:38:15 +00:00
title: string;
2018-03-20 12:32:07 +00:00
/** REQUIRED */
2018-03-20 19:38:15 +00:00
body: string;
custom?: { [key: string]: string | number } | string;
2018-03-20 19:38:15 +00:00
/**
* gcm, apn. Supported values are 'high' or 'normal' (gcm). Will be translated to 10 and 5 for apn. Defaults
* to 'high'
*/
priority?: string;
2018-03-20 12:32:07 +00:00
/** gcm for android, used as collapseId in apn */
2018-03-20 19:38:15 +00:00
collapseKey?: string;
2018-03-20 12:32:07 +00:00
/** gcm for android */
2018-03-20 19:38:15 +00:00
contentAvailable?: boolean | string;
2018-03-20 12:32:07 +00:00
/** gcm for android */
2018-03-20 19:38:15 +00:00
delayWhileIdle?: boolean;
2018-03-20 12:32:07 +00:00
/** gcm for android */
2018-03-20 19:38:15 +00:00
restrictedPackageName?: string;
2018-03-20 12:32:07 +00:00
/** gcm for android */
2018-03-20 19:38:15 +00:00
dryRun?: boolean;
2018-03-20 12:32:07 +00:00
/** gcm for android */
2018-03-20 19:38:15 +00:00
icon?: string;
2018-03-20 12:32:07 +00:00
/** gcm for android */
2018-03-20 19:38:15 +00:00
tag?: string;
2018-03-20 12:32:07 +00:00
/** gcm for android */
2018-03-20 19:38:15 +00:00
color?: string;
2018-03-20 12:32:07 +00:00
/** gcm for android. In ios, category will be used if not supplied */
2018-03-20 19:38:15 +00:00
clickAction?: string;
2018-03-20 12:32:07 +00:00
/** gcm, apn */
2018-03-20 19:38:15 +00:00
locKey?: string;
2018-03-20 12:32:07 +00:00
/** gcm, apn */
2018-03-20 19:38:15 +00:00
bodyLocArgs?: string;
2018-03-20 12:32:07 +00:00
/** gcm, apn */
2018-03-20 19:38:15 +00:00
titleLocKey?: string;
2018-03-20 12:32:07 +00:00
/** gcm, apn */
2018-03-20 19:38:15 +00:00
titleLocArgs?: string;
2018-03-20 12:32:07 +00:00
/** gcm, apn */
2018-03-20 19:38:15 +00:00
retries?: number;
2018-03-20 12:32:07 +00:00
/** apn */
2018-03-20 19:38:15 +00:00
encoding?: string;
2018-03-20 12:32:07 +00:00
/** gcm for ios, apn */
2018-03-20 19:38:15 +00:00
badge?: number;
2018-03-20 12:32:07 +00:00
/** gcm, apn */
2018-03-20 19:38:15 +00:00
sound?: string;
2018-03-20 12:32:07 +00:00
/** apn, will take precedence over title and body. It is also accepted a text message in alert */
2018-03-20 19:38:15 +00:00
alert?: {} | string;
2018-03-20 12:32:07 +00:00
/** apn and gcm for ios */
2018-03-20 19:38:15 +00:00
launchImage?: string;
2018-03-20 12:32:07 +00:00
/** apn and gcm for ios */
2018-03-20 19:38:15 +00:00
action?: string;
2018-03-20 12:32:07 +00:00
/** apn and gcm for ios */
2018-03-20 19:38:15 +00:00
topic?: string;
2018-03-20 12:32:07 +00:00
/** apn and gcm for ios */
2018-03-20 19:38:15 +00:00
category?: string;
2018-03-20 12:32:07 +00:00
/** apn and gcm for ios */
2018-03-20 19:38:15 +00:00
mdm?: string;
2018-03-20 12:32:07 +00:00
/** apn and gcm for ios */
2018-03-20 19:38:15 +00:00
urlArgs?: string;
2018-03-20 12:32:07 +00:00
/** apn and gcm for ios */
2018-03-20 19:38:15 +00:00
truncateAtWordEnd?: boolean;
2018-03-20 12:32:07 +00:00
/** apn */
2018-03-20 19:38:15 +00:00
mutableContent?: number;
2018-03-20 12:32:07 +00:00
/** seconds */
2018-03-20 19:38:15 +00:00
expiry?: number;
2018-03-20 12:32:07 +00:00
/** if both expiry and timeToLive are given, expiry will take precedency */
2018-03-20 19:38:15 +00:00
timeToLive?: number;
2018-03-20 12:32:07 +00:00
/** wns */
2018-03-20 19:38:15 +00:00
headers?: string[];
2018-03-20 12:32:07 +00:00
/** wns */
2018-03-20 19:38:15 +00:00
launch?: string;
2018-03-20 12:32:07 +00:00
/** wns */
2018-03-20 19:38:15 +00:00
duration?: string;
2018-03-20 12:32:07 +00:00
/** ADM */
2018-03-20 19:38:15 +00:00
consolidationKey?: string;
2018-03-20 12:32:07 +00:00
}
interface Message {
regId: string;
originalRegId?: string;
messageId?: string;
error?: Error | null;
errorMsg?: string;
}
interface Result {
method: string;
success: number;
failure: number;
message: Message[];
}
2018-03-20 19:38:15 +00:00
type PushMethod = (regIds: string[], data: Data, settings: Settings) => void;
type Callback = (err: any, result: any) => void;
type RegistrationId = string | webPush.PushSubscription;
2018-03-20 12:32:07 +00:00
}