fastify-feature-flags
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -5,2 +5,12 @@ # Change Log | ||
## [1.2.3](https://gitlab.com/m03geek/fastify-feature-flags/compare/v1.2.2...v1.2.3) (2019-04-26) | ||
### Bug Fixes | ||
* autoattach fastify to providers ([6982c79](https://gitlab.com/m03geek/fastify-feature-flags/commit/6982c79)) | ||
* make error code optional ([4ae481d](https://gitlab.com/m03geek/fastify-feature-flags/commit/4ae481d)) | ||
## [1.2.2](https://gitlab.com/m03geek/fastify-feature-flags/compare/v1.2.1...v1.2.2) (2019-04-26) | ||
@@ -7,0 +17,0 @@ |
@@ -23,4 +23,10 @@ /// <reference types="node" /> | ||
interface Options { | ||
/** | ||
* Providers list | ||
*/ | ||
providers: Array<GenericProvider>; | ||
errorCode: number; | ||
/** | ||
* Error code for checkEnabled | ||
*/ | ||
errorCode?: number; | ||
} | ||
@@ -27,0 +33,0 @@ } |
@@ -11,2 +11,5 @@ "use strict"; | ||
const { providers, errorCode = DEFAULT_ERROR_CODE } = options; | ||
providers.forEach((provider) => { | ||
provider.attachFastify(fastify); | ||
}); | ||
const isEnabled = async (feature, context) => { | ||
@@ -13,0 +16,0 @@ const result = await Promise.all(providers.map((provider) => provider.isEnabled(feature, context))); |
import { GenericProvider } from './generic'; | ||
export declare namespace ConfigProvider { | ||
interface Options extends GenericProvider.Options { | ||
interface Options { | ||
/** | ||
@@ -5,0 +5,0 @@ * Config prefix for flags |
import { GenericProvider } from './generic'; | ||
export declare namespace EnvProvider { | ||
interface Options extends GenericProvider.Options { | ||
interface Options { | ||
/** | ||
@@ -5,0 +5,0 @@ * Prefix for env var filtering |
import fastify from 'fastify'; | ||
export declare namespace GenericProvider { | ||
interface Options { | ||
fastify: fastify.FastifyInstance; | ||
} | ||
} | ||
export declare abstract class GenericProvider { | ||
protected options: GenericProvider.Options; | ||
protected options: any; | ||
protected fastify: fastify.FastifyInstance; | ||
/** | ||
* @param options Provider options | ||
*/ | ||
constructor(options: GenericProvider.Options); | ||
constructor(options: any); | ||
/** | ||
* Attach fastify instance to provider | ||
* @param f fastify instance | ||
*/ | ||
attachFastify(f: fastify.FastifyInstance): void; | ||
/** | ||
* Checks if feature is enabled | ||
@@ -15,0 +16,0 @@ * @param _feature feature name |
@@ -11,2 +11,9 @@ "use strict"; | ||
/** | ||
* Attach fastify instance to provider | ||
* @param f fastify instance | ||
*/ | ||
attachFastify(f) { | ||
this.fastify = f; | ||
} | ||
/** | ||
* Checks if feature is enabled | ||
@@ -13,0 +20,0 @@ * @param _feature feature name |
import { GenericProvider } from './generic'; | ||
import { UnleashConfig } from 'unleash-client/lib/unleash'; | ||
export declare namespace UnleashProvider { | ||
interface Options extends UnleashConfig, GenericProvider.Options { | ||
interface Options extends UnleashConfig { | ||
} | ||
@@ -6,0 +6,0 @@ } |
@@ -8,8 +8,7 @@ "use strict"; | ||
super(options); | ||
const { fastify } = options; | ||
this.instance = unleash_client_1.initialize(options); | ||
this.instance.on('error', fastify.log.error); | ||
this.instance.on('warn', fastify.log.error); | ||
this.instance.on('ready', fastify.log.info); | ||
fastify.addHook('onClose', (_instance, done) => { | ||
this.instance.on('error', this.fastify.log.error); | ||
this.instance.on('warn', this.fastify.log.error); | ||
this.instance.on('ready', this.fastify.log.info); | ||
this.fastify.addHook('onClose', (_instance, done) => { | ||
this.instance.destroy(); | ||
@@ -16,0 +15,0 @@ done(); |
{ | ||
"name": "fastify-feature-flags", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Fastify feature flags plugin", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
20130
252