From 9fb3b602b102351d49fb442a4ad6e799118c88ed Mon Sep 17 00:00:00 2001 From: Menushka Weeratunga Date: Tue, 20 Mar 2018 08:32:07 -0400 Subject: [PATCH] Added types for node-pushnotifications --- types/node-pushnotifications/index.d.ts | 170 ++++++++++++++++++ .../node-pushnotifications-tests.ts | 51 ++++++ types/node-pushnotifications/tsconfig.json | 22 +++ types/node-pushnotifications/tslint.json | 1 + 4 files changed, 244 insertions(+) create mode 100644 types/node-pushnotifications/index.d.ts create mode 100644 types/node-pushnotifications/node-pushnotifications-tests.ts create mode 100644 types/node-pushnotifications/tsconfig.json create mode 100644 types/node-pushnotifications/tslint.json diff --git a/types/node-pushnotifications/index.d.ts b/types/node-pushnotifications/index.d.ts new file mode 100644 index 0000000000..fbb11eac3b --- /dev/null +++ b/types/node-pushnotifications/index.d.ts @@ -0,0 +1,170 @@ +// Type definitions for node-pushnotifications 1.0 +// Project: https://github.com/appfeel/node-pushnotifications +// Definitions by: Menushka Weeratunga +// 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; +} + +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; +} \ No newline at end of file diff --git a/types/node-pushnotifications/node-pushnotifications-tests.ts b/types/node-pushnotifications/node-pushnotifications-tests.ts new file mode 100644 index 0000000000..2d815a21dc --- /dev/null +++ b/types/node-pushnotifications/node-pushnotifications-tests.ts @@ -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); + }); diff --git a/types/node-pushnotifications/tsconfig.json b/types/node-pushnotifications/tsconfig.json new file mode 100644 index 0000000000..bbd908bcdb --- /dev/null +++ b/types/node-pushnotifications/tsconfig.json @@ -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" + ] +} diff --git a/types/node-pushnotifications/tslint.json b/types/node-pushnotifications/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/node-pushnotifications/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }