Notwithstanding Previous Misdemeanors

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

    8.5.1 • Public • Published

    @whook/versions

    A wrapper to provide versions check support to a Whook server

    GitHub license NPM version

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

    To use this module, simply add it to your WRAPPERS service (usually in src/services/WRAPPERS.ts):

    import { service } from 'knifecycle';
    + import { wrapHandlerWithVersions } from '@whook/versions';
    import type { WhookWrapper } from '@whook/whook';
    
    export default service(initWrappers, 'WRAPPERS');
    
    async function initWrappers(): Promise<WhookWrapper<any, any>[]> {
    -  const WRAPPERS = [];
    +  const WRAPPERS = [wrapHandlerWithVersions];
    
      return WRAPPERS;
    }

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

    import { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/http-router';
    + import {
    +   VERSIONS_ERRORS_DESCRIPTORS,
    +   WhookVersionsConfig
    + } from '@whook/versions';
    
    // ...
    
    + const VERSIONS = [
    +   {
    +     header: 'X-SDK-Version',
    +     rule: '>=2.2.0',
    +   },
    +   {
    +     header: 'X-APP-Version',
    +     rule: '>=3.6.0',
    +   },
    + ];
    
    export type AppConfigs = WhookConfigs &
    +  WhookVersionsConfig &
      APIConfig;
    
    const CONFIG: AppConfigs = {
      // ...
    -   ERRORS_DESCRIPTORS: DEFAULT_ERRORS_DESCRIPTORS,
    +   ERRORS_DESCRIPTORS: {
    +     ...DEFAULT_ERRORS_DESCRIPTORS,
    +     ...VERSIONS_ERRORS_DESCRIPTORS,
    +   },
      // ...
    +   VERSIONS,
    };
    
    export default CONFIG;

    API

    Functions

    wrapHandlerWithVersionChecker(initHandler)function

    Wrap an handler initializer to check versions headers.

    augmentAPIWithVersionsHeaders(API, VERSIONS)Promise.<Object>

    Augment an OpenAPI with versions headers added.

    wrapHandlerWithVersionChecker(initHandler) ⇒ function

    Wrap an handler initializer to check versions headers.

    Kind: global function
    Returns: function - The handler initializer wrapped

    Param Type Description
    initHandler function The handler initializer

    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

    Authors

    License

    MIT

    Install

    npm i @whook/versions

    DownloadsWeekly Downloads

    106

    Version

    8.5.1

    License

    MIT

    Unpacked Size

    76.8 kB

    Total Files

    16

    Last publish

    Collaborators

    • nfroidure