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

@covisint/cui-api-interceptor

v1.0.6

Published

API validator/logger for cui products.

Downloads

4

Readme

cuiApiInterceptor

Lightweight logger / validator / adapter for $.ajax calls.

How it works

GET requests

Every time we get a response to a GET request we look at the accepts header and validate that against an existing JSON schema. Based on the response status and validity we issue a callback with different options to make it easier for you to log those requests in any fashion you'd like.

In the future there will be an option to set to which version of the schemas you want to validate and adapt to (have responses converted to).

Basic usage


const interceptorOptions = {
    apiUri: [ appConfig.serviceUrl ],
    stopIfInvalidPayload: false
};

window.cuiApiInterceptor.startGetInterceptor(interceptorOptions);

window.cuiApiInterceptor.startPrePutInterceptor(interceptorOptions);

window.cuiApiInterceptor.startPrePostInterceptor(interceptorOptions);

window.cuiApiInterceptor.startPostPutInterceptor(interceptorOptions);

window.cuiApiInterceptor.startPostPostInterceptor(interceptorOptions);

Advanced usage

Get / Post Put / Post Post interceptors

You can optionally set a method on the options object you pass the interceptor called logCallback. The logCallback function gets passed a single object, with the following properties:

  • e <object> : The jquery event matching the request. You can use this to access information like timestamp.

  • xhr <object> : Information on the response

  • result <object> : Information on the validity of the request

And, in the object result, you will have the following properties:

  • settings <object> : Information on the request and sources. Use this to see which domain the request was made from.

  • endpoint <string> : The endpoint which the call was made to.

  • success <true || undefined> : If the call got back a 200 and the response was validated.

  • error <true || undefined> : Wether or not there was an error (undefined if no error).

  • errorType <only defined if error is true - string> : The type of error the response gave us. Could be 'http error', 'response inconsistency' or 'missing schema'.

  • errors <only defined if error is true - array> : An array of errors (objects or strings) associated with the error. If the errorType is response inconsistency then the errors will be an array of objects returned by the AVJ library. Use this to access the data properties on the response that do not match against the schema.

  • status <only defined if errorType is http error - string> : The error status received.

  • response <only defined if no error or errorType different than http error - any> : The response that was received.

  • missing schema <only defined if errorType is missing schema - string> : The accepts header on that call.

Pre Put / Post Interceptor

For the prePut and prePost interceptors you can pass an extra property to the options object, stopIfInvalidPayload, that will abort the ajax request if the payload sent is not valid against the corresponding json schema.

The properties passed to result object in logCallback for these interceptors are similar to those of the post request interceptors, with the exception of the error types and response.

response is no longer defined, instead, payload will contain the data that we are attempting to PUT/POST errorType is now one of the following: 'missing schema', 'invalid payload'