Skip to content

Commit

Permalink
Merge pull request #201 from featurehub-io/feature/sdk-extensions
Browse files Browse the repository at this point in the history
- Support for feature properties (if any)
  • Loading branch information
rvowles authored Mar 14, 2024
2 parents 6b3b71a + 28e22ef commit f931f17
Show file tree
Hide file tree
Showing 42 changed files with 321 additions and 129 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM node:18-buster-slim as build
ADD . /app
WORKDIR /app
RUN cd /app/featurehub-javascript-client-sdk && npm install && npm run compile
RUN cd /app/featurehub-javascript-node-sdk && npm install && npm run link && npm run compile
RUN cd /app/featurehub-javascript-node-sdk && npm install && npm run setup && npm run compile && npm run link
RUN cd /app/examples/todo-server-tests && npm install && npm run compile
RUN cd /app/examples/todo-backend-typescript && npm install && npm run compile

4 changes: 2 additions & 2 deletions examples/todo-backend-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"license": "MIT",
"scripts": {
"build": "node_modules/.bin/tsc",
"link": "npm link featurehub-javascript-client-sdk featurehub-javascript-node-sdk",
"compile": "npm run link && npm run build",
"setup": "npm link featurehub-javascript-client-sdk featurehub-javascript-node-sdk",
"compile": "npm run setup && npm run build",
"start": "npm run build && node --trace-deprecation --trace-warnings dist/app.js",
"run": "npm run build && node --trace-deprecation --trace-warnings dist/app.js"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/todo-server-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Integration tests for FeatureHub SDKs (server-side)",
"scripts": {
"build": "node ./node_modules/typescript/bin/tsc",
"link": "npm link featurehub-javascript-client-sdk featurehub-javascript-node-sdk",
"compile": "npm run link && npm run build",
"setup": "npm link featurehub-javascript-client-sdk featurehub-javascript-node-sdk",
"compile": "npm run setup && npm run build",
"test": "cucumber-js --require-module ts-node/register --require 'features/support/*.ts' --publish",
"generate:specs": "openapi-generator-cli generate -g typescript-axios -i ../todo-api/todo-api.yaml -o ./src/client-axios"
},
Expand Down
3 changes: 3 additions & 0 deletions featurehub-javascript-client-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 1.3.4
- support for Extended Feature Properties from FHOS 1.8.0, see xxx insert documentation link.

#### 1.3.3
- listeners were not being fired when added to contexts that matched strategies. [bugfix](https://github.com/featurehub-io/featurehub-javascript-sdk/issues/196)
- all the getX methods on the Context now have defaults, so you can say fhContext.getFlag("feature", false) and if it isn't set or doesn't exist, it will return false. This is an optional field so it doesn't break existing code. (feature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ export class ClientFeatureRepository implements InternalFeatureRepository {
const fState = holder.getFeatureState()!;
if (fs.version! < fState.version!) {
return false;
} else if (fs.version === fState.version && fs.value === fState.value) {
return false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions featurehub-javascript-client-sdk/app/feature_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ export interface FeatureStateHolder<T = any> {
get type(): FeatureValueType | undefined;

withContext(param: ClientContext): FeatureStateHolder;

get featureProperties(): Record<string,string> | undefined;
}
12 changes: 8 additions & 4 deletions featurehub-javascript-client-sdk/app/feature_state_holders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FeatureState, FeatureValueType } from './models';
import { ClientContext } from './client_context';
import { InternalFeatureRepository } from './internal_feature_repository';
import { ListenerUtils } from './listener_utils';
import {fhLog} from "./feature_hub_config";
import { fhLog } from './feature_hub_config';

interface ListenerTracker {
listener: FeatureListener;
Expand Down Expand Up @@ -88,7 +88,7 @@ export class FeatureStateBaseHolder<T = any> implements FeatureStateHolder<T> {
if (this._ctx !== undefined) {
this.listeners.set(pos, {
listener: () => listener(this), holder: this
} );
});
} else {
this.listeners.set(pos, {
listener: listener, holder: this
Expand Down Expand Up @@ -146,7 +146,7 @@ export class FeatureStateBaseHolder<T = any> implements FeatureStateHolder<T> {
this.listeners.forEach((value, key) => {
listenerValues.set(key, {
value: value.holder.value
})
});
});

this.internalFeatureState = fs;
Expand All @@ -164,7 +164,7 @@ export class FeatureStateBaseHolder<T = any> implements FeatureStateHolder<T> {
try {
value.listener(value.holder);
} catch (e) {
fhLog.error(`Failed to trigger listener`, e);
fhLog.error('Failed to trigger listener', e);
}
}
});
Expand Down Expand Up @@ -293,4 +293,8 @@ export class FeatureStateBaseHolder<T = any> implements FeatureStateHolder<T> {
get value(): T {
return this._getValue(this.getType(), true);
}

get featureProperties(): Record<string, string> | undefined {
return this.featureState()?.fp ?? undefined;
}
}
5 changes: 5 additions & 0 deletions featurehub-javascript-client-sdk/app/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class BaggageHolder<T = any> implements FeatureStateHolder<T> {
this.baggageValue = value;
}

// feature properties are not included in baggage, they don't make logical sense.
get featureProperties(): Record<string, string> | undefined {
return undefined;
}

isEnabled(): boolean {
return this.getBoolean() === true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.gitignore
.npmignore
.openapi-generator-ignore
git_push.sh
index.ts
models/application-version-info.ts
models/base-rollout-strategy-attribute.ts
models/base-rollout-strategy-all-of.ts
models/base-rollout-strategy.ts
models/base-strategy.ts
models/base-uistrategy.ts
models/feature-environment-collection.ts
models/feature-rollout-strategy-all-of.ts
models/feature-rollout-strategy-attribute.ts
Expand All @@ -16,6 +17,7 @@ models/feature-value-type.ts
models/index.ts
models/role-type.ts
models/rollout-strategy-attribute-conditional.ts
models/rollout-strategy-attribute.ts
models/rollout-strategy-field-type.ts
models/sseresult-state.ts
models/strategy-attribute-country-name.ts
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c1d8832e6a2bf63c1201a9ce0e28f9024bb577984c9ab652a03f4bb27f443f83
357944b3dddaf0986739059920aae8fc5e554ee1d80beffa07e26b38ea4f88ff
2 changes: 1 addition & 1 deletion featurehub-javascript-client-sdk/app/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.3
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.3
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* tslint:disable */
/* eslint-disable */
/**
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



/**
*
* @export
* @interface BaseRolloutStrategyAllOf
*/
export interface BaseRolloutStrategyAllOf {
/**
* when we attach the RolloutStrategy for Dacha or SSE this lets us push the value out. Only visible in SDK and SSE Edge.
* @type {any}
* @memberof BaseRolloutStrategyAllOf
*/
value?: any | null;
}


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.3
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -13,44 +13,15 @@
*/


import { BaseRolloutStrategyAttribute } from './base-rollout-strategy-attribute';
import { BaseRolloutStrategyAllOf } from './base-rollout-strategy-all-of';
import { BaseStrategy } from './base-strategy';
import { RolloutStrategyAttribute } from './rollout-strategy-attribute';

/**
* if the feature in an environment is different from its default, this will be the reason for it. a rollout strategy is defined at the Application level and then applied to a specific feature value. When they are copied to the cache layer they are cloned and the feature value for that strategy is inserted into the clone and those are published.
* @type BaseRolloutStrategy
* @export
* @interface BaseRolloutStrategy
*/
export interface BaseRolloutStrategy {
/**
*
* @type {string}
* @memberof BaseRolloutStrategy
*/
id?: string;
/**
* value between 0 and 1000000 - for four decimal places
* @type {number}
* @memberof BaseRolloutStrategy
*/
percentage?: number;
/**
* if you don\'t wish to apply percentage based on user id, you can use one or more attributes defined here
* @type {Array<string>}
* @memberof BaseRolloutStrategy
*/
percentageAttributes?: Array<string>;
/**
* when we attach the RolloutStrategy for Dacha or SSE this lets us push the value out. Only visible in SDK and SSE Edge.
* @type {any}
* @memberof BaseRolloutStrategy
*/
value?: any | null;
/**
*
* @type {Array<BaseRolloutStrategyAttribute>}
* @memberof BaseRolloutStrategy
*/
attributes?: Array<BaseRolloutStrategyAttribute>;
}
export type BaseRolloutStrategy = BaseRolloutStrategyAllOf & BaseStrategy;



Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* tslint:disable */
/* eslint-disable */
/**
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


import { RolloutStrategyAttribute } from './rollout-strategy-attribute';

/**
* if the feature in an environment is different from its default, this will be the reason for it. a rollout strategy is defined at the Application level and then applied to a specific feature value. When they are copied to the cache layer they are cloned and the feature value for that strategy is inserted into the clone and those are published.
* @export
* @interface BaseStrategy
*/
export interface BaseStrategy {
/**
* value between 0 and 1000000 - for four decimal places
* @type {number}
* @memberof BaseStrategy
*/
percentage?: number | null;
/**
* if you don\'t wish to apply percentage based on user id, you can use one or more attributes defined here
* @type {Array<string>}
* @memberof BaseStrategy
*/
percentageAttributes?: Array<string> | null;
/**
*
* @type {Array<RolloutStrategyAttribute>}
* @memberof BaseStrategy
*/
attributes?: Array<RolloutStrategyAttribute> | null;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* tslint:disable */
/* eslint-disable */
/**
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



/**
*
* @export
* @interface BaseUIStrategy
*/
export interface BaseUIStrategy {
/**
* names are unique in a case insensitive fashion
* @type {string}
* @memberof BaseUIStrategy
*/
name?: string;
/**
* the colour used to display the strategy in the UI. indexed table of background/foreground combos.
* @type {number}
* @memberof BaseUIStrategy
*/
colouring?: number | null;
/**
* Disable this strategy across all feature values that are using it
* @type {boolean}
* @memberof BaseUIStrategy
*/
disabled?: boolean;
/**
* url to avatar (if any). Not sent to SDK. Preferably a unicorn.
* @type {string}
* @memberof BaseUIStrategy
*/
avatar?: string | null;
}


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.3
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* FeatureServiceApi
* This describes the API clients use for accessing features
*
* The version of the OpenAPI document: 1.1.3
* The version of the OpenAPI document: 1.1.8
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -21,12 +21,18 @@ import { FeatureRolloutStrategyAttribute } from './feature-rollout-strategy-attr
* @interface FeatureRolloutStrategyAllOf
*/
export interface FeatureRolloutStrategyAllOf {
/**
* strategy id
* @type {string}
* @memberof FeatureRolloutStrategyAllOf
*/
id: string;
/**
*
* @type {Array<FeatureRolloutStrategyAttribute>}
* @memberof FeatureRolloutStrategyAllOf
*/
attributes: Array<FeatureRolloutStrategyAttribute>;
attributes?: Array<FeatureRolloutStrategyAttribute>;
}


Loading

0 comments on commit f931f17

Please sign in to comment.