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

@ableron/ableron

v1.10.0

Published

JavaScript Library for Ableron Server Side UI Composition

Downloads

2,575

Readme

@ableron/ableron

Build Status npm version Node.js Version

JavaScript Library for Ableron Server Side UI Composition.

Installation

npm i @ableron/ableron

Usage

Normally, you do not want to use ableron-js directly, because intercepting and modifying the response body within your service may be tricky. Instead, you may want to use an existing framework integration, which uses ableron-js under the hood, e.g.

To use ableron-js directly, do something like this:

import { Ableron } from '@ableron/ableron';

const ableron = new Ableron(
  /* optional configuration */
  {
    statsAppendToContent: true
    // ...
  },
  // optional logger
  pinoWinstonMorganOrWhateverYouMayHave() || console
);
const rawResponseBody = buildRawResponseBody();
const req = yourNodeJsRequestObject();
const res = yourNodeJsResponseObject();

try {
  ableron
    .resolveIncludes(rawResponseBody, req.headers)
    .then((transclusionResult) => {
      transclusionResult
        .getResponseHeadersToPass()
        .forEach((headerValue, headerName) => res.setHeader(headerName, headerValue));
      res.setHeader(
        'Cache-Control',
        transclusionResult.calculateCacheControlHeaderValueByResponseHeaders(res.getHeaders())
      );
      res.setHeader('Content-Length', Buffer.byteLength(transclusionResult.getContent()));
      res.status(transclusionResult.getStatusCodeOverride() || res.statusCode);
      setFinalResponseBody(transclusionResult.getContent());
    })
    .catch((e) => {
      logger.error(`[Ableron] Unable to perform UI composition: ${e.stack || e.message}`);
    });
} catch (e) {
  logger.error(`[Ableron] Unable to perform UI composition: ${e.stack || e.message}`);
}

Configuration

enabled

Default: true

Whether UI composition is enabled.

fragmentRequestTimeoutMillis

Default: 3000

Timeout in milliseconds for requesting fragments.

fragmentRequestHeadersToPass

Default:

[
  'Accept-Language',
  'Correlation-ID',
  'Forwarded',
  'Referer',
  'User-Agent',
  'X-Correlation-ID',
  'X-Forwarded-For',
  'X-Forwarded-Proto',
  'X-Forwarded-Host',
  'X-Real-IP',
  'X-Request-ID'
];

Request headers that are passed to fragment requests, if present.

fragmentAdditionalRequestHeadersToPass

Default: []

Extends fragmentRequestHeadersToPass. Use this property to pass all headers defined in fragmentRequestHeadersToPass plus the additional headers defined here. This prevents the need to duplicate fragmentRequestHeadersToPass if the only use case is to add additional headers instead of modifying the default ones.

primaryFragmentResponseHeadersToPass

Default: ['Content-Language', 'Location', 'Refresh']

Response headers of primary fragments to pass to the page response, if present.

cacheMaxItems

Default: 10000

Maximum number of items, the fragment cache may hold.

cacheVaryByRequestHeaders

Default: []

Fragment request headers which influence the requested fragment aside from its URL. Used to create fragment cache keys. Must be a subset of fragmentRequestHeadersToPass. Common example are headers used for steering A/B-tests.

cacheAutoRefreshEnabled

Default: false

Whether to enable auto-refreshing of cached fragments, before they expire. If set to true, cached fragments are getting asynchronously refreshed before they expire. This reduces the cache miss rate and thus have a positive impact on latency. On the other hand, additional traffic is introduced, because the cached fragments are loaded again even before their actual expiration time. Fragments are tried to be refreshed when only 15% of their initial time to live remains. In case of failure, refresh is repeated three times with a static delay of one second.

cacheAutoRefreshMaxAttempts

Default: 3

Maximum number of attempts to refresh a cached fragment.

cacheAutoRefreshInactiveFragmentsMaxRefreshs

Default: 2

Maximum number of consecutive refreshs of inactive cached fragments. Fragments are considered inactive, if they have not been read from cache between writing to cache and a refresh attempt.

statsAppendToContent

Default: false

Whether to append UI composition stats as HTML comment to the content.

statsExposeFragmentUrl

Default: false

Whether to expose fragment URLs in the stats appended to the content.

Contributing

All contributions are greatly appreciated, be it pull requests, feature requests or bug reports. See ableron.github.io for details.

License

Licensed under MIT.