Skip to content

Commit

Permalink
Merge pull request #15 from takenet/feature/add-localstorage-cache
Browse files Browse the repository at this point in the history
Feature/add localstorage cache
  • Loading branch information
raynegomes committed Jun 10, 2021
2 parents a61c645 + aa34d99 commit 3e65eb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"commit": "./node_modules/.bin/git-cz",
"clean": "rimraf lib && rimraf coverage",
"format": "prettier --write \"{src,__tests__}/**/*.ts\" --single-quote es5",
"lint": "tslint --force --format verbose \"src/**/*.ts\"",
"lint": "tslint --format verbose \"src/**/*.ts\"",
"prepublishOnly": "npm run build",
"prebuild": "npm run clean && npm run lint && echo Using TypeScript && tsc --version",
"build": "tsc --pretty",
"build": "npm run prebuild && tsc --pretty",
"test": "jest",
"coverage": "jest --coverage --coverageReporters=text-lcov | coveralls",
"coverage-local": "jest --coverage",
Expand Down
11 changes: 5 additions & 6 deletions src/FeatureToggleApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { AddUserRequest } from './types/AddUserRequest';
import { UserAccount } from './types/UserAccount';
import { IFeatureToggleServiceSettings } from './types/IFeatureToggleServiceSettings';
import { Instruction } from './types/Instruction';

const axios = require('axios').default;
import axios from 'axios';

export class FeatureToggleApiService {
private readonly API_URL = 'https://app.launchdarkly.com/api/v2/flags';
Expand Down Expand Up @@ -38,13 +37,13 @@ export class FeatureToggleApiService {
instructions.push(new Instruction({
kind: this.ADD_USER_TARGETS,
values: users.map(user => user.email),
variationId: variationId
variationId
}));

const addUserRequest = new AddUserRequest({
comment: this.DEFAULT_COMMENT,
environmentKey: this.settings.environmentKey,
instructions: instructions
instructions
});

return addUserRequest;
Expand All @@ -56,8 +55,8 @@ export class FeatureToggleApiService {
headers: this.getApiRequestHeaders()
});
if (response.status === this.STATUS_CODE_OK) {
const variation = response.data.variations.find(variation => {
return variation.value === true;
const variation = response.data.variations.find(({ value }) => {
return value === true;
});
return variation._id;
}
Expand Down
5 changes: 4 additions & 1 deletion src/FeatureToggleInstanceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ const applicationByCluster = (p: any) =>

export class FeatureToggleInstanceFactory {
private client: LDClient;
private defaultOptions: Partial<LDOptions> = {
bootstrap: 'localStorage'
};

constructor(payload: UserAccount | Application, ldclientSdkKey: string, options?: LDOptions) {
this.client = initialize(ldclientSdkKey, this.payloadByType(payload), options);
this.client = initialize(ldclientSdkKey, this.payloadByType(payload), { ...options, ...this.defaultOptions });
}

/**
Expand Down

0 comments on commit 3e65eb6

Please sign in to comment.