@whook/versions
TypeScript icon, indicating that this package has built-in type declarations

16.1.1 • Public • Published

@whook/versions

A wrapper to provide versions check support to a Whook server

GitHub license

This Whook's wrapper simply answer to any HTTP call with a unsupported version header with a 418 HTTP error.

To use this plugin, simply install it:

npm i @whook/versions;

Declare it in the src/index.ts file of your project:

  // ...

  $.register(
    constant('HANDLERS_WRAPPERS', [
+      'wrapHandlerWithVersionChecker',
      'wrapHandlerWithAuthorization',
    ]),
  );

  // ...

  $.register(
    constant('WHOOK_PLUGINS', [
      '@whook/whook',
+      '@whook/versions',
      '@whook/authorization',
    ]),
  );

  // ...

Declare types in your src/whook.d.ts definition:

// ...
+ import type { WhookVersionsConfig } from '@whook/versions';

declare module 'application-services' {

  // ...

  export interface AppConfig
-    extends WhookBaseConfigs {}
+    extends WhookBaseConfigs, WhookVersionsConfig {}

  // ...

}

// ...

And add the errors descriptors or provide your own and configure the module (usually in src/config/common/config.js):

// ...
import { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/http-router';
+ import { VERSIONS_ERRORS_DESCRIPTORS } from '@whook/versions';
import type { AppConfig } from 'application-services';

// ...

+ const VERSIONS = [
+   {
+     header: 'X-SDK-Version',
+     rule: '>=2.2.0',
+   },
+   {
+     header: 'X-APP-Version',
+     rule: '>=3.6.0',
+   },
+ ];

const CONFIG: AppConfig = {
  // ...
-   ERRORS_DESCRIPTORS: DEFAULT_ERRORS_DESCRIPTORS,
+   ERRORS_DESCRIPTORS: {
+     ...DEFAULT_ERRORS_DESCRIPTORS,
+     ...VERSIONS_ERRORS_DESCRIPTORS,
+   },
  // ...
+   VERSIONS,
};

export default CONFIG;

API

Functions

augmentAPIWithVersionsHeaders(API, VERSIONS)Promise.<Object>

Augment an OpenAPI with versions headers added.

initWrapHandlerWithVersionChecker(services)Promise.<Object>

Wrap an handler to append CORS to response.

augmentAPIWithVersionsHeaders(API, VERSIONS) ⇒ Promise.<Object>

Augment an OpenAPI with versions headers added.

Kind: global function
Returns: Promise.<Object> - The augmented OpenAPI object

Param Type Description
API Object The OpenAPI object
VERSIONS Object The versions configurations

initWrapHandlerWithVersionChecker(services) ⇒ Promise.<Object>

Wrap an handler to append CORS to response.

Kind: global function
Returns: Promise.<Object> - A promise of an object containing the reshaped env vars.

Param Type Default Description
services Object The services ENV depends on
services.VERSIONS Object A VERSIONS object with the versions configuration
[services.log] Object noop An optional logging service

Authors

License

MIT

Package Sidebar

Install

npm i @whook/versions

Weekly Downloads

122

Version

16.1.1

License

MIT

Unpacked Size

45.2 kB

Total Files

16

Last publish

Collaborators

  • nfroidure