Added types for node-pushnotifications

This commit is contained in:
Menushka Weeratunga 2018-03-20 08:32:07 -04:00
parent 9f4c751261
commit 9fb3b602b1
4 changed files with 244 additions and 0 deletions

170
types/node-pushnotifications/index.d.ts vendored Normal file
View File

@ -0,0 +1,170 @@
// Type definitions for node-pushnotifications 1.0
// Project: https://github.com/appfeel/node-pushnotifications
// Definitions by: Menushka Weeratunga <https://github.com/menushka>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class PushNotifications {
constructor(settings: PushNotifications.ISettings);
setOptions(opts: PushNotifications.ISettings): void;
sendWith(method: PushNotifications.IPushMethod, regIds: string[], data: PushNotifications.IData, cb: PushNotifications.ICallback): void;
send(registrationIds: string[], data: PushNotifications.IData, cb: PushNotifications.ICallback): void;
send(registrationIds: string[], data: PushNotifications.IData): Promise<any>;
}
declare module PushNotifications {
interface ISettings {
/** Google Cloud Messaging */
gcm?: {
/** GCM or FCM token */
id?: string
},
/** Apple Push Notifications */
apn?: {
/** APN Token */
token?: {
/** 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,
/** The ID of the key issued by Apple */
keyId?: string,
/** ID of the team associated with the provider token key */
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/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?: (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,
/** The passphrase for the connection key, if required */
passphrase?: string,
productionv?: boolean,
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
},
/** Amazon Device Messaging */
adm?: {
client_id?: string,
client_secret?: string
},
/** Windows Push Notifications */
wns?: {
client_id?: string,
client_secret?: string,
accessToken?: string,
headers?: string,
notificationMethod?: string
},
/** Microsoft Push Notification Service */
mpns?: {
options?: {
client_id?: string,
client_secret?: string
}
}
}
interface IData {
/** REQUIRED */
title: string,
/** REQUIRED */
body: string,
custom?: {
sender?: string,
},
/** gcm, apn. Supported values are 'high' or 'normal' (gcm). Will be translated to 10 and 5 for apn. Defaults to 'high' */
priority?: string,
/** gcm for android, used as collapseId in apn */
collapseKey?: string,
/** gcm for android */
contentAvailable?: boolean | string,
/** gcm for android */
delayWhileIdle?: boolean,
/** gcm for android */
restrictedPackageName?: string,
/** gcm for android */
dryRun?: boolean,
/** gcm for android */
icon?: string,
/** gcm for android */
tag?: string,
/** gcm for android */
color?: string,
/** gcm for android. In ios, category will be used if not supplied */
clickAction?: string,
/** gcm, apn */
locKey?: string,
/** gcm, apn */
bodyLocArgs?: string,
/** gcm, apn */
titleLocKey?: string,
/** gcm, apn */
titleLocArgs?: string,
/** gcm, apn */
retries?: number,
/** apn */
encoding?: string,
/** gcm for ios, apn */
badge?: number,
/** gcm, apn */
sound?: string,
/** apn, will take precedence over title and body. It is also accepted a text message in alert */
alert?: {} | string,
/** apn and gcm for ios */
launchImage?: string,
/** apn and gcm for ios */
action?: string,
/** apn and gcm for ios */
topic?: string,
/** apn and gcm for ios */
category?: string,
/** apn and gcm for ios */
mdm?: string,
/** apn and gcm for ios */
urlArgs?: string,
/** apn and gcm for ios */
truncateAtWordEnd?: boolean,
/** apn */
mutableContent?: number,
/** seconds */
expiry?: number,
/** if both expiry and timeToLive are given, expiry will take precedency */
timeToLive?: number,
/** wns */
headers?: string[],
/** wns */
launch?: string,
/** wns */
duration?: string,
/** ADM */
consolidationKey?: string
}
interface IPushMethod {
(regIds: string[], data: IData, settings: ISettings): void
}
interface ICallback {
(err: any, result: any): void
}
}
declare module 'node-pushnotifications' {
export = PushNotifications;
}

View File

@ -0,0 +1,51 @@
import * as PushNotifications from "node-pushnotifications";
const settings = {
gcm: {
id: "null"
},
apn: {
token: {
key: './certs/key.p8',
keyId: 'ABCD',
teamId: 'EFGH',
}
},
adm: {
client_id: "null",
client_secret: "null"
},
wns: {
client_id: "null",
client_secret: "null",
notificationMethod: 'sendTileSquareBlock',
}
};
const push = new PushNotifications(settings);
const registrationIds = [];
registrationIds.push('INSERT_YOUR_DEVICE_ID');
registrationIds.push('INSERT_OTHER_DEVICE_ID');
const data = {
title: 'New push notification',
body: 'Powered by AppFeel'
};
// You can use it in node callback style
push.send(registrationIds, data, (err, result) => {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
// Or you could use it as a promise:
push.send(registrationIds, data)
.then((results) => {
console.log(results);
})
.catch((err) => {
console.log(err);
});

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": ["node"],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"node-pushnotifications-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }