16.1.0 • Published 2 months ago

@whook/versions v16.1.0

Weekly downloads
398
License
MIT
Repository
github
Last release
2 months ago

@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.

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

ParamTypeDescription
APIObjectThe OpenAPI object
VERSIONSObjectThe 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.

ParamTypeDefaultDescription
servicesObjectThe services ENV depends on
services.VERSIONSObjectA VERSIONS object with the versions configuration
services.logObjectnoopAn optional logging service

Authors

License

MIT

16.1.0

2 months ago

16.0.1

2 months ago

16.0.0

2 months ago

15.0.0

3 months ago

13.1.0

9 months ago

13.2.0

7 months ago

14.0.0

6 months ago

13.2.1

7 months ago

13.0.0

9 months ago

10.0.5

2 years ago

10.0.6

2 years ago

10.0.0

2 years ago

10.0.1

2 years ago

10.0.2

2 years ago

10.0.3

2 years ago

10.0.4

2 years ago

12.0.0

1 year ago

12.0.1

1 year ago

12.0.2

1 year ago

11.0.0

1 year ago

11.0.1

1 year ago

9.0.1

2 years ago

9.0.0

2 years ago

8.5.1

3 years ago

8.5.0

3 years ago

8.4.2

3 years ago

8.4.1

3 years ago

8.4.0

3 years ago

8.3.0

3 years ago

8.1.0

3 years ago

8.1.1

3 years ago

8.0.4

3 years ago

8.0.3

3 years ago

8.0.2

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

7.1.5

3 years ago

7.1.4

3 years ago

7.1.3

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.0

3 years ago

6.0.0

3 years ago

5.1.6

4 years ago

5.1.5

4 years ago

5.1.4

4 years ago

5.1.3

4 years ago

5.1.2

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.0

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.4

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

4.0.0-alpha.44

4 years ago

4.0.0-alpha.43

4 years ago

4.0.0-alpha.42

4 years ago

4.0.0-alpha.41

4 years ago

4.0.0-alpha.40

4 years ago

4.0.0-alpha.39

4 years ago

4.0.0-alpha.38

4 years ago

4.0.0-alpha.37

4 years ago

4.0.0-alpha.36

4 years ago

4.0.0-alpha.35

4 years ago

4.0.0-alpha.34

4 years ago

4.0.0-alpha.33

4 years ago

4.0.0-alpha.32

4 years ago

4.0.0-alpha.31

4 years ago

4.0.0-alpha.30

4 years ago

4.0.0-alpha.29

4 years ago

4.0.0-alpha.28

4 years ago

4.0.0-alpha.27

4 years ago

4.0.0-alpha.26

4 years ago

4.0.0-alpha.25

4 years ago

4.0.0-alpha.24

4 years ago

4.0.0-alpha.23

4 years ago

4.0.0-alpha.22

4 years ago

4.0.0-alpha.21

4 years ago

4.0.0-alpha.20

4 years ago