npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@devath/network-guard

v0.1.0

Published

Warn users when they leave a trusted corporate network in Angular apps.

Downloads

5

Readme

Network Guard

@devath/network-guard helps Angular applications detect when a user leaves a trusted (for example in-office or VPN) network. It validates connectivity against an internal endpoint and surfaces a warning banner whenever requests start failing or the browser reports that it is offline.

Key features

  • Lightweight service that listens for online/offline, connection, and visibility changes.
  • Configurable validation endpoint, retry strategy, and polling cadence.
  • Standalone warning banner component with retry and dismiss actions.
  • Strongly typed state stream so you can build your own UX if you prefer.

Installation

npm install @devath/network-guard

The package is published as an Angular library targeting Angular 18.

Quick start

  1. Provide a configuration that points to an endpoint only reachable from the trusted network (a simple /ping route works).
import { provideNetworkGuardConfig } from '@devath/network-guard';

bootstrapApplication(AppComponent, {
  providers: [
    provideNetworkGuardConfig({
      validationUrl: 'https://intranet.example.com/ping',
      timeoutMs: 3000,
      retryAttempts: 2,
    }),
  ],
});
  1. Drop the banner component somewhere near the root of your application shell.
<network-guard-banner
  title="You left the secure network"
  message="Reconnect to the corporate VPN to keep working securely."
  [showRetry]="true"
></network-guard-banner>

The banner becomes visible when the service labels the connection as untrusted. Users can retry the validation or dismiss the alert locally until the connection becomes trusted again.

Service API

The NetworkGuardService exposes two main entry points:

  • state$ (alias stateChanges): observable stream of NetworkGuardState values.
  • checkNow(trigger?: NetworkGuardTrigger): manually force a validation cycle, e.g. when the user taps a "Retry" button.

NetworkGuardState includes the current status ("unknown" | "checking" | "trusted" | "untrusted"), whether the browser is online, the trigger that caused the latest check, timestamps, and an optional failure payload.

Configuration

Provide NETWORK_GUARD_CONFIG with the options you need:

| Option | Description | Default | | --- | --- | --- | | validationUrl | URL that is only reachable on the trusted network. | /network-guard/ping | | method | HTTP method for the validation call. | "HEAD" | | timeoutMs | Abort the request after this many milliseconds. | 4000 | | retryAttempts | Additional attempts after the initial request. | 1 | | retryDelayMs | Delay between retries (ms). | 750 | | pollIntervalMs | Optional recurring validation interval. | Disabled | | checkOnStart | Run a validation immediately on service creation. | true | | warnOnOffline | Treat browser offline events as untrusted. | true | | listenForConnectionChanges | Subscribe to navigator.connection changes when available. | true | | listenForVisibilityChange | Re-check when the tab becomes visible. | true | | fetch | Custom fetch implementation (useful for testing). | Browser fetch | | requestInit | Additional options merged into the fetch request. | {} |

Custom UI

Prefer to show a custom warning banner or integrate with an existing notification center? Inject the service and subscribe to state$:

@Component({
  selector: 'app-shell',
  templateUrl: './shell.component.html',
})
export class ShellComponent {
  readonly networkState$ = inject(NetworkGuardService).state$;
}
<div *ngIf="(networkState$ | async)?.status === 'untrusted'" class="warning">
  Your connection is no longer trusted. Please reconnect.
</div>

Building & publishing

ng build network-guard
cd dist/network-guard
npm publish --access public

Run ng test network-guard to execute the unit tests.