diff --git a/src/config.ts b/src/config.ts index 6155995..8dd6526 100644 --- a/src/config.ts +++ b/src/config.ts @@ -158,7 +158,7 @@ const notifications = { playSound: envOrString(process.env.PLAY_SOUND), pushbullet: envOrString(process.env.PUSHBULLET), pushover: { - priority: envOrString(process.env.PUSHOVER_PRIORITY), + priority: envOrNumber(process.env.PUSHOVER_PRIORITY), token: envOrString(process.env.PUSHOVER_TOKEN), username: envOrString(process.env.PUSHOVER_USER) }, diff --git a/src/index.ts b/src/index.ts index 591e4c5..53725e6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ import {tryLookupAndLoop} from './store'; puppeteer.use(stealthPlugin()); if (config.browser.lowBandwidth) { puppeteer.use(resourceBlock({ - blockedTypes: new Set(['image', 'font']) + blockedTypes: new Set(['image', 'font'] as const) })); } else { puppeteer.use(adBlocker); diff --git a/src/notification/pushover.ts b/src/notification/pushover.ts index 07c1ca1..b939eb4 100644 --- a/src/notification/pushover.ts +++ b/src/notification/pushover.ts @@ -1,6 +1,6 @@ import {Link, Store} from '../store/model'; import {Print, logger} from '../logger'; -import Push from 'pushover-notifications'; +import Push, {PushoverMessage} from 'pushover-notifications'; import {config} from '../config'; const pushover = config.notifications.pushover; @@ -13,7 +13,7 @@ export function sendPushoverNotification(link: Link, store: Store) { if (pushover.token && pushover.username) { logger.debug('↗ sending pushover message'); - const message = { + const message: PushoverMessage = { message: link.cartUrl ? link.cartUrl : link.url, priority: pushover.priority, title: Print.inStock(link, store) diff --git a/src/notification/sound.ts b/src/notification/sound.ts index 082fa8f..c3e0d05 100644 --- a/src/notification/sound.ts +++ b/src/notification/sound.ts @@ -1,9 +1,9 @@ +import playerLib, {PlaySound} from 'play-sound'; import {config} from '../config'; import fs from 'fs'; import {logger} from '../logger'; -import playerLib from 'play-sound'; -let player: any; +let player: PlaySound; if (config.notifications.playSound) { player = playerLib(); @@ -11,7 +11,7 @@ if (config.notifications.playSound) { if (player.player === null) { logger.warn('✖ couldn\'t find sound player'); } else { - const playerName: string = player.player; + const playerName = player.player; logger.info(`✔ sound player found: ${playerName}`); } } diff --git a/src/types/play-sound.d.ts b/src/types/play-sound.d.ts index c366eeb..8a9dd53 100644 --- a/src/types/play-sound.d.ts +++ b/src/types/play-sound.d.ts @@ -1 +1,22 @@ -declare module 'play-sound'; +declare module 'play-sound' { + export interface Options { + players?: string[]; + player?: string; + } + + export interface PlayOptions { + [key: string]: any; + } + + export interface PlaySound { + player: string; + + play: ((file: string, callback: (error: Error) => void) => PlayerProcess) & ((file: string, options: PlayOptions, callback: (error: Error) => void) => PlayerProcess); + } + + export interface PlayerProcess { + kill: () => void; + } + + export default function (options?: Options): PlaySound; +} diff --git a/src/types/puppeteer-extra-plugin-block-resources.d.ts b/src/types/puppeteer-extra-plugin-block-resources.d.ts index a8be065..e8b2fa2 100644 --- a/src/types/puppeteer-extra-plugin-block-resources.d.ts +++ b/src/types/puppeteer-extra-plugin-block-resources.d.ts @@ -1 +1,25 @@ -declare module 'puppeteer-extra-plugin-block-resources'; +declare module 'puppeteer-extra-plugin-block-resources' { + import {PuppeteerExtraPlugin} from 'puppeteer-extra'; + + export type ResourceType = + 'document' | + 'eventsource' | + 'fetch' | + 'font' | + 'image' | + 'manifest' | + 'media' | + 'other' | + 'script' | + 'stylesheet' | + 'texttrack' | + 'websocket' | + 'xhr'; + + export interface Options { + availableTypes?: Set; + blockedTypes?: Set; + } + + export default function (options?: Options): PuppeteerExtraPlugin; +} diff --git a/src/types/pushbullet.d.ts b/src/types/pushbullet.d.ts index 5f82479..3303893 100644 --- a/src/types/pushbullet.d.ts +++ b/src/types/pushbullet.d.ts @@ -1 +1,59 @@ -declare module '@hijef/pushbullet'; +declare module '@hijef/pushbullet' { + export type DeviceParams = string | number | Record; + + export type PushBulletCallback = ((error: Error) => void) | ((error?: null, response: any) => void); + + export interface ListOptions { + active?: boolean; + cursor?: string; + limit?: number; + } + + export interface HistoryOptions extends ListOptions { + modified_after?: number; + } + + export interface PushBulletStream { + connect: () => void; + close: () => void; + on: ((event: 'connect' | 'close' | 'nop', callback: () => void) => void) & ((event: 'error', callback: (error: any) => void) => void) & ((event: 'message', callback: (message: any) => void) => void) & ((event: 'tickle', callback: (tickle: any) => void) => void) & ((event: 'push', callback: (push: any) => void) => void); + } + + export class PushBullet { + constructor(apiKey: string, options?: {fullResponses: boolean}): this; + me(callback: PushBulletCallback); + devices(options: ListOptions, callback: PushBulletCallback); + devices(callback: PushBulletCallback); + createDevice(options: Record, callback: PushBulletCallback); + updateDevice(deviceIden: string, deviceOptions: Record, callback: PushBulletCallback); + deleteDevice(deviceIden: string, callback: PushBulletCallback); + note(deviceParams: DeviceParams, title: string, body: string, callback: PushBulletCallback); + link(deviceParams: DeviceParams, name: string, url: string, body: string, callback: PushBulletCallback); + file(deviceParams: DeviceParams, filePath: string, message: string, callback: PushBulletCallback); + dismissPush(pushIden: DeviceParams, callback: PushBulletCallback); + deletePush(pushIden: DeviceParams, callback: PushBulletCallback); + deleteAllPushes(callback: PushBulletCallback); + history(options: HistoryOptions, callback: PushBulletCallback); + history(callback: PushBulletCallback); + subscriptions(options: ListOptions, callback: PushBulletCallback); + subscriptions(callback: PushBulletCallback); + subscribe(channelTag: string, callback: PushBulletCallback); + unsubscribe(subscriptionIden: string, callback: PushBulletCallback); + muteSubscription(subscriptionIden: string, callback: PushBulletCallback); + unmuteSubscription(subscriptionIden: string, callback: PushBulletCallback); + channelInfo(channelTag: string, callback: PushBulletCallback); + chats(options: ListOptions, callback: PushBulletCallback); + chats(callback: PushBulletCallback); + createChat(email: string, callback: PushBulletCallback); + deleteChat(chatIden: string, callback: PushBulletCallback); + muteChat(chatIden: string, callback: PushBulletCallback); + unmuteChat(chatIden: string, callback: PushBulletCallback); + sendSMS(options: Record, callback: PushBulletCallback); + sendClipboard(options: Record, callback: PushBulletCallback); + dismissEphemeral(options: Record, callback: PushBulletCallback); + stream(): PushBulletStream; + enableEncryption(encryptionPassword: string, userIden: string): PushBulletStream; + } + + export default PushBullet; +} diff --git a/src/types/pushover-notifications.d.ts b/src/types/pushover-notifications.d.ts index 93f67cf..cdb4fe1 100644 --- a/src/types/pushover-notifications.d.ts +++ b/src/types/pushover-notifications.d.ts @@ -1 +1,55 @@ -declare module 'pushover-notifications'; +declare module 'pushover-notifications' { + export type PushoverCallback = ((error: Error) => void) | ((error?: null, response: any) => void); + + export type Sound = + 'pushover' | + 'bike' | + 'bugle' | + 'cashregister' | + 'classical' | + 'cosmic' | + 'falling' | + 'gamelan' | + 'incoming' | + 'intermission' | + 'magic' | + 'mechanical' | + 'pianobar' | + 'siren' | + 'spacealarm' | + 'tugboat' | + 'alien' | + 'climb' | + 'persistent' | + 'echo' | + 'updown' | + 'vibrate' | + 'none'; + + export interface PushoverOptions { + token: string; + user: string; + httpOptions?: {proxy: string}; + onerror?: (error: Error | string) => void; + update_sounds?: boolean; + } + + export interface PushoverMessage { + message: string; + file?: string | {name: string; data: string}; + device?: string; + title?: string; + url?: string; + url_title?: string; + priority?: number; + sound?: Sound; + timestamp?: number; + } + + export class Pushover { + constructor(options: PushoverOptions); + send(message: PushoverMessage, callback: PushoverCallback); + } + + export default Pushover; +}