Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@promise-watch/core

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@promise-watch/core - npm Package Compare versions

Comparing version 1.1.0-next.4 to 1.1.0

2

package.json
{
"name": "@promise-watch/core",
"version": "1.1.0-next.4",
"version": "1.1.0",
"author": "Jason Raimondi <jason@raimondi.us> (https://jasonraimondi.com)",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -5,4 +5,9 @@ <h1 align="center">

[![Tests](https://github.com/jasonraimondi/promise-watch/actions/workflows/test.yml/badge.svg)](https://github.com/jasonraimondi/promise-watch/actions/workflows/test.yml)
[![License](https://img.shields.io/github/license/jasonraimondi/promise-watch?color=#31C754)](./LICENSE.md)
[![tests](https://github.com/jasonraimondi/promise-watch/actions/workflows/test.yml/badge.svg)](https://github.com/jasonraimondi/promise-watch/actions/workflows/test.yml)
[![license](https://img.shields.io/github/license/jasonraimondi/promise-watch?color=#31C754)](./LICENSE.md)
[![core](https://img.shields.io/npm/v/@promise-watch/core?label=%40promise-watch%2Fcore)](https://www.npmjs.com/package/@promise-watch/core)
[![axios](https://img.shields.io/npm/v/@promise-watch/axios?label=%40promise-watch%2Faxios)](https://www.npmjs.com/package/@promise-watch/axios)
[![pushover](https://img.shields.io/npm/v/@promise-watch/pushover?label=%40promise-watch%2Fpushover)](https://www.npmjs.com/package/@promise-watch/pushover)
[![slack](https://img.shields.io/npm/v/@promise-watch/slack?label=%40promise-watch%2Fslack)](https://www.npmjs.com/package/@promise-watch/slack)
[![smtp](https://img.shields.io/npm/v/@promise-watch/smtp?label=%40promise-watch%2Fsmtp)](https://www.npmjs.com/package/@promise-watch/smtp)

@@ -14,33 +19,28 @@ An Api/E2E monitor that runs promises on intervals and sends notifications on errors. Supports [playwright](https://playwright.dev/) for reliable E2E testing. Has prebuilt [notifiers](#notifiers) for [SMTP](./packages/smtp), [Slack](./packages/slack), and [Pushover](./packages/pushover), and can support any [custom notifier](#custom-notifiers).

```
./my-e2e-checks
├── runs
./my-e2e-checks/
├── runs/
│ ├── checks-https-jasonraimondi-com.ts
│ └── checks-https-google-com.ts
├── src
│ └── main.ts
├── promise-watch.config.ts
└── package.json
```
Your runs can be anything! It just needs to export an `options: RunOptions` and `run: Promise<void>`.
Your runs can be anything! It just needs to export an `options: RunPageOptions` and `run: Promise<void>`.
```typescript
// runs/checks-https-jasonraimondi-com.ts
import { chromium } from "playwright";
import { RunOptions } from "@promise-watch/core";
import { RunPageOptions } from "@promise-watch/core";
export const options: RunOptions = {
interval: 60, // in seconds
export const options: RunPageOptions = {
interval: 15,
};
export async function run(): Promise<void> {
export async function run() {
const browser = await chromium.launch();
const page = await browser.newPage();
const site = "https://jasonraimondi.com";
const response = await page.goto("https://jasonraimondi.com");
const response = await page.goto(site);
if ((response?.status() ?? 1000) > 399) {
throw new Error(`${site} Failed to load!`);
if (response?.status && response.status() > 399) {
throw new Error(`Failed with response code [${response.status()}].`);
}

@@ -50,60 +50,20 @@

await browser.close();
console.log(`success: ${__filename}`);
}
```
## Getting Started
Really, you can put anything in the promise.
Make a new project directory
```bash
mkdir -p my-watchers/{runs/src}
cd my-watchers
git init
pnpm init -y
```
Install dependencies
```bash
pnpm add @promise-watch/core playwright
pnpm add -D typescript ts-node @types/node
```
Next, create a sample run. A run requires two exports: `options: { interval: number; }` and `run: Promise<void>`. For each
Add an entrypoint
```typescript
const options: ExecuteOptions = {
dir: __dirname,
notifiers: [
// The ConsoleNotifier logs errors to the console
// see below for other notifiers
new ConsoleNotifier(),
],
export const options = {
interval: 15,
};
executeJobs(options).catch(err => {
console.error(err);
process.exit(1);
});
```
And a run script
```json
{
"scripts": {
"start": "ts-node src/main.ts"
}
export async function run() {
// you can run anything here... if it throws an error, it will send a notification.
}
```
And go
## Getting Started
```bash
pnpm start
```
The best way to get started is to use the [starter-template](https://github.com/promise-watch/starter-template). Clone it down and then add your own custom runs to the `runs/` directory.

@@ -115,22 +75,8 @@ ## Configuration

```typescript
type RunOptions = {
interval: number;
notifiers?: Notifier[];
logSuccess?: boolean;
retryImmediatelyAfterFail?: boolean;
type RunPageOptions = {
interval: number; // required
notifiers?: Notifier[]; // default: []
logSuccess?: boolean; // default: false
retryImmediatelyAfterFail?: boolean; // default: false
};
const options: RunOptions = {
// required, in seconds
interval: 30,
// default: undefined
notifiers: undefined,
// default: false
logSuccess: false,
// default: false
retryImmediatelyAfterFail: false,
};
```

@@ -147,8 +93,2 @@

```bash
pnpm add @promise-watch/pushover @promise-watch/slack @promise-watch/smtp
```
Then in your execute options, add the `PushoverNotifier` to your `errorNotifiers` array.
```typescript

@@ -182,5 +122,19 @@ import { ConsoleNotifier } from "@promise-watch/core";

So you'd implement your own more or less like the following.
```typescript
export class MyCustomNotifier implements Notifier {
async sendError(options: SendOptions) {
// handle custom error message
}
async sendRecovered(options: SendOptions) {
// handle custom recovered message
}
}
```
## API Monitoring
Since it is just a Promise with errors being thrown, you can opt to just have a run that just makes an http api request to an endpoint. There is a helper package `@promise-watch/axois` that has a small helper for that.
Since it is just a Promise with errors being thrown, you can opt to just have a run that just makes an http api request to an endpoint. There is a helper package [`@promise-watch/axois`](./run/axios) that has a small helper for that.

@@ -187,0 +141,0 @@ ```typescript

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc