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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-http-notifier

v1.0.0-a

Published

Library for handeling Http reponse .

Downloads

6

Readme

NgHttpNotifier

Library for handeling Http reponse .

Project Goals:

  1. configurable Notification messages per(uri, method, status) can use server response each notification has 4 basic Severity levels

    • info
    • success
    • warning
    • error

    use assets/config/http-notification-config.json file to configure notification messages no need to redeploy if you want to change some message.

  1. Plugable Toastr providers if any advanced Toastr exists it can be used and also can be configured
  1. UI consistency if you are using ui libraries like prime - boot strap- material that has their own toastr just just provide ToastrService implementation that uses the toolkit toastr.
  1. for i18n just provide Toastr that implements NotifierToastr interface that has translation cabability
  1. Has Default Impel(provider) its not good and not recommended its alert alret(). just use your favorite toastr library or what matches UI library you use ex angular material, primeng

Repositories

source on github

contents

  1. Getting started
  2. Use Case generate notification with ngx-toastr

Getting Started

first create assets/config/http-notification-config.json file make sure of correct path and file name add some configurations its an object with property config witch is a list of endpoint configs

{
    "config": [

        {
      "url": "",
      "method": "",
      "messages": [
        {
          "message": "success",
          "status": 200,
          "severity": "success",
          "useResponseBody": true
        }
      ]
    }

    ]
}

the above configuration matches any method any url with status 200

for the default impl add the module to your app imports its ugly not recommended NgHttpNotifierModule.forRoot()

Use ngx-toastr for notification

install ngx-toastr and its dependencies

create new module called app-notifier.module.ts it will provide toastr service and configurations

@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    BrowserAnimationsModule,
    ToastrModule.forRoot({
      timeOut: 10000,
      positionClass: 'toast-bottom-right',
      preventDuplicates: true,
    }),
  ],
})
export class AppNotifierModule {}

create toaster provider which extends ToastrService from "ng-http-notifier"

import { Injectable } from "@angular/core";
import { ToastrService } from "ng-http-notifier";
import { ToastrService as NgXToasterService}  from 'ngx-toastr';


@Injectable()
export class NgxToastrProviderService extends ToastrService{

    constructor(private ngXToasterService: NgXToasterService){
        super();
    }

    override info(message: string, options?: any): void {
        this.ngXToasterService.info(message);
    }
    override success(message: string, options?: any): void {
        this.ngXToasterService.success(message);
    }
    override warning(message: string, options: any): void {
        this.ngXToasterService.warning(message);
    }
    override error(message: string, options?: any): void {
        this.ngXToasterService.error(message);
    }

}

configure NgHttpNotifierModule to use NgxToastrProviderService

@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    BrowserAnimationsModule,
    ToastrModule.forRoot({
      timeOut: 10000,
      positionClass: 'toast-bottom-right',
      preventDuplicates: true,
    }),
    NgHttpNotifierModule.forRoot(NgxToastrProviderService), // confiured toastr provider
  ],
})
export class AppNotifierModule {}

now you provide any impelmentation not just ngx-toastr use the same way to enhance the functionality example translation just configure the module with provider that has translation capabilities.

Interfaces

http-notification-config.json will be loaded as an instance of HttpNotificationConfig and this is the JSON configuration file structure.

interface HttpNotificationConfig{
    config: EndpointNotificationConfig[];
}

interface EndpointNotificationConfig{
    method: string;
    url: string;
    messages: NotificationMessageConfig[];
}

interface NotificationMessageConfig{
    status: string; // http status codes
    message: string;
    useResponseBody?: boolean; // to use return body of server response
    severity: 'info'|'success'|'warrning'|'error';
    options?: {[x:string]: any} 
}


abstract class ToastrService{
    abstract info(message: string , options?:any):void;
    abstract success(message: string , options?:any):void;
    abstract warning(message: string , options:any):void;
    abstract error(message: string , options?:any):void;
}

// default provider 
@Injectable()
export class AlertToastrProvider extends ToastrService{

    override info(message: string, options?: any): void {
        this.showAlert(message);
    }
    override success(message: string, options?: any): void {
        this.showAlert(message);
    }
    override warning(message: string, options: any): void {
        this.showAlert(message);
    }
    override error(message: string, options?: any): void {
        this.showAlert(message);
    }

    private showAlert(message: string):void{
        console.log("showAlert", message);
        alert(message);
    }
}