18.1.0 • Published 10 months ago

@whook/versions v18.1.0

Weekly downloads
398
License
MIT
Repository
github
Last release
10 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

18.1.0

10 months ago

18.0.3

10 months ago

18.0.0

10 months ago

17.0.2

12 months ago

17.0.1

1 year ago

17.0.0

1 year ago

16.1.1

1 year ago

16.1.0

2 years ago

16.0.1

2 years ago

16.0.0

2 years ago

15.0.0

2 years ago

13.1.0

2 years ago

13.2.0

2 years ago

14.0.0

2 years ago

13.2.1

2 years ago

13.0.0

2 years ago

10.0.5

3 years ago

10.0.6

3 years ago

10.0.0

3 years ago

10.0.1

3 years ago

10.0.2

3 years ago

10.0.3

3 years ago

10.0.4

3 years ago

12.0.0

3 years ago

12.0.1

3 years ago

12.0.2

3 years ago

11.0.0

3 years ago

11.0.1

3 years ago

9.0.1

3 years ago

9.0.0

3 years ago

8.5.1

4 years ago

8.5.0

4 years ago

8.4.2

4 years ago

8.4.1

4 years ago

8.4.0

4 years ago

8.3.0

4 years ago

8.1.0

4 years ago

8.1.1

4 years ago

8.0.4

4 years ago

8.0.3

5 years ago

8.0.2

5 years ago

8.0.1

5 years ago

8.0.0

5 years ago

7.1.5

5 years ago

7.1.4

5 years ago

7.1.3

5 years ago

7.1.1

5 years ago

7.1.0

5 years ago

7.0.0

5 years ago

6.0.0

5 years ago

5.1.6

5 years ago

5.1.5

5 years ago

5.1.4

5 years ago

5.1.3

5 years ago

5.1.2

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.4

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

4.0.0-alpha.44

5 years ago

4.0.0-alpha.43

5 years ago

4.0.0-alpha.42

5 years ago

4.0.0-alpha.41

5 years ago

4.0.0-alpha.40

5 years ago

4.0.0-alpha.39

6 years ago

4.0.0-alpha.38

6 years ago

4.0.0-alpha.37

6 years ago

4.0.0-alpha.36

6 years ago

4.0.0-alpha.35

6 years ago

4.0.0-alpha.34

6 years ago

4.0.0-alpha.33

6 years ago

4.0.0-alpha.32

6 years ago

4.0.0-alpha.31

6 years ago

4.0.0-alpha.30

6 years ago

4.0.0-alpha.29

6 years ago

4.0.0-alpha.28

6 years ago

4.0.0-alpha.27

6 years ago

4.0.0-alpha.26

6 years ago

4.0.0-alpha.25

6 years ago

4.0.0-alpha.24

6 years ago

4.0.0-alpha.23

6 years ago

4.0.0-alpha.22

6 years ago

4.0.0-alpha.21

6 years ago

4.0.0-alpha.20

6 years ago