2.0.0 • Published 11 months ago

@ableron/ableron v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@ableron/ableron

Build Status npm version Node.js Version

JavaScript implementation for Ableron - The Distributed Server Side UI Composition Library.

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
        .getResponseHeadersToForward()
        .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 to enable UI composition.
  • requestTimeoutMs
    • Default: 3000
    • Timeout in milliseconds for requesting fragments.
  • requestHeadersForward
    • Default: [Correlation-ID, X-Correlation-ID, X-Request-ID]
    • Request headers that are forwarded to fragment requests, if present. These request headers are not considered to influence the response and thus will not influence caching.
  • requestHeadersForwardVary
    • Default: empty list
    • Request headers that are forwarded to fragment requests, if present and that influence the requested fragment aside from its URL. These request headers are considered to influence the response and thus influence caching.
  • responseHeadersForward
    • Default: [Content-Language, Location, Refresh]
    • Response headers of primary fragments to forward to the page response, if present.
  • cacheMaxItems
    • Default: 10000
    • Maximum number of items, the fragment cache may hold.
  • 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 has 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.
2.0.0

11 months ago

1.9.1

1 year ago

1.8.2

2 years ago

1.9.0

1 year ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.9.2

1 year ago

1.8.3

2 years ago

1.10.0

1 year ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.4.0-alpha.3

2 years ago

1.4.0-alpha.1

2 years ago

1.4.0-alpha.2

2 years ago

1.2.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago