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

@appear.sh/introspector

v0.1.2

Published

**Unlock the full potential of your existing APIs @ [Appear.sh](https://www.appear.sh/)**

Downloads

2,046

Readme

Appear JS introspector

Unlock the full potential of your existing APIs @ Appear.sh

Appear is a API development platform that helps companies understand, improve and manage their internal APIs.

This JS introspector is a tool that listens to both incoming and outgoing traffic in JS runtime (browser, node) and detects the shape (schema) of it and reports this schema to Appear platform where it's further merged, processed and analyzed.

Because it reports only schema of the traffic it never sends any actual content of the data nor PII.

Usage

  1. Install using your favourite package manager
    npm i @appear.sh/introspector
    yarn add @appear.sh/introspector
    pnpm add @appear.sh/introspector
  2. In entrypoint of your service initialise the introspector
    Appear.init({
      // you can obtain your reporting key in keys section in Appear settings
      // reporting keys have only the permission to report schema and can't read any data, so are safe to be sent to browser.
      apiKey: "your-api-key",
      // environment can be any string that identifies environment data are reported from.
      // Often used as "production" or "staging", however if you're using some form of ephemeral farm feel free to use it's identifier
      environment: process.env.NODE_ENV,
    })
  3. If your service hosts a HTTP server (such as Express, NestJS etc) sometimes you'll have to "hook" things before your application actually starts. To do this, we expose a @appear.sh/introspector/hook package that does this for you. The easiest way to use this is to modify your node executable parameters.

Before: node build/server.js After: node -r @appear.sh/introspector/hook build/server.js

  1. you're done, now you can login into app.appear.sh and see what's being reported

Configuration

export interface AppearConfig {
  /** API key used for reporting */
  apiKey: string
  /** environment where the report is sent from */
  environment: string
  /**
   * flag you can use to disable introspector completely
   * useful if you don't want to report in certain environments
   *
   * @default true
   */
  enabled?: boolean

  /** configuration of how often and where are data reported */
  reporting?: {
    /**
     * endpoint reports are sent to, useful if you want to audit what data are reported
     * simple audit can be done by navigating to https://public.requestbin.com/r which will give you endpoint url you can paste here and see in the debugger all traffic
     *
     * @default https://api.appear.sh/v1/reports
     */
    endpoint?: string
    /**
     * interval how often are batches sent
     * `0` means that reports are sent immidiately
     *
     * @default 5
     */
    batchIntervalSeconds?: number
    /** number of items in batch before it reports them
     * report can be triggered be either time or size depending on what happens first
     *
     * every schema is reported only once
     *
     * `0` means batching is disabled and reports are sent immidiately
     *
     * @default 10
     */
    batchSize?: number
  }

  interception?: {
    /**
     * disables XHR introspection hook which may introduce noise in some situations
     *
     * @default false
     */
    disableXHR?: boolean
    /**
     * Optional function that allows to filter what request/response pair is getting analyzed and reported
     *
     * @default (req, req, config) => req.destination === "" && request.url !== config.reporting.endpoint
     */
    filter?: (
      request: Request,
      response: Response,
      config: ResolvedAppearConfig,
    ) => boolean
  }
}

Framework specific integrations

Not all services are deployed as a node applications. If that applies to you, you can either use one of pre-built integrations, or write your own adapter.

RedwoodJS at vercel

  1. Create a file where you can instantiate Appear, for example: api/src/withAppear.ts
// withAppear.ts
import { createVercelMiddleware } from "@appear.sh/introspector/integrations/redwoodjs"

export const withAppear = createVercelMiddleware({
  // api key you can obtain at https://app.appear.sh/settings
  apiKey: "your-api-key",
  // any identifier of enviroment you prefer, we recommend to at least separate production/staging/development. The more granular the better
  environment: process.env.NODE_ENV,
  // other config as you desire
  // ...
})
  1. Wrap your Serverless Functions (API Endpoints) in withAppear
// eg. api/src/functions/<function name>/<function name>.ts
import { withAppear } from "src/withAppear"

export const handler = withAppear(async (event, context) => {
  // your code
})
  1. Once finished, any calls to your APIs should show up in Appear

Next.JS server-side integration at vercel

Note:

only pages router is supported at this moment. If you'd like app router support please let us know on [email protected]

  1. Create a file where you can instantiate Appear, for example: api/src/withAppear.ts
// withAppear.ts
import { createVercelPagesMiddleware } from "@appear.sh/introspector/integrations/nextjs"

export const withAppear = createVercelPagesMiddleware({
  // api key you can obtain at https://app.appear.sh/settings
  apiKey: "your-api-key",
  // any identifier of enviroment you prefer, we recommend to at least separate production/staging/development. The more granular the better
  environment: process.env.NODE_ENV,
  // other config as you desire
  // ...
})
  1. Wrap your API Routes in withAppear
// eg. src/pages/api/<route name>.ts
import { withAppear } from "src/withAppear"

export default withAppear(async (req, res) => {
  // your code
})
  1. Patch webpack configuration in next.config.js
// @ts-check
const {
  withAppearConfig,
} = require("@appear.sh/introspector/integrations/nextjs")

/** @type {import('next').NextConfig} */
const nextConfig = {
  // your next config
}

module.exports = withAppearConfig(nextConfig)
  1. Once finished, any calls to your APIs should show up in Appear